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

Author Topic: sf:utf16 and std::vector<uint16_t>  (Read 1158 times)

0 Members and 1 Guest are viewing this topic.

Zamadatix

  • Newbie
  • *
  • Posts: 27
    • View Profile
sf:utf16 and std::vector<uint16_t>
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10791
    • View Profile
    • development blog
    • Email
AW: sf:utf16 and std::vector<uint16_t>
« Reply #1 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());
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/