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

Author Topic: how to check for mutated vowels?  (Read 5407 times)

0 Members and 1 Guest are viewing this topic.

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
how to check for mutated vowels?
« on: November 06, 2009, 12:50:55 pm »
hi all,

i am prototyping a very simple text input application for my project
and since we are currently expecting german speaking users i need
to check for mutated vowels like ö, ä and ü. they are very important in our language and i can't use their alternatives (oe, ae or ue).

is there a way to detect them?
as event.Key.Code i always get a zero value when i press those keys on my mac...

using current revision of SFML 1.5x on macosx 10.5.8

thanks in advance
didi

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how to check for mutated vowels?
« Reply #1 on: November 06, 2009, 12:52:58 pm »
Hi

Event::KeyPressed is not made for text input, you must use Event::TextEntered.
Laurent Gomila - SFML developer

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
how to check for mutated vowels?
« Reply #2 on: November 06, 2009, 01:09:49 pm »
ah ok, i thought so, but i did not find any good documentation on that and the keypressed version did work properly so far.
i used this sample code i found somewhere on SFML-Dev

Code: [Select]

if (event.Type == sf::Event::TextEntered)
{
    std::string ucStr;
    ucStr += event.Text.Unicode;
    printf("[INFO] incoming event \"TextEntered\" - %s\n", ucStr.c_str());
}


but i still get the output "[INFO] incoming event "TextEntered" - ?".
for ö, ü and ä i should not even need unicode, since they are only extended ascii and are available on every standard german keyboard.
so if i consider using textentered, how do i get the right symbols/chars then?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how to check for mutated vowels?
« Reply #3 on: November 06, 2009, 01:25:02 pm »
When you deal with character encoding, you have to know which encoding is used at every step.

Code: [Select]
ucStr += event.Text.Unicode;
Here, event.Text.Unicode is UTF-32 and ucStr is a 1-byte characters storage.
So you end up with latin1 (ISO-8859-1), which contains the characters of UTF-32 that can fit in 8 bits (and 1 byte is probably 8 bits on your system).

Code: [Select]
printf("[INFO] incoming event \"TextEntered\" - %s\n", ucStr.c_str());
Here you send your latin1 string to the console, which uses whatever character encoding Mac OS X likes. Probably not latin1.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how to check for mutated vowels?
« Reply #4 on: November 06, 2009, 01:29:31 pm »
It seems that the default encoding on Mac OS X is UTF-8. So you have to convert your string if you want to display it in the console.

However if you just need to display it in SFML (with sf::String), you won't need any conversion.
Laurent Gomila - SFML developer

didito

  • Newbie
  • *
  • Posts: 27
    • View Profile
    • http://didito.gpigs.com
how to check for mutated vowels?
« Reply #5 on: November 06, 2009, 01:49:08 pm »
thank you very much for clearifying that! i definitly have a lack of knowledge in this area  :oops:

i do not need this string displayed in the console, i need it on the display and the string should get converted and sent over network via UDP (mac to mac system).
and i need to process the text somehow (append character, delete last char).
so if i use sf::String and cast it to std::string will i postpone the problem and loose my symbols again?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how to check for mutated vowels?
« Reply #6 on: November 06, 2009, 02:16:53 pm »
Quote
so if i use sf::String and cast it to std::string will i postpone the problem and loose my symbols again?

By storing your string in std::string, you loose every character that doesn't fit in 8 bits (i.e. you work with Latin1 instead of UTF-32). But if Latin1 contains all the characters that you need, you can work with it, there's no problem (you can refer to http://en.wikipedia.org/wiki/Latin1#Codepage_layout).

If you want to support a much larger range of characters, you can use std::wstring. On Mac OS X it can store the whole UTF-32 range.
Laurent Gomila - SFML developer