SFML community forums

Help => System => Topic started by: dydya-stepa on March 05, 2012, 06:01:31 pm

Title: How to disallow all but text characters for all languages?
Post by: dydya-stepa on March 05, 2012, 06:01:31 pm
I want to allow only text characters for a textbox. How can I filter out all the other characters from evt.Text.Unicode. I'm talking about commas, semicolons and so on.
Title: How to disallow all but text characters for all languages?
Post by: texus on March 05, 2012, 06:13:56 pm
Every character has a number: http://www.asciitable.com/

For only the letters you will need to do this:
Code: [Select]
if (((evt.Text.Unicode > 64) && (evt.Text.Unicode < 91)) // check for capital letters
 || ((evt.Text.Unicode > 96) && (evt.Text.Unicode < 123))) // and check for lowercase
{
    // add the letters to the textbox
}
Title: How to disallow all but text characters for all languages?
Post by: dydya-stepa on March 05, 2012, 06:58:19 pm
isn't that for english only? i want ALL languages as stated in the name of the topic

http://en.wikibooks.org/wiki/Unicode/Character_reference/0000-0FFF

3rd an 4th section contain also crappy characters.
Title: How to disallow all but text characters for all languages?
Post by: texus on March 05, 2012, 07:23:56 pm
Sorry, I didn't read the topic name.

You might want to check out functions like iswalpha.
Title: How to disallow all but text characters for all languages?
Post by: dydya-stepa on March 05, 2012, 07:56:03 pm
good idea. does sfml support this ? can I use sfml's evt.Text.Unicode with c/c++ build in functions?
Title: How to disallow all but text characters for all languages?
Post by: Laurent on March 05, 2012, 08:11:43 pm
iswalpha expects a wide character, but it's not clear what encoding it works with.

If you need to classify Unicode characters, you should use a true Unicode library. You won't do anything good with only standard functions; they are not made for Unicode.
Title: How to disallow all but text characters for all languages?
Post by: Nexus on March 13, 2012, 06:40:49 pm
texus, when working with ASCII, I would rather use the meaningful char literals instead of magic numbers, e.g. 'A'.
Title: How to disallow all but text characters for all languages?
Post by: texus on March 13, 2012, 06:45:39 pm
You are absolutely right, that would be clearer.