Re: Support for std::wstring
Bronek Kozicki skrev:
peter koch <peter.koch.larsen@gmail.com> wrote:
Yes - all conforming compilers will support std::wstring. I doubt you
can find a compiler that supports std::string but not std::wstring.
libstdc++ port for Windows (as bundled with mingw compiler) does not
support std::wstring, because its implementation is dependent on
POSIX-style locale. But one can always use STLPort, which does support
std::wstring with this compiler.
I forgot that - thanks for reminding me.
Another related question that I have is, is it advisable to use
wstring than string for unicode support? To be able to support
Unicode build, is it that all the occurrence of std::string will
need to be changed to std::wstring?
Hold on. std::wstring is not necesarrily unicode.
indeed, but on platforms that directly support Unicode on the operating
system level, wchar_t usually is some Unicode encoding (on Windows 2000
or newer it's UTF-16). I'd say that it's OK to use std::wstring and
wchar_t to handle Unicode strings if both are true:
- you do not care which encoding is used
- you do not target exotic platforms where wchar_t is not Unicode at all
I part of agree here. You can not use std::wstring as a generic unicode
string in Windows as the representation is encoded using the same
principle as for utf-8. Thus, s[i] might not necesarrily return the
i'th character of s. If you are aware of this (or only process
characters in the basic plane), you are safe.
/Peter
B.