Home | History | Annotate | Download | only in conversions.string
      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 // wide_string from_bytes(char byte);
     15 // wide_string from_bytes(const char* ptr);
     16 // wide_string from_bytes(const byte_string& str);
     17 // wide_string from_bytes(const char* first, const char* last);
     18 
     19 #include <locale>
     20 #include <codecvt>
     21 #include <cassert>
     22 
     23 int main()
     24 {
     25     {
     26         std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
     27         std::string bs("\xF1\x80\x80\x83");
     28         std::wstring ws = myconv.from_bytes('a');
     29         assert(ws == L"a");
     30         ws = myconv.from_bytes(bs.c_str());
     31         assert(ws == L"\x40003");
     32         ws = myconv.from_bytes(bs);
     33         assert(ws == L"\x40003");
     34         ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
     35         assert(ws == L"\x40003");
     36         ws = myconv.from_bytes("");
     37         assert(ws.size() == 0);
     38     }
     39 }
     40