Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to disallow all but text characters for all languages?  (Read 4650 times)

0 Members and 1 Guest are viewing this topic.

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
How to disallow all but text characters for all languages?
« 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.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
How to disallow all but text characters for all languages?
« Reply #1 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
}
TGUI: C++ SFML GUI

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
How to disallow all but text characters for all languages?
« Reply #2 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.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
How to disallow all but text characters for all languages?
« Reply #3 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.
TGUI: C++ SFML GUI

dydya-stepa

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
How to disallow all but text characters for all languages?
« Reply #4 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to disallow all but text characters for all languages?
« Reply #5 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.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
How to disallow all but text characters for all languages?
« Reply #6 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'.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
How to disallow all but text characters for all languages?
« Reply #7 on: March 13, 2012, 06:45:39 pm »
You are absolutely right, that would be clearer.
TGUI: C++ SFML GUI