1 // 2001-09-12 Benjamin Kosnik  <bkoz@redhat.com>
2 
3 // Copyright (C) 2001-2020 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_a : public std::moneypunct<char,false>
27 {
do_decimal_pointMy_money_io_a28   char_type do_decimal_point() const { return '.'; }
do_groupingMy_money_io_a29   std::string do_grouping() const { return "\004"; }
30 
do_curr_symbolMy_money_io_a31   std::string do_curr_symbol() const { return "$"; }
do_positive_signMy_money_io_a32   std::string do_positive_sign() const { return "()"; }
33 
do_frac_digitsMy_money_io_a34   int do_frac_digits() const { return 2; }
35 
do_neg_formatMy_money_io_a36   pattern do_neg_format() const
37   {
38     pattern pat = { { sign, value, space, symbol } };
39     return pat;
40   }
41 };
42 
43 struct My_money_io_b : public std::moneypunct<char,false>
44 {
do_decimal_pointMy_money_io_b45   char_type do_decimal_point() const { return '.'; }
do_groupingMy_money_io_b46   std::string do_grouping() const { return "\004"; }
47 
do_curr_symbolMy_money_io_b48   std::string do_curr_symbol() const { return "$"; }
do_positive_signMy_money_io_b49   std::string do_positive_sign() const { return "()"; }
50 
do_frac_digitsMy_money_io_b51   int do_frac_digits() const { return 2; }
52 
do_neg_formatMy_money_io_b53   pattern do_neg_format() const
54   {
55     pattern pat = { { sign, value, symbol, none } };
56     return pat;
57   }
58 };
59 
60 // This one exercises patterns of the type { X, Y, Z, symbol } and
61 // { X, Y, symbol, none } for a two character long sign. Therefore
62 // the optional symbol (showbase is false by default) must be consumed
63 // if present, since "rest of the sign" is left to read.
test08()64 void test08()
65 {
66   using namespace std;
67   typedef istreambuf_iterator<char> InIt;
68 
69   bool intl = false;
70   ios_base::iostate err;
71 
72   locale loc_a(locale::classic(), new My_money_io_a);
73 
74   string buffer_a("(1234.56 $)");
75   string buffer_a_ns("(1234.56 )");
76 
77   InIt iend_a, iend_a_ns;
78   string val_a, val_a_ns;
79 
80   const money_get<char,InIt>& mg_a  = use_facet<money_get<char, InIt> >(loc_a);
81 
82   istringstream fmt_a(buffer_a);
83   fmt_a.imbue(loc_a);
84   InIt ibeg_a(fmt_a);
85   mg_a.get(ibeg_a,iend_a,intl,fmt_a,err,val_a);
86   VERIFY( val_a == "123456" );
87 
88   istringstream fmt_a_ns(buffer_a_ns);
89   fmt_a_ns.imbue(loc_a);
90   InIt ibeg_a_ns(fmt_a_ns);
91   mg_a.get(ibeg_a_ns,iend_a_ns,intl,fmt_a_ns,err,val_a_ns);
92   VERIFY( val_a_ns == "123456" );
93 
94   locale loc_b(locale::classic(), new My_money_io_b);
95 
96   string buffer_b("(1234.56$)");
97   string buffer_b_ns("(1234.56)");
98 
99   InIt iend_b, iend_b_ns;
100   string val_b, val_b_ns;
101 
102   const money_get<char,InIt>& mg_b = use_facet<money_get<char, InIt> >(loc_b);
103 
104   istringstream fmt_b(buffer_b);
105   fmt_b.imbue(loc_b);
106   InIt ibeg_b(fmt_b);
107   mg_b.get(ibeg_b,iend_b,intl,fmt_b,err,val_b);
108   VERIFY( val_b == "123456" );
109 
110   istringstream fmt_b_ns(buffer_b_ns);
111   fmt_b_ns.imbue(loc_b);
112   InIt ibeg_b_ns(fmt_b_ns);
113   mg_b.get(ibeg_b_ns,iend_b_ns,intl,fmt_b_ns,err,val_b_ns);
114   VERIFY( val_b_ns == "123456" );
115 }
116 
main()117 int main()
118 {
119   test08();
120   return 0;
121 }
122