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 //===----------------------------------------------------------------------===//
8 #ifndef LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H
9 #define LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H
12 #include "platform_support.h"
13 #include "test_macros.h"
14 #include "make_string.h"
16 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
20 #endif // TEST_HAS_NO_WIDE_CHARACTERS
22 namespace LocaleHelpers
{
24 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
26 std::wstring
convert_thousands_sep(std::wstring
const& in
, wchar_t sep
) {
28 bool seen_num_start
= false;
29 bool seen_decimal
= false;
30 for (unsigned i
= 0; i
< in
.size(); ++i
) {
31 seen_decimal
|= in
[i
] == L
',';
32 seen_num_start
|= in
[i
] == L
'-' || std::iswdigit(in
[i
]);
33 if (seen_decimal
|| !seen_num_start
|| in
[i
] != L
' ') {
37 assert(in
[i
] == L
' ');
43 // GLIBC 2.27 and newer use U+202F NARROW NO-BREAK SPACE as a thousands separator.
44 // This function converts the spaces in string inputs to U+202F if need
45 // be. FreeBSD's locale data also uses U+202F, since 2018.
46 // Windows uses U+00A0 NO-BREAK SPACE.
47 std::wstring
convert_thousands_sep_fr_FR(std::wstring
const& in
) {
48 #if defined(_CS_GNU_LIBC_VERSION)
49 if (glibc_version_less_than("2.27"))
52 return convert_thousands_sep(in
, L
'\u202F');
53 #elif defined(__FreeBSD__)
54 return convert_thousands_sep(in
, L
'\u202F');
56 return convert_thousands_sep(in
, L
'\u00A0');
62 // GLIBC 2.27 uses U+202F NARROW NO-BREAK SPACE as a thousands separator.
63 // FreeBSD and Windows use U+00A0 NO-BREAK SPACE.
64 std::wstring
convert_thousands_sep_ru_RU(std::wstring
const& in
) {
65 #if defined(TEST_HAS_GLIBC)
66 return convert_thousands_sep(in
, L
'\u202F');
67 #elif defined(__FreeBSD__) || defined(_WIN32)
68 return convert_thousands_sep(in
, L
'\u00A0');
74 std::wstring
negate_en_US(std::wstring s
) {
76 return L
"(" + s
+ L
")";
82 #endif // TEST_HAS_NO_WIDE_CHARACTERS
84 std::string
negate_en_US(std::string s
) {
92 MultiStringType
currency_symbol_ru_RU() {
93 #if defined(_CS_GNU_LIBC_VERSION)
94 if (glibc_version_less_than("2.24"))
95 return MKSTR("\u0440\u0443\u0431");
97 return MKSTR("\u20BD"); // U+20BD RUBLE SIGN
98 #elif defined(_WIN32) || defined(__FreeBSD__)
99 return MKSTR("\u20BD"); // U+20BD RUBLE SIGN
101 return MKSTR("\u0440\u0443\u0431.");
105 MultiStringType
currency_symbol_zh_CN() {
107 return MKSTR("\u00A5"); // U+00A5 YEN SIGN
109 return MKSTR("\uFFE5"); // U+FFE5 FULLWIDTH YEN SIGN
113 } // namespace LocaleHelpers
115 #endif // LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H