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

Author Topic: sf::Utf  (Read 3541 times)

0 Members and 1 Guest are viewing this topic.

Kairuni

  • Newbie
  • *
  • Posts: 2
    • View Profile
sf::Utf
« 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. :\

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Utf
« Reply #1 on: September 23, 2011, 09:39:00 am »
Quote
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:

Code: [Select]
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);
}
Laurent Gomila - SFML developer

Kairuni

  • Newbie
  • *
  • Posts: 2
    • View Profile
sf::Utf
« Reply #2 on: September 23, 2011, 10:08:20 am »
Excellent. Thank you, Laurent. =)

 

anything