]>
Commit | Line | Data |
---|---|---|
5f8d36fe BK |
1 | // 2001-09-12 Benjamin Kosnik <bkoz@redhat.com> |
2 | ||
748086b7 | 3 | // Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation |
5f8d36fe BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
5f8d36fe BK |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
5f8d36fe BK |
19 | |
20 | // 22.2.6.1.1 money_get members | |
21 | ||
22 | #include <locale> | |
23 | #include <sstream> | |
24 | #include <testsuite_hooks.h> | |
25 | ||
26 | struct My_money_io_a : public std::moneypunct<wchar_t,false> | |
27 | { | |
28 | char_type do_decimal_point() const { return '.'; } | |
29 | std::string do_grouping() const { return "\004"; } | |
30 | ||
31 | std::wstring do_curr_symbol() const { return L"$"; } | |
32 | std::wstring do_positive_sign() const { return L"()"; } | |
33 | ||
34 | int do_frac_digits() const { return 2; } | |
35 | ||
b7e64db2 | 36 | pattern do_neg_format() const |
5f8d36fe BK |
37 | { |
38 | pattern pat = { { sign, value, space, symbol } }; | |
39 | return pat; | |
40 | } | |
41 | }; | |
42 | ||
43 | struct My_money_io_b : public std::moneypunct<wchar_t,false> | |
44 | { | |
45 | char_type do_decimal_point() const { return '.'; } | |
46 | std::string do_grouping() const { return "\004"; } | |
47 | ||
48 | std::wstring do_curr_symbol() const { return L"$"; } | |
49 | std::wstring do_positive_sign() const { return L"()"; } | |
50 | ||
51 | int do_frac_digits() const { return 2; } | |
52 | ||
b7e64db2 | 53 | pattern do_neg_format() const |
5f8d36fe BK |
54 | { |
55 | pattern pat = { { sign, value, symbol, none } }; | |
56 | return pat; | |
57 | } | |
58 | }; | |
59 | ||
60 | // This one exercises patterns of the type { X, Y, Z, symbol } and | |
61 | // { X, Y, symbol, none } for a two character long sign. Therefore | |
62 | // the optional symbol (showbase is false by default) must be consumed | |
63 | // if present, since "rest of the sign" is left to read. | |
64 | void test08() | |
65 | { | |
66 | using namespace std; | |
67 | typedef istreambuf_iterator<wchar_t> InIt; | |
68 | ||
69 | bool intl = false; | |
11f10e6b | 70 | bool test __attribute__((unused)) = true; |
5f8d36fe BK |
71 | ios_base::iostate err; |
72 | ||
73 | locale loc_a(locale::classic(), new My_money_io_a); | |
74 | ||
75 | wstring buffer_a(L"(1234.56 $)"); | |
76 | wstring buffer_a_ns(L"(1234.56 )"); | |
77 | ||
78 | InIt iend_a, iend_a_ns; | |
79 | wstring val_a, val_a_ns; | |
80 | ||
81 | const money_get<wchar_t,InIt>& mg_a = use_facet<money_get<wchar_t, InIt> >(loc_a); | |
82 | ||
83 | wistringstream fmt_a(buffer_a); | |
84 | fmt_a.imbue(loc_a); | |
85 | InIt ibeg_a(fmt_a); | |
86 | mg_a.get(ibeg_a,iend_a,intl,fmt_a,err,val_a); | |
87 | VERIFY( val_a == L"123456" ); | |
88 | ||
89 | wistringstream fmt_a_ns(buffer_a_ns); | |
90 | fmt_a_ns.imbue(loc_a); | |
91 | InIt ibeg_a_ns(fmt_a_ns); | |
92 | mg_a.get(ibeg_a_ns,iend_a_ns,intl,fmt_a_ns,err,val_a_ns); | |
93 | VERIFY( val_a_ns == L"123456" ); | |
94 | ||
95 | locale loc_b(locale::classic(), new My_money_io_b); | |
96 | ||
97 | wstring buffer_b(L"(1234.56$)"); | |
98 | wstring buffer_b_ns(L"(1234.56)"); | |
99 | ||
100 | InIt iend_b, iend_b_ns; | |
101 | wstring val_b, val_b_ns; | |
102 | ||
103 | const money_get<wchar_t,InIt>& mg_b = use_facet<money_get<wchar_t, InIt> >(loc_b); | |
104 | ||
105 | wistringstream fmt_b(buffer_b); | |
106 | fmt_b.imbue(loc_b); | |
107 | InIt ibeg_b(fmt_b); | |
108 | mg_b.get(ibeg_b,iend_b,intl,fmt_b,err,val_b); | |
109 | VERIFY( val_b == L"123456" ); | |
110 | ||
111 | wistringstream fmt_b_ns(buffer_b_ns); | |
112 | fmt_b_ns.imbue(loc_b); | |
113 | InIt ibeg_b_ns(fmt_b_ns); | |
114 | mg_b.get(ibeg_b_ns,iend_b_ns,intl,fmt_b_ns,err,val_b_ns); | |
115 | VERIFY( val_b_ns == L"123456" ); | |
116 | } | |
117 | ||
118 | int main() | |
119 | { | |
120 | test08(); | |
121 | return 0; | |
122 | } |