1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <locale>
11 
12 // wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
13 
14 // byte_string to_bytes(Elem wchar);
15 // byte_string to_bytes(const Elem* wptr);
16 // byte_string to_bytes(const wide_string& wstr);
17 // byte_string to_bytes(const Elem* first, const Elem* last);
18 
19 #include <locale>
20 #include <codecvt>
21 #include <cassert>
22 
main()23 int main()
24 {
25     {
26         std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
27         std::wstring ws(1, L'\x40003');
28         std::string bs = myconv.to_bytes(ws[0]);
29         assert(bs == "\xF1\x80\x80\x83");
30         bs = myconv.to_bytes(ws.c_str());
31         assert(bs == "\xF1\x80\x80\x83");
32         bs = myconv.to_bytes(ws);
33         assert(bs == "\xF1\x80\x80\x83");
34         bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
35         assert(bs == "\xF1\x80\x80\x83");
36         bs = myconv.to_bytes(L"");
37         assert(bs.size() == 0);
38     }
39 }
40