| 1 |
// 981027 ncm work with libstdc++v3 |
| 2 |
|
| 3 |
// Copyright (C) 1997-2025 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 |
|
| 21 |
#include <sstream> |
| 22 |
#include <locale> |
| 23 |
#include <iomanip> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
|
| 26 |
struct MyNP : std::numpunct<char> |
| 27 |
{ |
| 28 |
std::string do_grouping() const; |
| 29 |
char do_thousands_sep() const; |
| 30 |
}; |
| 31 |
|
| 32 |
std::string |
| 33 |
MyNP::do_grouping() const |
| 34 |
{ |
| 35 |
std::string s("\3"); |
| 36 |
return s; |
| 37 |
} |
| 38 |
|
| 39 |
char |
| 40 |
MyNP::do_thousands_sep() const |
| 41 |
{ return ' '; } |
| 42 |
|
| 43 |
void test01() |
| 44 |
{ |
| 45 |
const char lit[] = "0123 456\n" |
| 46 |
": 01 234 567:\n" |
| 47 |
":0123 456 :\n" |
| 48 |
": 012 345:\n" |
| 49 |
": 01 234:\n" |
| 50 |
":0726 746 425:\n" |
| 51 |
":04 553 207 :\n" |
| 52 |
": 0361 100:\n" |
| 53 |
": 0173:\n" |
| 54 |
"0x12 345 678\n" |
| 55 |
"|0x000012 345 678|\n" |
| 56 |
"|0x12 345 6780000|\n" |
| 57 |
"|00000x12 345 678|\n" |
| 58 |
"|0x000012 345 678|\n"; |
| 59 |
|
| 60 |
std::ostringstream oss; |
| 61 |
oss.imbue(std::locale(std::locale(), new MyNP)); |
| 62 |
|
| 63 |
// Octals |
| 64 |
oss << std::oct << std::showbase; |
| 65 |
oss << 0123456l << std::endl; |
| 66 |
|
| 67 |
oss << ":" << std::setw(11); |
| 68 |
oss << 01234567l << ":" << std::endl; |
| 69 |
|
| 70 |
oss << ":" << std::setw(11) << std::left; |
| 71 |
oss << 0123456l << ":" << std::endl; |
| 72 |
|
| 73 |
oss << ":" << std::setw(11) << std::right; |
| 74 |
oss << 012345l << ":" << std::endl; |
| 75 |
|
| 76 |
oss << ":" << std::setw(11) << std::internal; |
| 77 |
oss << 01234l << ":" << std::endl; |
| 78 |
|
| 79 |
oss << ":" << std::setw(11); |
| 80 |
oss << 123456789l << ":" << std::endl; |
| 81 |
|
| 82 |
oss << ":" << std::setw(11) << std::left; |
| 83 |
oss << 1234567l << ":" << std::endl; |
| 84 |
|
| 85 |
oss << ":" << std::setw(11) << std::right; |
| 86 |
oss << 123456l << ":" << std::endl; |
| 87 |
|
| 88 |
oss << ":" << std::setw(11) << std::internal; |
| 89 |
oss << 123l << ":" << std::endl; |
| 90 |
|
| 91 |
// Hexadecimals |
| 92 |
oss << std::hex << std::setfill('0'); |
| 93 |
oss << 0x12345678l << std::endl; |
| 94 |
|
| 95 |
oss << "|" << std::setw(16); |
| 96 |
oss << 0x12345678l << "|" << std::endl; |
| 97 |
|
| 98 |
oss << "|" << std::setw(16) << std::left; |
| 99 |
oss << 0x12345678l << "|" << std::endl; |
| 100 |
|
| 101 |
oss << "|" << std::setw(16) << std::right; |
| 102 |
oss << 0x12345678l << "|" << std::endl; |
| 103 |
|
| 104 |
oss << "|" << std::setw(16) << std::internal; |
| 105 |
oss << 0x12345678l << "|" << std::endl; |
| 106 |
|
| 107 |
VERIFY( oss.good() ); |
| 108 |
VERIFY( oss.str() == lit ); |
| 109 |
} |
| 110 |
|
| 111 |
int |
| 112 |
main() |
| 113 |
{ |
| 114 |
test01(); |
| 115 |
return 0; |
| 116 |
} |