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   GDNet+   

6202
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   Moderators   

9742
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".
zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

#3   Members   

1622
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   Members   

13100
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   Moderators   

41269
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   GDNet+   

6202
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.