]>
Commit | Line | Data |
---|---|---|
f85716e0 BK |
1 | // 2003-05-27 Brendan Kehoe <brendan@zen.org> |
2 | ||
a945c346 | 3 | // Copyright (C) 2003-2024 Free Software Foundation, Inc. |
f85716e0 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) |
f85716e0 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/>. | |
f85716e0 | 19 | |
d9010fca | 20 | // $22.2.6.3/3 |
f85716e0 BK |
21 | // The number of digits required after the decimal point (if any) is exactly |
22 | // the value returned by frac_digits(). | |
23 | ||
24 | #include <locale> | |
25 | #include <sstream> | |
26 | ||
27 | class dublin : public std::moneypunct<wchar_t> { | |
28 | public: | |
29 | int do_frac_digits() const { return 3; } | |
30 | }; | |
31 | ||
32 | int main() | |
33 | { | |
34 | std::wistringstream liffey; | |
35 | std::wstring coins; | |
36 | ||
37 | std::locale eire(std::locale::classic(), new dublin); | |
38 | liffey.imbue(eire); | |
39 | ||
40 | const std::money_get<wchar_t>& greed | |
41 | = std::use_facet<std::money_get<wchar_t> >(liffey.getloc()); | |
42 | ||
43 | typedef std::istreambuf_iterator<wchar_t> iterator_type; | |
f85716e0 BK |
44 | iterator_type end; |
45 | ||
46 | std::ios_base::iostate err01 = std::ios_base::goodbit; | |
47 | ||
48 | int fails = 0; | |
49 | ||
50 | // Feed it 1 digit too many, which should fail. | |
51 | liffey.str(L"12.3456"); | |
e324f9cb | 52 | greed.get(liffey, end, false, liffey, err01, coins); |
f85716e0 BK |
53 | if (! (err01 & std::ios_base::failbit )) |
54 | fails |= 0x01; | |
55 | ||
56 | err01 = std::ios_base::goodbit; | |
57 | ||
58 | // Feed it exactly what it wants, which should succeed. | |
59 | liffey.str(L"12.345"); | |
e324f9cb | 60 | greed.get(liffey, end, false, liffey, err01, coins); |
f85716e0 BK |
61 | if ( err01 & std::ios_base::failbit ) |
62 | fails |= 0x02; | |
63 | ||
64 | err01 = std::ios_base::goodbit; | |
65 | ||
66 | // Feed it 1 digit too few, which should fail. | |
67 | liffey.str(L"12.34"); | |
e324f9cb | 68 | greed.get(liffey, end, false, liffey, err01, coins); |
f85716e0 BK |
69 | if (! ( err01 & std::ios_base::failbit )) |
70 | fails |= 0x04; | |
71 | ||
72 | err01 = std::ios_base::goodbit; | |
73 | ||
74 | // Feed it only a decimal-point, which should fail. | |
75 | liffey.str(L"12."); | |
e324f9cb | 76 | greed.get(liffey, end, false, liffey, err01, coins); |
f85716e0 BK |
77 | if (! (err01 & std::ios_base::failbit )) |
78 | fails |= 0x08; | |
79 | ||
80 | err01 = std::ios_base::goodbit; | |
81 | ||
82 | // Feed it no decimal-point at all, which should succeed. | |
83 | liffey.str(L"12"); | |
e324f9cb | 84 | greed.get(liffey, end, false, liffey, err01, coins); |
f85716e0 BK |
85 | if ( err01 & std::ios_base::failbit ) |
86 | fails |= 0x10; | |
87 | ||
88 | return fails; | |
89 | } |