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: 2388

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?



Sponsor:

#2 fastcall22   Crossbones+   -  Reputation: 4158

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".
c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#3 FRex   Members   -  Reputation: 289

Like
4Likes
Like

Posted 24 May 2014 - 09:14 PM

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



#4 Bacterius   Crossbones+   -  Reputation: 8352

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/


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 frob   Moderators   -  Reputation: 19862

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 personal indie blog at bryanwagstaff.com.

#6 Juliean   GDNet+   -  Reputation: 2388

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