brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 3cec739 Raw
104 lines · c
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#ifndef LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H10#define LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H11 12#include <string>13#include "platform_support.h"14#include "test_macros.h"15#include "make_string.h"16 17#ifndef TEST_HAS_NO_WIDE_CHARACTERS18 19#include <cwctype>20 21#endif // TEST_HAS_NO_WIDE_CHARACTERS22 23namespace LocaleHelpers {24 25#ifndef TEST_HAS_NO_WIDE_CHARACTERS26 27std::wstring convert_thousands_sep(std::wstring const& in, wchar_t sep) {28  std::wstring out;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' ') {35      out.push_back(in[i]);36      continue;37    }38    assert(in[i] == L' ');39    out.push_back(sep);40  }41  return out;42}43 44std::wstring negate_en_US(std::wstring s) {45#if defined(_WIN32)46  return L"(" + s + L")";47#else48  return L"-" + s;49#endif50}51 52wchar_t thousands_sep_or_default(std::wstring s) { return !s.empty() ? s[0] : L','; }53 54wchar_t mon_thousands_sep_or_default(std::wstring s) { return thousands_sep_or_default(s); }55 56wchar_t decimal_point_or_default(std::wstring s) { return !s.empty() ? s[0] : L'.'; }57 58#endif // TEST_HAS_NO_WIDE_CHARACTERS59 60std::string negate_en_US(std::string s) {61#if defined(_WIN32)62  return "(" + s + ")";63#else64  return "-" + s;65#endif66}67 68MultiStringType currency_symbol_ru_RU() {69#if defined(_CS_GNU_LIBC_VERSION)70  if (glibc_version_less_than("2.24"))71    return MKSTR("\u0440\u0443\u0431");72  else73    return MKSTR("\u20BD"); // U+20BD RUBLE SIGN74#elif defined(_WIN32) || defined(__FreeBSD__) || defined(_AIX)75  return MKSTR("\u20BD"); // U+20BD RUBLE SIGN76#elif defined(__APPLE__)77  if (__builtin_available(macOS 15.4, *)) {78    return MKSTR("\u20BD"); // U+20BD RUBLE SIGN79  } else {80    return MKSTR("\u0440\u0443\u0431.");81  }82#else83  return MKSTR("\u0440\u0443\u0431.");84#endif85}86 87MultiStringType currency_symbol_zh_CN() {88#if defined(_WIN32)89  return MKSTR("\u00A5"); // U+00A5 YEN SIGN90#elif defined(__APPLE__)91  if (__builtin_available(macOS 15.4, *)) {92    return MKSTR("\u00A5"); // U+00A5 YEN SIGN93  } else {94    return MKSTR("\uFFE5"); // U+FFE5 FULLWIDTH YEN SIGN95  }96#else97  return MKSTR("\uFFE5"); // U+FFE5 FULLWIDTH YEN SIGN98#endif99}100 101} // namespace LocaleHelpers102 103#endif // LIBCXX_TEST_SUPPORT_LOCALE_HELPERS_H104