SFML community forums
Help => System => Topic started by: Kairuni on September 23, 2011, 09:31:49 am
-
Unfortunately, or not, I've very little experience working with unicode strings.
Currently, I'm working on a MUD client that I would like to support utf-8 inputs.
As is usual with telnet-related applications, I'm already pulling out the various telnet and MUD-specific things as they come in.
This leaves me with a stream of bytes, which need to get converted to a utf-8 string for parsing and displaying. Unfortunately, these won't always be valid utf-8 strings, as the final character might get chopped in half (though in most cases, it will not).
Essentially, I'm trying to understand how to use sf::Utf along with sf::String for displaying the characters. The templating on sf::Utf is mildly confusing, as well. Any tips?
Edit: Definitely meant to post this under system. Apologies. :\
-
The templating on sf::Utf is mildly confusing
You don't have to care about the template parameter. Use one of the typedefs, in your case sf::Utf8.
If you want to put a UTF-8 string into a sf::String (and then a sf::Text), you must use the sf::Utf8::ToUtf32 function:
sf::String Utf8ToString(const char* utf8, std::size_t size)
{
std::basic_string<sf::Utf32> utf32;
sf::Utf8::ToUtf32(utf8, utf8 + size, std::back_inserter(utf32));
return sf::String(utf32);
}
-
Excellent. Thank you, Laurent. =)