Home | History | Annotate | Download | only in ext.manip
      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 // REQUIRES: locale.en_US.UTF-8
     15 
     16 #include <iomanip>
     17 #include <cassert>
     18 
     19 #include "platform_support.h" // locale name macros
     20 
     21 template <class CharT>
     22 struct testbuf
     23     : public std::basic_streambuf<CharT>
     24 {
     25     typedef std::basic_string<CharT> string_type;
     26     typedef std::basic_streambuf<CharT> base;
     27 private:
     28     string_type str_;
     29 public:
     30 
     31     testbuf() {}
     32     testbuf(const string_type& str)
     33         : str_(str)
     34     {
     35         base::setg(const_cast<CharT*>(str_.data()),
     36                    const_cast<CharT*>(str_.data()),
     37                    const_cast<CharT*>(str_.data()) + str_.size());
     38     }
     39 };
     40 
     41 int main()
     42 {
     43     {
     44         testbuf<char> sb("  -$1,234,567.89");
     45         std::istream is(&sb);
     46         is.imbue(std::locale(LOCALE_en_US_UTF_8));
     47         long double x = 0;
     48         is >> std::get_money(x, false);
     49         assert(x == -123456789);
     50     }
     51     {
     52         testbuf<char> sb("  -USD 1,234,567.89");
     53         std::istream is(&sb);
     54         is.imbue(std::locale(LOCALE_en_US_UTF_8));
     55         long double x = 0;
     56         is >> std::get_money(x, true);
     57         assert(x == -123456789);
     58     }
     59     {
     60         testbuf<wchar_t> sb(L"  -$1,234,567.89");
     61         std::wistream is(&sb);
     62         is.imbue(std::locale(LOCALE_en_US_UTF_8));
     63         long double x = 0;
     64         is >> std::get_money(x, false);
     65         assert(x == -123456789);
     66     }
     67     {
     68         testbuf<wchar_t> sb(L"  -USD 1,234,567.89");
     69         std::wistream is(&sb);
     70         is.imbue(std::locale(LOCALE_en_US_UTF_8));
     71         long double x = 0;
     72         is >> std::get_money(x, true);
     73         assert(x == -123456789);
     74     }
     75 }
     76