from_bytes.pass.cpp revision 1ca23672a0a694a6979b6e62d7893d8fe019a664
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 23int 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