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// REQUIRES: locale.en_US.UTF-8
11// REQUIRES: locale.fr_CA.ISO8859-1
12
13// <locale>
14
15// template <class charT> class ctype_byname;
16
17// const charT* narrow(const charT* low, const charT*, char dfault, char* to) const;
18
19#include <locale>
20#include <string>
21#include <vector>
22#include <cassert>
23
24#include "platform_support.h" // locale name macros
25
26int main()
27{
28    {
29        std::locale l(LOCALE_fr_CA_ISO8859_1);
30        {
31            typedef std::ctype<wchar_t> F;
32            const F& f = std::use_facet<F>(l);
33            std::wstring in(L" A\x07.a1\xDA");
34            std::vector<char> v(in.size());
35
36            assert(f.narrow(&in[0], in.data() + in.size(), '*', v.data()) == in.data() + in.size());
37            assert(v[0] == ' ');
38            assert(v[1] == 'A');
39            assert(v[2] == '\x07');
40            assert(v[3] == '.');
41            assert(v[4] == 'a');
42            assert(v[5] == '1');
43            assert(v[6] == '\xDA');
44        }
45    }
46    {
47        std::locale l(LOCALE_en_US_UTF_8);
48        {
49            typedef std::ctype<wchar_t> F;
50            const F& f = std::use_facet<F>(l);
51            std::wstring in(L" A\x07.a1\xDA");
52            std::vector<char> v(in.size());
53
54            assert(f.narrow(&in[0], in.data() + in.size(), '*', v.data()) == in.data() + in.size());
55            assert(v[0] == ' ');
56            assert(v[1] == 'A');
57            assert(v[2] == '\x07');
58            assert(v[3] == '.');
59            assert(v[4] == 'a');
60            assert(v[5] == '1');
61            assert(v[6] == '*');
62        }
63    }
64}
65