1 //===----------------------------------------------------------------------===//
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-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H
10 #define LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H
13 #include "platform_support.h"
14 #include "test_macros.h"
15 #include "make_string.h"
17 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
21 #endif // TEST_HAS_NO_WIDE_CHARACTERS
23 namespace LocaleHelpers
{
25 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
27 std::wstring
convert_thousands_sep(std::wstring
const& in
, wchar_t sep
) {
29 bool seen_num_start
= false;
30 bool seen_decimal
= false;
31 for (unsigned i
= 0; i
< in
.size(); ++i
) {
32 seen_decimal
|= in
[i
] == L
',';
33 seen_num_start
|= in
[i
] == L
'-' || std::iswdigit(in
[i
]);
34 if (seen_decimal
|| !seen_num_start
|| in
[i
] != L
' ') {
38 assert(in
[i
] == L
' ');
44 // GLIBC 2.27 and newer use U+202F NARROW NO-BREAK SPACE as a thousands separator.
45 // This function converts the spaces in string inputs to U+202F if need
46 // be. FreeBSD's locale data also uses U+202F, since 2018.
47 // Windows uses U+00A0 NO-BREAK SPACE.
48 std::wstring
convert_thousands_sep_fr_FR(std::wstring
const& in
) {
49 #if defined(_CS_GNU_LIBC_VERSION)
50 if (glibc_version_less_than("2.27"))
53 return convert_thousands_sep(in
, L
'\u202F');
54 #elif defined(__FreeBSD__)
55 return convert_thousands_sep(in
, L
'\u202F');
57 return convert_thousands_sep(in
, L
'\u00A0');
63 // GLIBC 2.27 uses U+202F NARROW NO-BREAK SPACE as a thousands separator.
64 // FreeBSD, AIX and Windows use U+00A0 NO-BREAK SPACE.
65 std::wstring
convert_thousands_sep_ru_RU(std::wstring
const& in
) {
66 #if defined(TEST_HAS_GLIBC)
67 return convert_thousands_sep(in
, L
'\u202F');
68 # elif defined(__FreeBSD__) || defined(_WIN32) || defined(_AIX)
69 return convert_thousands_sep(in
, L
'\u00A0');
75 std::wstring
negate_en_US(std::wstring s
) {
77 return L
"(" + s
+ L
")";
83 #endif // TEST_HAS_NO_WIDE_CHARACTERS
85 std::string
negate_en_US(std::string s
) {
93 MultiStringType
currency_symbol_ru_RU() {
94 #if defined(_CS_GNU_LIBC_VERSION)
95 if (glibc_version_less_than("2.24"))
96 return MKSTR("\u0440\u0443\u0431");
98 return MKSTR("\u20BD"); // U+20BD RUBLE SIGN
99 #elif defined(_WIN32) || defined(__FreeBSD__) || defined(_AIX)
100 return MKSTR("\u20BD"); // U+20BD RUBLE SIGN
102 return MKSTR("\u0440\u0443\u0431.");
106 MultiStringType
currency_symbol_zh_CN() {
108 return MKSTR("\u00A5"); // U+00A5 YEN SIGN
110 return MKSTR("\uFFE5"); // U+FFE5 FULLWIDTH YEN SIGN
114 } // namespace LocaleHelpers
116 #endif // LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H