2010-05-31 22:58:54 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2010-11-16 23:09:02 +01:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-31 22:58:54 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// <locale>
|
|
|
|
|
|
|
|
// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
|
|
|
|
|
|
|
|
// wide_string from_bytes(char byte);
|
|
|
|
// wide_string from_bytes(const char* ptr);
|
|
|
|
// wide_string from_bytes(const byte_string& str);
|
|
|
|
// wide_string from_bytes(const char* first, const char* last);
|
|
|
|
|
|
|
|
#include <locale>
|
|
|
|
#include <codecvt>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
|
|
|
|
std::string bs("\xF1\x80\x80\x83");
|
|
|
|
std::wstring ws = myconv.from_bytes('a');
|
|
|
|
assert(ws == L"a");
|
|
|
|
ws = myconv.from_bytes(bs.c_str());
|
|
|
|
assert(ws == L"\x40003");
|
|
|
|
ws = myconv.from_bytes(bs);
|
|
|
|
assert(ws == L"\x40003");
|
|
|
|
ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
|
|
|
|
assert(ws == L"\x40003");
|
2012-07-12 20:07:41 +02:00
|
|
|
ws = myconv.from_bytes("");
|
|
|
|
assert(ws.size() == 0);
|
2010-05-31 22:58:54 +02:00
|
|
|
}
|
|
|
|
}
|