Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Reliably converting between std::vector<uint8_t> and WString (I would like to use other libraries which leverage std::vector etc and would like to know how to convert)
Reliably converting between std::vector<uint8_t> and WString [message #55560] Sun, 22 November 2020 00:17 Go to next message
steveo is currently offline  steveo
Messages: 11
Registered: November 2020
Promising Member
I have a desire to use some encryption libraries which are not WString aware.

How do I reliably take the raw buffer of a WString and convert it to a std::vector<uint8_t>?

and conversely.

How do I reliably take a buffer thus converted and reliably put it back into a WString?

It's been years since I did pointer arithmetic and back in the day we simply ignored WString because we could.

WString input = "Some unicode text";
std::vector<uint8_t> bytes(const uint8_t*)input.Begin(), input.GetCount()*sizeof(wchar));
WString output((const wchar*)bytes.data(), (bytes.size()/sizeof(wchar));

[Updated on: Sun, 22 November 2020 00:24]

Report message to a moderator

Re: Reliably converting between std::vector<uint8_t> and WString [message #55561 is a reply to message #55560] Sun, 22 November 2020 00:26 Go to previous message
Oblivion is currently offline  Oblivion
Messages: 1094
Registered: August 2007
Senior Contributor
Quote:
How do I reliably take the raw buffer of a WString and convert it to a std::vector<uint8_t>?



Both Upp::WString and Upp::String classes have a ToStd() method and relevant constructors which converts them to std::string or from std::string to them, if that's what you need.

If you simply need Utf16 to Utf8 conversion, there is also a ToUtf8 method that takes a WString and converts it to Utf8.

Best regards,
Oblivion


[Updated on: Sun, 22 November 2020 00:32]

Report message to a moderator

Previous Topic: How to Mask Input fields
Next Topic: The Mysterious checkbox
Goto Forum:
  


Current Time: Sat Jun 15 06:14:35 CEST 2024

Total time taken to generate the page: 0.02232 seconds