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_FR.UTF-8
12 // REQUIRES: locale.ru_RU.UTF-8
13 // REQUIRES: locale.zh_CN.UTF-8
14 
15 // <locale>
16 
17 // class moneypunct_byname<charT, International>
18 
19 // charT thousands_sep() const;
20 
21 // Failure related to GLIBC's use of U00A0 as mon_thousands_sep
22 // and U002E as mon_decimal_point.
23 // TODO: U00A0 should be investigated.
24 // Possibly related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=16006
25 // XFAIL: linux-gnu
26 
27 #include <locale>
28 #include <limits>
29 #include <cassert>
30 
31 #include "platform_support.h" // locale name macros
32 
33 class Fnf
34     : public std::moneypunct_byname<char, false>
35 {
36 public:
Fnf(const std::string & nm,std::size_t refs=0)37     explicit Fnf(const std::string& nm, std::size_t refs = 0)
38         : std::moneypunct_byname<char, false>(nm, refs) {}
39 };
40 
41 class Fnt
42     : public std::moneypunct_byname<char, true>
43 {
44 public:
Fnt(const std::string & nm,std::size_t refs=0)45     explicit Fnt(const std::string& nm, std::size_t refs = 0)
46         : std::moneypunct_byname<char, true>(nm, refs) {}
47 };
48 
49 class Fwf
50     : public std::moneypunct_byname<wchar_t, false>
51 {
52 public:
Fwf(const std::string & nm,std::size_t refs=0)53     explicit Fwf(const std::string& nm, std::size_t refs = 0)
54         : std::moneypunct_byname<wchar_t, false>(nm, refs) {}
55 };
56 
57 class Fwt
58     : public std::moneypunct_byname<wchar_t, true>
59 {
60 public:
Fwt(const std::string & nm,std::size_t refs=0)61     explicit Fwt(const std::string& nm, std::size_t refs = 0)
62         : std::moneypunct_byname<wchar_t, true>(nm, refs) {}
63 };
64 
main()65 int main()
66 {
67     {
68         Fnf f("C", 1);
69         assert(f.thousands_sep() == std::numeric_limits<char>::max());
70     }
71     {
72         Fnt f("C", 1);
73         assert(f.thousands_sep() == std::numeric_limits<char>::max());
74     }
75     {
76         Fwf f("C", 1);
77         assert(f.thousands_sep() == std::numeric_limits<wchar_t>::max());
78     }
79     {
80         Fwt f("C", 1);
81         assert(f.thousands_sep() == std::numeric_limits<wchar_t>::max());
82     }
83 
84     {
85         Fnf f(LOCALE_en_US_UTF_8, 1);
86         assert(f.thousands_sep() == ',');
87     }
88     {
89         Fnt f(LOCALE_en_US_UTF_8, 1);
90         assert(f.thousands_sep() == ',');
91     }
92     {
93         Fwf f(LOCALE_en_US_UTF_8, 1);
94         assert(f.thousands_sep() == L',');
95     }
96     {
97         Fwt f(LOCALE_en_US_UTF_8, 1);
98         assert(f.thousands_sep() == L',');
99     }
100 
101     {
102         Fnf f(LOCALE_fr_FR_UTF_8, 1);
103         assert(f.thousands_sep() == ' ');
104     }
105     {
106         Fnt f(LOCALE_fr_FR_UTF_8, 1);
107         assert(f.thousands_sep() == ' ');
108     }
109     {
110         Fwf f(LOCALE_fr_FR_UTF_8, 1);
111         assert(f.thousands_sep() == L' ');
112     }
113     {
114         Fwt f(LOCALE_fr_FR_UTF_8, 1);
115         assert(f.thousands_sep() == L' ');
116     }
117 
118     {
119         Fnf f(LOCALE_ru_RU_UTF_8, 1);
120         assert(f.thousands_sep() == ' ');
121     }
122     {
123         Fnt f(LOCALE_ru_RU_UTF_8, 1);
124         assert(f.thousands_sep() == ' ');
125     }
126     {
127         Fwf f(LOCALE_ru_RU_UTF_8, 1);
128         assert(f.thousands_sep() == L' ');
129     }
130     {
131         Fwt f(LOCALE_ru_RU_UTF_8, 1);
132         assert(f.thousands_sep() == L' ');
133     }
134 
135     {
136         Fnf f(LOCALE_zh_CN_UTF_8, 1);
137         assert(f.thousands_sep() == ',');
138     }
139     {
140         Fnt f(LOCALE_zh_CN_UTF_8, 1);
141         assert(f.thousands_sep() == ',');
142     }
143     {
144         Fwf f(LOCALE_zh_CN_UTF_8, 1);
145         assert(f.thousands_sep() == L',');
146     }
147     {
148         Fwt f(LOCALE_zh_CN_UTF_8, 1);
149         assert(f.thousands_sep() == L',');
150     }
151 }
152