check if char is displayable character

Started by
4 comments, last by Juliean 9 years, 10 months ago

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?

Advertisement
On an en-US keyboard? Check the ASCII chart, any characters between 32 and 126 are "printable".

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

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

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.


* 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!

This topic is closed to new replies.

Advertisement