| 1 | // 2004-03-15 Paolo Carlini <[email protected]> |
| 2 | |
| 3 | // Copyright (C) 2004-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_01 : public std::moneypunct<wchar_t, false> |
| 27 | { |
| 28 | std::wstring do_curr_symbol() const { return L"$"; } |
| 29 | std::wstring do_positive_sign() const { return L""; } |
| 30 | std::wstring do_negative_sign() const { return L""; } |
| 31 | |
| 32 | pattern do_neg_format() const |
| 33 | { |
| 34 | pattern pat = { { value, symbol, none, sign } }; |
| 35 | return pat; |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | struct My_money_io_02 : public std::moneypunct<wchar_t, false> |
| 40 | { |
| 41 | std::wstring do_curr_symbol() const { return L"%"; } |
| 42 | std::wstring do_positive_sign() const { return L""; } |
| 43 | std::wstring do_negative_sign() const { return L"-"; } |
| 44 | |
| 45 | pattern do_neg_format() const |
| 46 | { |
| 47 | pattern pat = { { value, symbol, sign, none } }; |
| 48 | return pat; |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | struct My_money_io_03 : public std::moneypunct<wchar_t, false> |
| 53 | { |
| 54 | std::wstring do_curr_symbol() const { return L"&"; } |
| 55 | std::wstring do_positive_sign() const { return L""; } |
| 56 | std::wstring do_negative_sign() const { return L""; } |
| 57 | |
| 58 | pattern do_neg_format() const |
| 59 | { |
| 60 | pattern pat = { { value, space, symbol, sign } }; |
| 61 | return pat; |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | // When both do_positive_sign and do_negative_sign return an empty |
| 66 | // string, patterns of the forms { value, symbol, none, sign }, |
| 67 | // { value, symbol, sign, none } and { X, Y, symbol, sign } imply |
| 68 | // that the symbol is not consumed since no other characters are |
| 69 | // needed to complete the format. |
| 70 | void test01() |
| 71 | { |
| 72 | using namespace std; |
| 73 | typedef istreambuf_iterator<wchar_t> iterator_type; |
| 74 | |
| 75 | // basic construction |
| 76 | locale loc_01(locale::classic(), new My_money_io_01); |
| 77 | locale loc_02(locale::classic(), new My_money_io_02); |
| 78 | locale loc_03(locale::classic(), new My_money_io_03); |
| 79 | |
| 80 | iterator_type end, end01, end02, end03; |
| 81 | wistringstream iss_01, iss_02, iss_03; |
| 82 | iss_01.imbue(loc_01); |
| 83 | iss_02.imbue(loc_02); |
| 84 | iss_03.imbue(loc_03); |
| 85 | // cache the money_get facet |
| 86 | const money_get<wchar_t>& mon_get_01 = |
| 87 | use_facet<money_get<wchar_t> >(iss_01.getloc()); |
| 88 | const money_get<wchar_t>& mon_get_02 = |
| 89 | use_facet<money_get<wchar_t> >(iss_02.getloc()); |
| 90 | const money_get<wchar_t>& mon_get_03 = |
| 91 | use_facet<money_get<wchar_t> >(iss_03.getloc()); |
| 92 | |
| 93 | iss_01.str(L"10$"); |
| 94 | iterator_type is_it01(iss_01); |
| 95 | wstring result01; |
| 96 | ios_base::iostate err01 = ios_base::goodbit; |
| 97 | end01 = mon_get_01.get(is_it01, end, false, iss_01, err01, result01); |
| 98 | VERIFY( err01 == ios_base::goodbit ); |
| 99 | VERIFY( *end01 == L'$' ); |
| 100 | |
| 101 | iss_02.str(L"50%"); |
| 102 | iterator_type is_it02(iss_02); |
| 103 | wstring result02; |
| 104 | ios_base::iostate err02 = ios_base::goodbit; |
| 105 | end02 = mon_get_02.get(is_it02, end, false, iss_02, err02, result02); |
| 106 | VERIFY( err02 == ios_base::goodbit ); |
| 107 | VERIFY( *end02 == L'%' ); |
| 108 | |
| 109 | iss_03.str(L"7 &"); |
| 110 | iterator_type is_it03(iss_03); |
| 111 | wstring result03; |
| 112 | ios_base::iostate err03 = ios_base::goodbit; |
| 113 | end03 = mon_get_03.get(is_it03, end, false, iss_03, err03, result03); |
| 114 | VERIFY( err03 == ios_base::goodbit ); |
| 115 | VERIFY( *end03 == L'&' ); |
| 116 | } |
| 117 | |
| 118 | int main() |
| 119 | { |
| 120 | test01(); |
| 121 | return 0; |
| 122 | } |