Jump to content

  • Log In with Google      Sign In   
  • Create Account

check if char is displayable character


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 Juliean   GDNet+   -  Reputation: 5443

Like
0Likes
Like

Posted 24 May 2014 - 05:51 PM

Hello,

 

there is the isalnum-function for determining whether a character is eigther a-zA-Z or 0-9, but is there any function that checks if the char contains any other displayble character like , ; etc...? I have a generic key-press handling routine using chars for performing text-input in my gui using char-code as input, this also includes shift, alt, etc... which I want to still be able to receive, but filter from a textbox (else pressing alt would overwrite content if e.g. text is selected in the box). Any predefined functions or do I have to enroll one myself?



#2 fastcall22   Crossbones+   -  Reputation: 8829

Like
1Likes
Like

Posted 24 May 2014 - 07:30 PM

On an en-US keyboard? Check the ASCII chart, any characters between 32 and 126 are "printable".
gzip: H4sIAAAAAAAEAG1QTUvEMBC991e8nvaiFfYoS7yo sLCo6MnjtJ1ugmkiyWRL/72z3T1YEQIJ8z4zA2Xp yPvt1qBpGrRFIJZkk9FyRyUzHCbKIHgn4hnZOrm1 TD0mG0HCCs+QGDGWziKXI6Wm2n++GYwUVH2mrGEE PnGCVQ8K8+JYfXA6URDEQfMZh5h6g5eoAlWJdeEI bbH2qYZf7XMUfw8f/Q0oMeZYNL9/WHF0uFEshvMr XYujd9SycFb+F18QcSOvlJauZ8ejqevdnV7/d550 e0t6prmunh73Bu+vz4c/XUeOQXfJgvKNkhf95U8/ Dtgmy5IBAAA=

#3 FRex   Members   -  Reputation: 1468

Like
4Likes
Like

Posted 24 May 2014 - 09:14 PM

http://www.cplusplus.com/reference/cctype/isprint/


An in-game LuaConsole for SFML: https://github.com/FRex/LuaConsole


#4 Bacterius   Crossbones+   -  Reputation: 12840

Like
2Likes
Like

Posted 24 May 2014 - 09:15 PM

This one seems to support locales as well: http://www.cplusplus.com/reference/locale/isprint/


“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


#5 frob   Moderators   -  Reputation: 38038

Like
4Likes
Like

Posted 24 May 2014 - 10:11 PM

More shenanigans and problems with fonts and fancy characters:

* Just because the value exists as printable in a locale doesn't mean the font contains a glyph for it.
* Even if the locale doesn't support the value as a printable character, the font may contain a glyph for it anyway.

It is okay to rely on the system for validation when everything is going through the system. In that scenario it isn't yours to control.

But in games, you often have your own custom GUI, and often your own custom fonts. In that case it is yours to control, so you should control it.

If you are using the language-supplied system for characters and glyphs and displays, use the language-supplied validation tests. If you are not using the language-supplied system, you need to validate it with the tools that match your GUI system. If you wrote your GUI system yourself, you need to validate it yourself.

Edited by frob, 24 May 2014 - 10:14 PM.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.


#6 Juliean   GDNet+   -  Reputation: 5443

Like
0Likes
Like

Posted 25 May 2014 - 03:29 AM


* Just because the value exists as printable in a locale doesn't mean the font contains a glyph for it.

 

I'm aware of that, but whats the recommended handling for this? I wouldn't just want to ignore the letter int that case, wouldn't it be awkard if the player/user tried to type something and it would just skip certain characters like 'a'? Well, just having them not displayed is weird too, but I quess its better to at least get some sort of feedback from the application and at least have it there. I use that check here foremost not to determine what is being displayed, but what content the textbox has, so if I ignore a character, it won't get used by whatever system uses the textbox.

 


* Even if the locale doesn't support the value as a printable character, the font may contain a glyph for it anyway.

 

Thats a case I really don't want to support though, before using isalnum, my default arial 16 font appeared to have glyphs for keys like shift, alt, etc... so in that case I'm willing to accept only what is known as valid input.

 


It is okay to rely on the system for validation when everything is going through the system. In that scenario it isn't yours to control.

But in games, you often have your own custom GUI, and often your own custom fonts. In that case it is yours to control, so you should control it.

If you are using the language-supplied system for characters and glyphs and displays, use the language-supplied validation tests. If you are not using the language-supplied system, you need to validate it with the tools that match your GUI system. If you wrote your GUI system yourself, you need to validate it yourself.

 

Well, I am using the win32-api to generate my custom font-definition file/font texture in the first place, but I get where you are going at. I gotta admit too, I've just been a little lazy regarding this input-thingy. I already have a custom key-handling routine using my own key-enum etc... , but that is only used to register key events like ecs for close window, shortcuts etc... . I quess I am better off just going full way and finally customize the key-typing-handling as well. Thanks.

 

Thanks also for the other suggestions!






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS