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

Author Topic: [SOLVED] How to convert from Glib::ustring to sf::String?  (Read 13059 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How to convert from Glib::ustring to sf::String?
« Reply #15 on: January 26, 2015, 05:52:52 pm »
Can you show your code again?
Laurent Gomila - SFML developer

tapule

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to convert from Glib::ustring to sf::String?
« Reply #16 on: January 26, 2015, 06:03:08 pm »
This doesn't work:
Glib::ustring text = "Text: ñáéíóúö";
sf::String string;

string = sf::String::fromUtf8(text.begin(), text.end());
 

This work
Glib::ustring text = "Text: ñáéíóúö";
sf::String string;

string = sf::String::fromUtf16(text.begin(), text.end());
 

and this
Glib::ustring text = "Text: ñáéíóúö";
sf::String string;

string = sf::String::fromUtf32(text.begin(), text.end());
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How to convert from Glib::ustring to sf::String?
« Reply #17 on: January 26, 2015, 07:06:24 pm »
It seems that Glib::ustring::iterator provides gunichar, which is a codepoint (UTF-32).

So the following should both work:

sf::String string = sf::String::fromUtf32(text.begin(), text.end());

sf::String string = sf::String::fromUtf8(text.raw().begin(), text.raw().end());
Laurent Gomila - SFML developer

tapule

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to convert from Glib::ustring to sf::String?
« Reply #18 on: January 26, 2015, 07:39:35 pm »
So, as sf::String::fromUtf32 basically does an assign to the internal std::basic_string<unsigned int> that sf::String has, this is the reason that make my code work, this is, is the same behaviour.

Thank you for your time Laurent.

 

anything