SFML community forums

Help => General => Topic started by: Zamadatix on May 28, 2015, 05:49:38 am

Title: sf:utf16 and std::vector<uint16_t>
Post by: Zamadatix on May 28, 2015, 05:49:38 am
Hello all,

I have been writing an open client that can connect to an existing server model (that I have no control of). The server sends node names in UTF-16 format. I decode this into a null terminated std::vector<uint16_t>. Here is where I run into problems... std::u16string seems new and doesn't have nearly as much documentation or functions on conversions as std::string or std::wchar. I tried doing some string.resize() and memcpy magic but it always caused application crashes. std::wchar (in my understanding) isn't proper UTF-16 as it is today so I want to avoid using that as much information there is on it. I am using sfml for the graphics anyways so I figure I might as well use sf::utf16. Is there any way to convert std::vector<uint16_t> to sf::utf16?

Thank you,

zamadatix
Title: AW: sf:utf16 and std::vector<uint16_t>
Post by: eXpl0it3r on May 28, 2015, 09:47:50 am
I think this should work:

std::vector<uint16_t> vec = data();
sf::String str = sf::String::fromUtf16(vec.begin(), vec.end());