widen_many.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
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// template <class charT> class ctype_byname;
13
14// const char* widen(const char* low, const char* high, charT* to) const;
15
16// I doubt this test is portable
17
18#include <locale>
19#include <string>
20#include <vector>
21#include <cassert>
22
23int main()
24{
25    {
26        std::locale l("en_US");
27        {
28            typedef std::ctype<wchar_t> F;
29            const F& f = std::use_facet<F>(l);
30            std::string in(" A\x07.a1\x85");
31            std::vector<wchar_t> v(in.size());
32
33            assert(f.widen(&in[0], in.data() + in.size(), v.data()) == in.data() + in.size());
34            assert(v[0] == L' ');
35            assert(v[1] == L'A');
36            assert(v[2] == L'\x07');
37            assert(v[3] == L'.');
38            assert(v[4] == L'a');
39            assert(v[5] == L'1');
40            assert(v[6] == wchar_t(-1));
41        }
42    }
43    {
44        std::locale l("C");
45        {
46            typedef std::ctype<wchar_t> F;
47            const F& f = std::use_facet<F>(l);
48            std::string in(" A\x07.a1\x85");
49            std::vector<wchar_t> v(in.size());
50
51            assert(f.widen(&in[0], in.data() + in.size(), v.data()) == in.data() + in.size());
52            assert(v[0] == L' ');
53            assert(v[1] == L'A');
54            assert(v[2] == L'\x07');
55            assert(v[3] == L'.');
56            assert(v[4] == L'a');
57            assert(v[5] == L'1');
58            assert(v[6] == wchar_t(133));
59        }
60    }
61}
62