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>
|
|
|
|
|
|
|
|
// byte_string to_bytes(Elem wchar);
|
|
|
|
// byte_string to_bytes(const Elem* wptr);
|
|
|
|
// byte_string to_bytes(const wide_string& wstr);
|
|
|
|
// byte_string to_bytes(const Elem* first, const Elem* last);
|
|
|
|
|
|
|
|
#include <locale>
|
|
|
|
#include <codecvt>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
|
|
|
|
std::wstring ws(1, L'\x40003');
|
|
|
|
std::string bs = myconv.to_bytes(ws[0]);
|
|
|
|
assert(bs == "\xF1\x80\x80\x83");
|
|
|
|
bs = myconv.to_bytes(ws.c_str());
|
|
|
|
assert(bs == "\xF1\x80\x80\x83");
|
|
|
|
bs = myconv.to_bytes(ws);
|
|
|
|
assert(bs == "\xF1\x80\x80\x83");
|
|
|
|
bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
|
|
|
|
assert(bs == "\xF1\x80\x80\x83");
|
2012-07-12 20:07:41 +02:00
|
|
|
bs = myconv.to_bytes(L"");
|
|
|
|
assert(bs.size() == 0);
|
2010-05-31 22:58:54 +02:00
|
|
|
}
|
|
|
|
}
|