• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <iomanip>
11 
12 // template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
13 
14 #include <iomanip>
15 #include <cassert>
16 
17 #include "platform_support.h" // locale name macros
18 
19 template <class CharT>
20 struct testbuf
21     : public std::basic_streambuf<CharT>
22 {
23     typedef std::basic_string<CharT> string_type;
24     typedef std::basic_streambuf<CharT> base;
25 private:
26     string_type str_;
27 public:
28 
testbuftestbuf29     testbuf() {}
testbuftestbuf30     testbuf(const string_type& str)
31         : str_(str)
32     {
33         base::setg(const_cast<CharT*>(str_.data()),
34                    const_cast<CharT*>(str_.data()),
35                    const_cast<CharT*>(str_.data()) + str_.size());
36     }
37 };
38 
main()39 int main()
40 {
41     {
42         testbuf<char> sb("  -$1,234,567.89");
43         std::istream is(&sb);
44         is.imbue(std::locale(LOCALE_en_US_UTF_8));
45         long double x = 0;
46         is >> std::get_money(x, false);
47         assert(x == -123456789);
48     }
49     {
50         testbuf<char> sb("  -USD 1,234,567.89");
51         std::istream is(&sb);
52         is.imbue(std::locale(LOCALE_en_US_UTF_8));
53         long double x = 0;
54         is >> std::get_money(x, true);
55         assert(x == -123456789);
56     }
57     {
58         testbuf<wchar_t> sb(L"  -$1,234,567.89");
59         std::wistream is(&sb);
60         is.imbue(std::locale(LOCALE_en_US_UTF_8));
61         long double x = 0;
62         is >> std::get_money(x, false);
63         assert(x == -123456789);
64     }
65     {
66         testbuf<wchar_t> sb(L"  -USD 1,234,567.89");
67         std::wistream is(&sb);
68         is.imbue(std::locale(LOCALE_en_US_UTF_8));
69         long double x = 0;
70         is >> std::get_money(x, true);
71         assert(x == -123456789);
72     }
73 }
74