]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/localization/locale.categories/category.ctype/locale.ctype.byname/tolower_many.pass.cpp
Vendor import of libc++ trunk r302418:
[FreeBSD/FreeBSD.git] / test / std / localization / locale.categories / category.ctype / locale.ctype.byname / tolower_many.pass.cpp
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
12 // <locale>
13
14 // template <class charT> class ctype_byname;
15
16 // const charT* tolower(charT* low, const charT* high) const;
17
18 #include <locale>
19 #include <string>
20 #include <cassert>
21
22 #include "platform_support.h" // locale name macros
23
24 int main()
25 {
26     {
27         std::locale l;
28         {
29             typedef std::ctype_byname<char> F;
30             std::locale ll(l, new F(LOCALE_en_US_UTF_8));
31             const F& f = std::use_facet<F>(ll);
32             std::string in("c A\x07.a1");
33
34             assert(f.tolower(&in[0], in.data() + in.size()) == in.data() + in.size());
35             assert(in[0] == 'c');
36             assert(in[1] == ' ');
37             assert(in[2] == 'a');
38             assert(in[3] == '\x07');
39             assert(in[4] == '.');
40             assert(in[5] == 'a');
41             assert(in[6] == '1');
42         }
43     }
44     {
45         std::locale l;
46         {
47             typedef std::ctype_byname<char> F;
48             std::locale ll(l, new F("C"));
49             const F& f = std::use_facet<F>(ll);
50             std::string in("\xDA A\x07.a1");
51
52             assert(f.tolower(&in[0], in.data() + in.size()) == in.data() + in.size());
53             assert(in[0] == '\xDA');
54             assert(in[1] == ' ');
55             assert(in[2] == 'a');
56             assert(in[3] == '\x07');
57             assert(in[4] == '.');
58             assert(in[5] == 'a');
59             assert(in[6] == '1');
60         }
61     }
62     {
63         std::locale l;
64         {
65             typedef std::ctype_byname<wchar_t> F;
66             std::locale ll(l, new F(LOCALE_en_US_UTF_8));
67             const F& f = std::use_facet<F>(ll);
68             std::wstring in(L"\xDA A\x07.a1");
69
70             assert(f.tolower(&in[0], in.data() + in.size()) == in.data() + in.size());
71             assert(in[0] == L'\xFA');
72             assert(in[1] == L' ');
73             assert(in[2] == L'a');
74             assert(in[3] == L'\x07');
75             assert(in[4] == L'.');
76             assert(in[5] == L'a');
77             assert(in[6] == L'1');
78         }
79     }
80     {
81         std::locale l;
82         {
83             typedef std::ctype_byname<wchar_t> F;
84             std::locale ll(l, new F("C"));
85             const F& f = std::use_facet<F>(ll);
86             std::wstring in(L"\xDA A\x07.a1");
87
88             assert(f.tolower(&in[0], in.data() + in.size()) == in.data() + in.size());
89             assert(in[0] == L'\xDA');
90             assert(in[1] == L' ');
91             assert(in[2] == L'a');
92             assert(in[3] == L'\x07');
93             assert(in[4] == L'.');
94             assert(in[5] == L'a');
95             assert(in[6] == L'1');
96         }
97     }
98 }