UnicodeConverter question

Please post support and help requests here.
Posts: 10
Joined: 22 Dec 2008, 07:46

UnicodeConverter question

Postby chinistan » 25 Feb 2009, 02:38


void UnicodeConverter::toUTF16(const std::string& utf8String, std::wstring& utf16String)
UTF8Encoding utf8Encoding;
TextIterator it(utf8String, utf8Encoding);
TextIterator end(utf8String);
while (it != end) utf16String += (wchar_t) *it++;

use wchar_t to cast it,in linux or UNIX ,wchar_t has 4 bytes,is that correct?

see this:http://www.firstobject.com/wchar_t-string-on-linux-osx-windows.htm

Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: UnicodeConverter question

Postby guenter » 25 Feb 2009, 07:15

Yes, wchar_t on Windows is 16 bit and uses UTF-16 encoding, as on Windows all Unicode APIs expect wchar_t based strings. On Unix platforms (including Linux and Mac OS X), wchar_t is 32 bit and the encoding is unspecified. Since wchar_t is 32 bit on those platforms, using UTF-16 actually does not make much sense, as one could directly store an unencoded Unicode character in a wchar_t.

The main reason why we have UnicodeConverter is for converting UTF-8 encoded std::strings coming from POCO into std::wstrings (and vice versa) for using with the Windows Unicode APIs. I'd strongly advice against using wchar_t and std::wstring in your code if that code is meant to be portable across platforms.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 4 guests