STL string conversion between wstring and string -
i wondering adequate enough use in production codebase?
std::wstring s2w(const std::string& s) { std::wstring ws; ws.assign(s.begin(), s.end()); return ws; } std::string w2s(const std::wstring& w) { std::string s; s.assign(w.begin(), w.end()); return s; }
no, not sufficient.
consider wstring contains following characters (numeric values used clarity) { 0x41, 0x1243, 0x62 } (that's 'a', followed ethiopic syllable qaa, followed 'b' if you're using unicode).
converting string using routine result in sequence containing { 0x41, 0x43, 0x42 }, or 'acb'. not expected - or wanted.
as dyp said - you're not doing conversion, narrowing.
Comments
Post a Comment