brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · d0ff2c8 Raw
116 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <iomanip>10 11// template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);12 13// Bionic has minimal locale support, investigate this later.14// XFAIL: LIBCXX-ANDROID-FIXME15 16// REQUIRES: locale.en_US.UTF-817 18#include <iomanip>19#include <ostream>20#include <cassert>21 22#include "test_macros.h"23#include "platform_support.h" // locale name macros24 25template <class CharT>26class testbuf27    : public std::basic_streambuf<CharT>28{29    typedef std::basic_streambuf<CharT> base;30    std::basic_string<CharT> str_;31public:32    testbuf()33    {34    }35 36    std::basic_string<CharT> str() const37        {return std::basic_string<CharT>(base::pbase(), base::pptr());}38 39protected:40 41    virtual typename base::int_type42        overflow(typename base::int_type ch = base::traits_type::eof())43        {44            if (ch != base::traits_type::eof())45            {46                int n = str_.size();47                str_.push_back(static_cast<CharT>(ch));48                str_.resize(str_.capacity());49                base::setp(const_cast<CharT*>(str_.data()),50                           const_cast<CharT*>(str_.data() + str_.size()));51                base::pbump(n+1);52            }53            return ch;54        }55};56 57int main(int, char**)58{59    {60        testbuf<char> sb;61        std::ostream os(&sb);62        os.imbue(std::locale(LOCALE_en_US_UTF_8));63        std::showbase(os);64        long double x = -123456789;65        os << std::put_money(x, false);66#if defined(_WIN32)67        assert(sb.str() == "($1,234,567.89)");68#else69        assert(sb.str() == "-$1,234,567.89");70#endif71    }72    {73        testbuf<char> sb;74        std::ostream os(&sb);75        os.imbue(std::locale(LOCALE_en_US_UTF_8));76        std::showbase(os);77        long double x = -123456789;78        os << std::put_money(x, true);79#if defined(_WIN32)80        assert(sb.str() == "(USD1,234,567.89)");81#else82        assert(sb.str() == "-USD 1,234,567.89");83#endif84    }85#ifndef TEST_HAS_NO_WIDE_CHARACTERS86    {87        testbuf<wchar_t> sb;88        std::wostream os(&sb);89        os.imbue(std::locale(LOCALE_en_US_UTF_8));90        std::showbase(os);91        long double x = -123456789;92        os << std::put_money(x, false);93#if defined(_WIN32)94        assert(sb.str() == L"($1,234,567.89)");95#else96        assert(sb.str() == L"-$1,234,567.89");97#endif98    }99    {100        testbuf<wchar_t> sb;101        std::wostream os(&sb);102        os.imbue(std::locale(LOCALE_en_US_UTF_8));103        std::showbase(os);104        long double x = -123456789;105        os << std::put_money(x, true);106#if defined(_WIN32)107        assert(sb.str() == L"(USD1,234,567.89)");108#else109        assert(sb.str() == L"-USD 1,234,567.89");110#endif111    }112#endif113 114  return 0;115}116