| 1 |
// { dg-require-namedlocale "en_HK.ISO8859-1" } |
| 2 |
|
| 3 |
// 2001-09-12 Benjamin Kosnik <[email protected]> |
| 4 |
|
| 5 |
// Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 6 |
// |
| 7 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 8 |
// software; you can redistribute it and/or modify it under the |
| 9 |
// terms of the GNU General Public License as published by the |
| 10 |
// Free Software Foundation; either version 3, or (at your option) |
| 11 |
// any later version. |
| 12 |
|
| 13 |
// This library is distributed in the hope that it will be useful, |
| 14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
// GNU General Public License for more details. |
| 17 |
|
| 18 |
// You should have received a copy of the GNU General Public License along |
| 19 |
// with this library; see the file COPYING3. If not see |
| 20 |
// <http://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
// 22.2.6.1.1 money_get members |
| 23 |
|
| 24 |
#include <locale> |
| 25 |
#include <sstream> |
| 26 |
#include <testsuite_hooks.h> |
| 27 |
|
| 28 |
// test string version |
| 29 |
void test02() |
| 30 |
{ |
| 31 |
using namespace std; |
| 32 |
typedef istreambuf_iterator<char> iterator_type; |
| 33 |
|
| 34 |
// basic construction |
| 35 |
locale loc_c = locale::classic(); |
| 36 |
locale loc_hk = locale(ISO_8859(1,en_HK)); |
| 37 |
VERIFY( loc_c != loc_hk ); |
| 38 |
|
| 39 |
// total EPA budget FY 2002 |
| 40 |
const string digits1("720000000000"); |
| 41 |
|
| 42 |
// est. cost, national missile "defense", expressed as a loss in USD 2001 |
| 43 |
const string digits2("-10000000000000"); |
| 44 |
|
| 45 |
// input less than frac_digits |
| 46 |
const string digits4("-1"); |
| 47 |
|
| 48 |
iterator_type end; |
| 49 |
istringstream iss; |
| 50 |
iss.imbue(loc_hk); |
| 51 |
// cache the money_get facet |
| 52 |
const money_get<char>& mon_get = use_facet<money_get<char> >(iss.getloc()); |
| 53 |
|
| 54 |
// now try with showbase, to get currency symbol in format |
| 55 |
iss.setf(ios_base::showbase); |
| 56 |
|
| 57 |
iss.str("HK$7,200,000,000.00"); |
| 58 |
iterator_type is_it09(iss); |
| 59 |
string result9; |
| 60 |
ios_base::iostate err09 = ios_base::goodbit; |
| 61 |
mon_get.get(is_it09, end, false, iss, err09, result9); |
| 62 |
VERIFY( result9 == digits1 ); |
| 63 |
VERIFY( err09 == ios_base::eofbit ); |
| 64 |
|
| 65 |
iss.str("(HKD 100,000,000,000.00)"); |
| 66 |
iterator_type is_it10(iss); |
| 67 |
string result10; |
| 68 |
ios_base::iostate err10 = ios_base::goodbit; |
| 69 |
mon_get.get(is_it10, end, true, iss, err10, result10); |
| 70 |
VERIFY( result10 == digits2 ); |
| 71 |
VERIFY( err10 == ios_base::eofbit ); |
| 72 |
|
| 73 |
iss.str("(HKD .01)"); |
| 74 |
iterator_type is_it11(iss); |
| 75 |
string result11; |
| 76 |
ios_base::iostate err11 = ios_base::goodbit; |
| 77 |
mon_get.get(is_it11, end, true, iss, err11, result11); |
| 78 |
VERIFY( result11 == digits4 ); |
| 79 |
VERIFY( err11 == ios_base::eofbit ); |
| 80 |
|
| 81 |
// for the "en_HK.ISO8859-1" locale the parsing of the very same input streams must |
| 82 |
// be successful without showbase too, since the symbol field appears in |
| 83 |
// the first positions in the format and the symbol, when present, must be |
| 84 |
// consumed. |
| 85 |
iss.unsetf(ios_base::showbase); |
| 86 |
|
| 87 |
iss.str("HK$7,200,000,000.00"); |
| 88 |
iterator_type is_it12(iss); |
| 89 |
string result12; |
| 90 |
ios_base::iostate err12 = ios_base::goodbit; |
| 91 |
mon_get.get(is_it12, end, false, iss, err12, result12); |
| 92 |
VERIFY( result12 == digits1 ); |
| 93 |
VERIFY( err12 == ios_base::eofbit ); |
| 94 |
|
| 95 |
iss.str("(HKD 100,000,000,000.00)"); |
| 96 |
iterator_type is_it13(iss); |
| 97 |
string result13; |
| 98 |
ios_base::iostate err13 = ios_base::goodbit; |
| 99 |
mon_get.get(is_it13, end, true, iss, err13, result13); |
| 100 |
VERIFY( result13 == digits2 ); |
| 101 |
VERIFY( err13 == ios_base::eofbit ); |
| 102 |
|
| 103 |
iss.str("(HKD .01)"); |
| 104 |
iterator_type is_it14(iss); |
| 105 |
string result14; |
| 106 |
ios_base::iostate err14 = ios_base::goodbit; |
| 107 |
mon_get.get(is_it14, end, true, iss, err14, result14); |
| 108 |
VERIFY( result14 == digits4 ); |
| 109 |
VERIFY( err14 == ios_base::eofbit ); |
| 110 |
} |
| 111 |
|
| 112 |
int main() |
| 113 |
{ |
| 114 |
test02(); |
| 115 |
return 0; |
| 116 |
} |