from_bytes.pass.cpp revision d23b464e21648e252d5ae501b2db2e93dc02b1f7
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. 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    }
37}
38