OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [22_locale/] [money_get/] [get/] [char/] [8.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 2001-09-12 Benjamin Kosnik  <bkoz@redhat.com>
2
 
3
// Copyright (C) 2001, 2002, 2003 Free Software Foundation
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 2, 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 COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// 22.2.6.1.1 money_get members
22
 
23
#include <locale>
24
#include <sstream>
25
#include <testsuite_hooks.h>
26
 
27
struct My_money_io_a : public std::moneypunct<char,false>
28
{
29
  char_type do_decimal_point() const { return '.'; }
30
  std::string do_grouping() const { return "\004"; }
31
 
32
  std::string do_curr_symbol() const { return "$"; }
33
  std::string do_positive_sign() const { return "()"; }
34
 
35
  int do_frac_digits() const { return 2; }
36
 
37
  pattern do_neg_format() const
38
  {
39
    pattern pat = { { sign, value, space, symbol } };
40
    return pat;
41
  }
42
};
43
 
44
struct My_money_io_b : public std::moneypunct<char,false>
45
{
46
  char_type do_decimal_point() const { return '.'; }
47
  std::string do_grouping() const { return "\004"; }
48
 
49
  std::string do_curr_symbol() const { return "$"; }
50
  std::string do_positive_sign() const { return "()"; }
51
 
52
  int do_frac_digits() const { return 2; }
53
 
54
  pattern do_neg_format() const
55
  {
56
    pattern pat = { { sign, value, symbol, none } };
57
    return pat;
58
  }
59
};
60
 
61
// This one exercises patterns of the type { X, Y, Z, symbol } and
62
// { X, Y, symbol, none } for a two character long sign. Therefore
63
// the optional symbol (showbase is false by default) must be consumed
64
// if present, since "rest of the sign" is left to read.
65
void test08()
66
{
67
  using namespace std;
68
  typedef istreambuf_iterator<char> InIt;
69
 
70
  bool intl = false;
71
  bool test __attribute__((unused)) = true;
72
  ios_base::iostate err;
73
 
74
  locale loc_a(locale::classic(), new My_money_io_a);
75
 
76
  string buffer_a("(1234.56 $)");
77
  string buffer_a_ns("(1234.56 )");
78
 
79
  InIt iend_a, iend_a_ns;
80
  string val_a, val_a_ns;
81
 
82
  const money_get<char,InIt>& mg_a  = use_facet<money_get<char, InIt> >(loc_a);
83
 
84
  istringstream fmt_a(buffer_a);
85
  fmt_a.imbue(loc_a);
86
  InIt ibeg_a(fmt_a);
87
  mg_a.get(ibeg_a,iend_a,intl,fmt_a,err,val_a);
88
  VERIFY( val_a == "123456" );
89
 
90
  istringstream fmt_a_ns(buffer_a_ns);
91
  fmt_a_ns.imbue(loc_a);
92
  InIt ibeg_a_ns(fmt_a_ns);
93
  mg_a.get(ibeg_a_ns,iend_a_ns,intl,fmt_a_ns,err,val_a_ns);
94
  VERIFY( val_a_ns == "123456" );
95
 
96
  locale loc_b(locale::classic(), new My_money_io_b);
97
 
98
  string buffer_b("(1234.56$)");
99
  string buffer_b_ns("(1234.56)");
100
 
101
  InIt iend_b, iend_b_ns;
102
  string val_b, val_b_ns;
103
 
104
  const money_get<char,InIt>& mg_b = use_facet<money_get<char, InIt> >(loc_b);
105
 
106
  istringstream fmt_b(buffer_b);
107
  fmt_b.imbue(loc_b);
108
  InIt ibeg_b(fmt_b);
109
  mg_b.get(ibeg_b,iend_b,intl,fmt_b,err,val_b);
110
  VERIFY( val_b == "123456" );
111
 
112
  istringstream fmt_b_ns(buffer_b_ns);
113
  fmt_b_ns.imbue(loc_b);
114
  InIt ibeg_b_ns(fmt_b_ns);
115
  mg_b.get(ibeg_b_ns,iend_b_ns,intl,fmt_b_ns,err,val_b_ns);
116
  VERIFY( val_b_ns == "123456" );
117
}
118
 
119
int main()
120
{
121
  test08();
122
  return 0;
123
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.