1*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc 
10*4684ddb6SLionel Sambuc // <locale>
11*4684ddb6SLionel Sambuc 
12*4684ddb6SLionel Sambuc // class num_put<charT, OutputIterator>
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc // iter_type put(iter_type s, ios_base& iob, char_type fill, long long v) const;
15*4684ddb6SLionel Sambuc 
16*4684ddb6SLionel Sambuc #include <locale>
17*4684ddb6SLionel Sambuc #include <ios>
18*4684ddb6SLionel Sambuc #include <cassert>
19*4684ddb6SLionel Sambuc #include <streambuf>
20*4684ddb6SLionel Sambuc #include "test_iterators.h"
21*4684ddb6SLionel Sambuc 
22*4684ddb6SLionel Sambuc typedef std::num_put<char, output_iterator<char*> > F;
23*4684ddb6SLionel Sambuc 
24*4684ddb6SLionel Sambuc class my_facet
25*4684ddb6SLionel Sambuc     : public F
26*4684ddb6SLionel Sambuc {
27*4684ddb6SLionel Sambuc public:
my_facet(std::size_t refs=0)28*4684ddb6SLionel Sambuc     explicit my_facet(std::size_t refs = 0)
29*4684ddb6SLionel Sambuc         : F(refs) {}
30*4684ddb6SLionel Sambuc };
31*4684ddb6SLionel Sambuc 
32*4684ddb6SLionel Sambuc class my_numpunct
33*4684ddb6SLionel Sambuc     : public std::numpunct<char>
34*4684ddb6SLionel Sambuc {
35*4684ddb6SLionel Sambuc public:
my_numpunct()36*4684ddb6SLionel Sambuc     my_numpunct() : std::numpunct<char>() {}
37*4684ddb6SLionel Sambuc 
38*4684ddb6SLionel Sambuc protected:
do_thousands_sep() const39*4684ddb6SLionel Sambuc     virtual char_type do_thousands_sep() const {return '_';}
do_grouping() const40*4684ddb6SLionel Sambuc     virtual std::string do_grouping() const {return std::string("\1\2\3");}
41*4684ddb6SLionel Sambuc };
42*4684ddb6SLionel Sambuc 
main()43*4684ddb6SLionel Sambuc int main()
44*4684ddb6SLionel Sambuc {
45*4684ddb6SLionel Sambuc     const my_facet f(1);
46*4684ddb6SLionel Sambuc     {
47*4684ddb6SLionel Sambuc         std::ios ios(0);
48*4684ddb6SLionel Sambuc         long long v = 0;
49*4684ddb6SLionel Sambuc         char str[50];
50*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
51*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
52*4684ddb6SLionel Sambuc         assert(ex == "0");
53*4684ddb6SLionel Sambuc     }
54*4684ddb6SLionel Sambuc     {
55*4684ddb6SLionel Sambuc         std::ios ios(0);
56*4684ddb6SLionel Sambuc         long long v = 1;
57*4684ddb6SLionel Sambuc         char str[50];
58*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
59*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
60*4684ddb6SLionel Sambuc         assert(ex == "1");
61*4684ddb6SLionel Sambuc     }
62*4684ddb6SLionel Sambuc     {
63*4684ddb6SLionel Sambuc         std::ios ios(0);
64*4684ddb6SLionel Sambuc         long long v = -1;
65*4684ddb6SLionel Sambuc         char str[50];
66*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
67*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
68*4684ddb6SLionel Sambuc         assert(ex == "-1");
69*4684ddb6SLionel Sambuc     }
70*4684ddb6SLionel Sambuc     {
71*4684ddb6SLionel Sambuc         std::ios ios(0);
72*4684ddb6SLionel Sambuc         long long v = -1000;
73*4684ddb6SLionel Sambuc         char str[50];
74*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
75*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
76*4684ddb6SLionel Sambuc         assert(ex == "-1000");
77*4684ddb6SLionel Sambuc     }
78*4684ddb6SLionel Sambuc     {
79*4684ddb6SLionel Sambuc         std::ios ios(0);
80*4684ddb6SLionel Sambuc         long long v = 1000;
81*4684ddb6SLionel Sambuc         char str[50];
82*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
83*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
84*4684ddb6SLionel Sambuc         assert(ex == "1000");
85*4684ddb6SLionel Sambuc     }
86*4684ddb6SLionel Sambuc     {
87*4684ddb6SLionel Sambuc         std::ios ios(0);
88*4684ddb6SLionel Sambuc         showpos(ios);
89*4684ddb6SLionel Sambuc         long long v = 1000;
90*4684ddb6SLionel Sambuc         char str[50];
91*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
92*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
93*4684ddb6SLionel Sambuc         assert(ex == "+1000");
94*4684ddb6SLionel Sambuc     }
95*4684ddb6SLionel Sambuc     {
96*4684ddb6SLionel Sambuc         std::ios ios(0);
97*4684ddb6SLionel Sambuc         oct(ios);
98*4684ddb6SLionel Sambuc         long long v = 1000;
99*4684ddb6SLionel Sambuc         char str[50];
100*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
101*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
102*4684ddb6SLionel Sambuc         assert(ex == "1750");
103*4684ddb6SLionel Sambuc     }
104*4684ddb6SLionel Sambuc     {
105*4684ddb6SLionel Sambuc         std::ios ios(0);
106*4684ddb6SLionel Sambuc         oct(ios);
107*4684ddb6SLionel Sambuc         showbase(ios);
108*4684ddb6SLionel Sambuc         long long v = 1000;
109*4684ddb6SLionel Sambuc         char str[50];
110*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
111*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
112*4684ddb6SLionel Sambuc         assert(ex == "01750");
113*4684ddb6SLionel Sambuc     }
114*4684ddb6SLionel Sambuc     {
115*4684ddb6SLionel Sambuc         std::ios ios(0);
116*4684ddb6SLionel Sambuc         hex(ios);
117*4684ddb6SLionel Sambuc         long long v = 1000;
118*4684ddb6SLionel Sambuc         char str[50];
119*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
120*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
121*4684ddb6SLionel Sambuc         assert(ex == "3e8");
122*4684ddb6SLionel Sambuc     }
123*4684ddb6SLionel Sambuc     {
124*4684ddb6SLionel Sambuc         std::ios ios(0);
125*4684ddb6SLionel Sambuc         hex(ios);
126*4684ddb6SLionel Sambuc         showbase(ios);
127*4684ddb6SLionel Sambuc         long long v = 1000;
128*4684ddb6SLionel Sambuc         char str[50];
129*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
130*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
131*4684ddb6SLionel Sambuc         assert(ex == "0x3e8");
132*4684ddb6SLionel Sambuc     }
133*4684ddb6SLionel Sambuc     {
134*4684ddb6SLionel Sambuc         std::ios ios(0);
135*4684ddb6SLionel Sambuc         hex(ios);
136*4684ddb6SLionel Sambuc         showbase(ios);
137*4684ddb6SLionel Sambuc         uppercase(ios);
138*4684ddb6SLionel Sambuc         long long v = 1000;
139*4684ddb6SLionel Sambuc         char str[50];
140*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
141*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
142*4684ddb6SLionel Sambuc         assert(ex == "0X3E8");
143*4684ddb6SLionel Sambuc     }
144*4684ddb6SLionel Sambuc     {
145*4684ddb6SLionel Sambuc         std::ios ios(0);
146*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
147*4684ddb6SLionel Sambuc         hex(ios);
148*4684ddb6SLionel Sambuc         showbase(ios);
149*4684ddb6SLionel Sambuc         uppercase(ios);
150*4684ddb6SLionel Sambuc         long long v = 1000;
151*4684ddb6SLionel Sambuc         char str[50];
152*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
153*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
154*4684ddb6SLionel Sambuc         assert(ex == "0X3E_8");
155*4684ddb6SLionel Sambuc     }
156*4684ddb6SLionel Sambuc     {
157*4684ddb6SLionel Sambuc         std::ios ios(0);
158*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
159*4684ddb6SLionel Sambuc         hex(ios);
160*4684ddb6SLionel Sambuc         showbase(ios);
161*4684ddb6SLionel Sambuc         long long v = 2147483647;
162*4684ddb6SLionel Sambuc         char str[50];
163*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
164*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
165*4684ddb6SLionel Sambuc         assert(ex == "0x7f_fff_ff_f");
166*4684ddb6SLionel Sambuc     }
167*4684ddb6SLionel Sambuc     {
168*4684ddb6SLionel Sambuc         std::ios ios(0);
169*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
170*4684ddb6SLionel Sambuc         oct(ios);
171*4684ddb6SLionel Sambuc         long long v = 0123467;
172*4684ddb6SLionel Sambuc         char str[50];
173*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
174*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
175*4684ddb6SLionel Sambuc         assert(ex == "123_46_7");
176*4684ddb6SLionel Sambuc     }
177*4684ddb6SLionel Sambuc     {
178*4684ddb6SLionel Sambuc         std::ios ios(0);
179*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
180*4684ddb6SLionel Sambuc         oct(ios);
181*4684ddb6SLionel Sambuc         showbase(ios);
182*4684ddb6SLionel Sambuc         long long v = 0123467;
183*4684ddb6SLionel Sambuc         char str[50];
184*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
185*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
186*4684ddb6SLionel Sambuc         assert(ex == "0_123_46_7");
187*4684ddb6SLionel Sambuc     }
188*4684ddb6SLionel Sambuc     {
189*4684ddb6SLionel Sambuc         std::ios ios(0);
190*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
191*4684ddb6SLionel Sambuc         oct(ios);
192*4684ddb6SLionel Sambuc         showbase(ios);
193*4684ddb6SLionel Sambuc         right(ios);
194*4684ddb6SLionel Sambuc         ios.width(15);
195*4684ddb6SLionel Sambuc         long long v = 0123467;
196*4684ddb6SLionel Sambuc         char str[50];
197*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
198*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
199*4684ddb6SLionel Sambuc         assert(ex == "*****0_123_46_7");
200*4684ddb6SLionel Sambuc     }
201*4684ddb6SLionel Sambuc     {
202*4684ddb6SLionel Sambuc         std::ios ios(0);
203*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
204*4684ddb6SLionel Sambuc         oct(ios);
205*4684ddb6SLionel Sambuc         showbase(ios);
206*4684ddb6SLionel Sambuc         left(ios);
207*4684ddb6SLionel Sambuc         ios.width(15);
208*4684ddb6SLionel Sambuc         long long v = 0123467;
209*4684ddb6SLionel Sambuc         char str[50];
210*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
211*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
212*4684ddb6SLionel Sambuc         assert(ex == "0_123_46_7*****");
213*4684ddb6SLionel Sambuc     }
214*4684ddb6SLionel Sambuc     {
215*4684ddb6SLionel Sambuc         std::ios ios(0);
216*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
217*4684ddb6SLionel Sambuc         oct(ios);
218*4684ddb6SLionel Sambuc         showbase(ios);
219*4684ddb6SLionel Sambuc         internal(ios);
220*4684ddb6SLionel Sambuc         ios.width(15);
221*4684ddb6SLionel Sambuc         long long v = 0123467;
222*4684ddb6SLionel Sambuc         char str[50];
223*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
224*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
225*4684ddb6SLionel Sambuc         assert(ex == "*****0_123_46_7");
226*4684ddb6SLionel Sambuc         assert(ios.width() == 0);
227*4684ddb6SLionel Sambuc     }
228*4684ddb6SLionel Sambuc     {
229*4684ddb6SLionel Sambuc         std::ios ios(0);
230*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
231*4684ddb6SLionel Sambuc         hex(ios);
232*4684ddb6SLionel Sambuc         showbase(ios);
233*4684ddb6SLionel Sambuc         right(ios);
234*4684ddb6SLionel Sambuc         ios.width(15);
235*4684ddb6SLionel Sambuc         long long v = 2147483647;
236*4684ddb6SLionel Sambuc         char str[50];
237*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
238*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
239*4684ddb6SLionel Sambuc         assert(ex == "**0x7f_fff_ff_f");
240*4684ddb6SLionel Sambuc     }
241*4684ddb6SLionel Sambuc     {
242*4684ddb6SLionel Sambuc         std::ios ios(0);
243*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
244*4684ddb6SLionel Sambuc         hex(ios);
245*4684ddb6SLionel Sambuc         showbase(ios);
246*4684ddb6SLionel Sambuc         left(ios);
247*4684ddb6SLionel Sambuc         ios.width(15);
248*4684ddb6SLionel Sambuc         long long v = 2147483647;
249*4684ddb6SLionel Sambuc         char str[50];
250*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
251*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
252*4684ddb6SLionel Sambuc         assert(ex == "0x7f_fff_ff_f**");
253*4684ddb6SLionel Sambuc     }
254*4684ddb6SLionel Sambuc     {
255*4684ddb6SLionel Sambuc         std::ios ios(0);
256*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
257*4684ddb6SLionel Sambuc         hex(ios);
258*4684ddb6SLionel Sambuc         showbase(ios);
259*4684ddb6SLionel Sambuc         internal(ios);
260*4684ddb6SLionel Sambuc         ios.width(15);
261*4684ddb6SLionel Sambuc         long long v = 2147483647;
262*4684ddb6SLionel Sambuc         char str[50];
263*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
264*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
265*4684ddb6SLionel Sambuc         assert(ex == "0x**7f_fff_ff_f");
266*4684ddb6SLionel Sambuc         assert(ios.width() == 0);
267*4684ddb6SLionel Sambuc     }
268*4684ddb6SLionel Sambuc     {
269*4684ddb6SLionel Sambuc         std::ios ios(0);
270*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
271*4684ddb6SLionel Sambuc         showpos(ios);
272*4684ddb6SLionel Sambuc         long long v = 1000;
273*4684ddb6SLionel Sambuc         right(ios);
274*4684ddb6SLionel Sambuc         ios.width(10);
275*4684ddb6SLionel Sambuc         char str[50];
276*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
277*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
278*4684ddb6SLionel Sambuc         assert(ex == "***+1_00_0");
279*4684ddb6SLionel Sambuc         assert(ios.width() == 0);
280*4684ddb6SLionel Sambuc     }
281*4684ddb6SLionel Sambuc     {
282*4684ddb6SLionel Sambuc         std::ios ios(0);
283*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
284*4684ddb6SLionel Sambuc         showpos(ios);
285*4684ddb6SLionel Sambuc         long long v = 1000;
286*4684ddb6SLionel Sambuc         left(ios);
287*4684ddb6SLionel Sambuc         ios.width(10);
288*4684ddb6SLionel Sambuc         char str[50];
289*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
290*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
291*4684ddb6SLionel Sambuc         assert(ex == "+1_00_0***");
292*4684ddb6SLionel Sambuc         assert(ios.width() == 0);
293*4684ddb6SLionel Sambuc     }
294*4684ddb6SLionel Sambuc     {
295*4684ddb6SLionel Sambuc         std::ios ios(0);
296*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
297*4684ddb6SLionel Sambuc         showpos(ios);
298*4684ddb6SLionel Sambuc         long long v = 1000;
299*4684ddb6SLionel Sambuc         internal(ios);
300*4684ddb6SLionel Sambuc         ios.width(10);
301*4684ddb6SLionel Sambuc         char str[50];
302*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
303*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
304*4684ddb6SLionel Sambuc         assert(ex == "+***1_00_0");
305*4684ddb6SLionel Sambuc         assert(ios.width() == 0);
306*4684ddb6SLionel Sambuc     }
307*4684ddb6SLionel Sambuc     {
308*4684ddb6SLionel Sambuc         std::ios ios(0);
309*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
310*4684ddb6SLionel Sambuc         long long v = -1000;
311*4684ddb6SLionel Sambuc         right(ios);
312*4684ddb6SLionel Sambuc         showpos(ios);
313*4684ddb6SLionel Sambuc         ios.width(10);
314*4684ddb6SLionel Sambuc         char str[50];
315*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
316*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
317*4684ddb6SLionel Sambuc         assert(ex == "***-1_00_0");
318*4684ddb6SLionel Sambuc         assert(ios.width() == 0);
319*4684ddb6SLionel Sambuc     }
320*4684ddb6SLionel Sambuc     {
321*4684ddb6SLionel Sambuc         std::ios ios(0);
322*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
323*4684ddb6SLionel Sambuc         long long v = -1000;
324*4684ddb6SLionel Sambuc         left(ios);
325*4684ddb6SLionel Sambuc         ios.width(10);
326*4684ddb6SLionel Sambuc         char str[50];
327*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
328*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
329*4684ddb6SLionel Sambuc         assert(ex == "-1_00_0***");
330*4684ddb6SLionel Sambuc         assert(ios.width() == 0);
331*4684ddb6SLionel Sambuc     }
332*4684ddb6SLionel Sambuc     {
333*4684ddb6SLionel Sambuc         std::ios ios(0);
334*4684ddb6SLionel Sambuc         ios.imbue(std::locale(std::locale::classic(), new my_numpunct));
335*4684ddb6SLionel Sambuc         long long v = -1000;
336*4684ddb6SLionel Sambuc         internal(ios);
337*4684ddb6SLionel Sambuc         ios.width(10);
338*4684ddb6SLionel Sambuc         char str[50];
339*4684ddb6SLionel Sambuc         output_iterator<char*> iter = f.put(output_iterator<char*>(str), ios, '*', v);
340*4684ddb6SLionel Sambuc         std::string ex(str, iter.base());
341*4684ddb6SLionel Sambuc         assert(ex == "-***1_00_0");
342*4684ddb6SLionel Sambuc         assert(ios.width() == 0);
343*4684ddb6SLionel Sambuc     }
344*4684ddb6SLionel Sambuc }
345