| 1 |
// 2005-06-28 Paolo Carlini <[email protected]> |
| 2 |
|
| 3 |
// Copyright (C) 2005-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.1.1 money_get members |
| 21 |
|
| 22 |
#include <locale> |
| 23 |
#include <sstream> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
|
| 26 |
struct My_money_io : public std::moneypunct<wchar_t, false> |
| 27 |
{ |
| 28 |
std::string do_grouping() const { return "\1"; } |
| 29 |
char_type do_thousands_sep() const { return L'#'; } |
| 30 |
|
| 31 |
pattern do_neg_format() const |
| 32 |
{ |
| 33 |
pattern pat = { { symbol, none, sign, value } }; |
| 34 |
return pat; |
| 35 |
} |
| 36 |
}; |
| 37 |
|
| 38 |
// libstdc++/22131 |
| 39 |
void test01() |
| 40 |
{ |
| 41 |
using namespace std; |
| 42 |
typedef istreambuf_iterator<wchar_t> InIt; |
| 43 |
|
| 44 |
locale loc(locale::classic(), new My_money_io); |
| 45 |
|
| 46 |
wstring buffer1(L"00#0#1"); |
| 47 |
wstring buffer2(L"000##1"); |
| 48 |
|
| 49 |
bool intl = false; |
| 50 |
|
| 51 |
InIt iend1, iend2; |
| 52 |
ios_base::iostate err1, err2; |
| 53 |
wstring val1, val2; |
| 54 |
|
| 55 |
const money_get<wchar_t,InIt>& mg = |
| 56 |
use_facet<money_get<wchar_t, InIt> >(loc); |
| 57 |
|
| 58 |
wistringstream fmt1(buffer1); |
| 59 |
fmt1.imbue(loc); |
| 60 |
InIt ibeg1(fmt1); |
| 61 |
err1 = ios_base::goodbit; |
| 62 |
mg.get(ibeg1, iend1, intl, fmt1, err1, val1); |
| 63 |
VERIFY( err1 == (ios_base::eofbit | ios_base::failbit) ); |
| 64 |
VERIFY( val1 == L"1" ); |
| 65 |
|
| 66 |
wistringstream fmt2(buffer2); |
| 67 |
fmt2.imbue(loc); |
| 68 |
InIt ibeg2(fmt2); |
| 69 |
err2 = ios_base::goodbit; |
| 70 |
ibeg2 = mg.get(ibeg2, iend2, intl, fmt2, err2, val2); |
| 71 |
VERIFY( err2 == ios_base::failbit ); |
| 72 |
VERIFY( *ibeg2 == L'#' ); |
| 73 |
VERIFY( val2 == L"" ); |
| 74 |
} |
| 75 |
|
| 76 |
int main() |
| 77 |
{ |
| 78 |
test01(); |
| 79 |
return 0; |
| 80 |
} |