| 1 |
// 2003-05-27 Brendan Kehoe <[email protected]> |
| 2 |
|
| 3 |
// Copyright (C) 2003-2025 Free Software Foundation, Inc. |
| 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 |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 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 |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// $22.2.6.3/3 |
| 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; |
| 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"); |
| 52 |
greed.get(liffey, end, false, liffey, err01, coins); |
| 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"); |
| 60 |
greed.get(liffey, end, false, liffey, err01, coins); |
| 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"); |
| 68 |
greed.get(liffey, end, false, liffey, err01, coins); |
| 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."); |
| 76 |
greed.get(liffey, end, false, liffey, err01, coins); |
| 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"); |
| 84 |
greed.get(liffey, end, false, liffey, err01, coins); |
| 85 |
if ( err01 & std::ios_base::failbit ) |
| 86 |
fails |= 0x10; |
| 87 |
|
| 88 |
return fails; |
| 89 |
} |