File indexing completed on 2026-05-03 08:13:54
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H
0010 #define _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H
0011
0012 #include <__config>
0013 #include <__cstddef/nullptr_t.h>
0014 #include <__utility/forward.h>
0015 #include <clocale> // std::lconv & friends
0016 #include <cstddef>
0017 #include <ctype.h> // ::_isupper_l & friends
0018 #include <locale.h> // ::_locale_t
0019 #include <stdio.h> // ::_sscanf_l
0020 #include <stdlib.h> // ::_strtod_l & friends
0021 #include <string.h> // ::_strcoll_l
0022 #include <string>
0023 #include <time.h> // ::_strftime_l
0024
0025 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0026 # pragma GCC system_header
0027 #endif
0028
0029 _LIBCPP_BEGIN_NAMESPACE_STD
0030 namespace __locale {
0031
0032 using __lconv_t = std::lconv;
0033
0034 class __lconv_storage {
0035 public:
0036 __lconv_storage(const __lconv_t* __lc_input) {
0037 __lc_ = *__lc_input;
0038
0039 __decimal_point_ = __lc_input->decimal_point;
0040 __thousands_sep_ = __lc_input->thousands_sep;
0041 __grouping_ = __lc_input->grouping;
0042 __int_curr_symbol_ = __lc_input->int_curr_symbol;
0043 __currency_symbol_ = __lc_input->currency_symbol;
0044 __mon_decimal_point_ = __lc_input->mon_decimal_point;
0045 __mon_thousands_sep_ = __lc_input->mon_thousands_sep;
0046 __mon_grouping_ = __lc_input->mon_grouping;
0047 __positive_sign_ = __lc_input->positive_sign;
0048 __negative_sign_ = __lc_input->negative_sign;
0049
0050 __lc_.decimal_point = const_cast<char*>(__decimal_point_.c_str());
0051 __lc_.thousands_sep = const_cast<char*>(__thousands_sep_.c_str());
0052 __lc_.grouping = const_cast<char*>(__grouping_.c_str());
0053 __lc_.int_curr_symbol = const_cast<char*>(__int_curr_symbol_.c_str());
0054 __lc_.currency_symbol = const_cast<char*>(__currency_symbol_.c_str());
0055 __lc_.mon_decimal_point = const_cast<char*>(__mon_decimal_point_.c_str());
0056 __lc_.mon_thousands_sep = const_cast<char*>(__mon_thousands_sep_.c_str());
0057 __lc_.mon_grouping = const_cast<char*>(__mon_grouping_.c_str());
0058 __lc_.positive_sign = const_cast<char*>(__positive_sign_.c_str());
0059 __lc_.negative_sign = const_cast<char*>(__negative_sign_.c_str());
0060 }
0061
0062 __lconv_t* __get() { return &__lc_; }
0063
0064 private:
0065 __lconv_t __lc_;
0066 std::string __decimal_point_;
0067 std::string __thousands_sep_;
0068 std::string __grouping_;
0069 std::string __int_curr_symbol_;
0070 std::string __currency_symbol_;
0071 std::string __mon_decimal_point_;
0072 std::string __mon_thousands_sep_;
0073 std::string __mon_grouping_;
0074 std::string __positive_sign_;
0075 std::string __negative_sign_;
0076 };
0077
0078
0079
0080
0081 #define _CATMASK(n) ((1 << (n)) >> 1)
0082 #define _LIBCPP_COLLATE_MASK _CATMASK(LC_COLLATE)
0083 #define _LIBCPP_CTYPE_MASK _CATMASK(LC_CTYPE)
0084 #define _LIBCPP_MONETARY_MASK _CATMASK(LC_MONETARY)
0085 #define _LIBCPP_NUMERIC_MASK _CATMASK(LC_NUMERIC)
0086 #define _LIBCPP_TIME_MASK _CATMASK(LC_TIME)
0087 #define _LIBCPP_MESSAGES_MASK _CATMASK(6)
0088 #define _LIBCPP_ALL_MASK \
0089 (_LIBCPP_COLLATE_MASK | _LIBCPP_CTYPE_MASK | _LIBCPP_MESSAGES_MASK | _LIBCPP_MONETARY_MASK | _LIBCPP_NUMERIC_MASK | \
0090 _LIBCPP_TIME_MASK)
0091 #define _LIBCPP_LC_ALL LC_ALL
0092
0093 class __locale_t {
0094 public:
0095 __locale_t() : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
0096 __locale_t(std::nullptr_t) : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
0097 __locale_t(::_locale_t __loc, const char* __loc_str) : __locale_(__loc), __locale_str_(__loc_str), __lc_(nullptr) {}
0098 __locale_t(const __locale_t& __loc)
0099 : __locale_(__loc.__locale_), __locale_str_(__loc.__locale_str_), __lc_(nullptr) {}
0100
0101 ~__locale_t() { delete __lc_; }
0102
0103 __locale_t& operator=(const __locale_t& __loc) {
0104 __locale_ = __loc.__locale_;
0105 __locale_str_ = __loc.__locale_str_;
0106
0107 return *this;
0108 }
0109
0110 friend bool operator==(const __locale_t& __left, const __locale_t& __right) {
0111 return __left.__locale_ == __right.__locale_;
0112 }
0113
0114 friend bool operator==(const __locale_t& __left, int __right) { return __left.__locale_ == nullptr && __right == 0; }
0115
0116 friend bool operator==(const __locale_t& __left, long long __right) {
0117 return __left.__locale_ == nullptr && __right == 0;
0118 }
0119
0120 friend bool operator==(const __locale_t& __left, std::nullptr_t) { return __left.__locale_ == nullptr; }
0121
0122 friend bool operator==(int __left, const __locale_t& __right) { return __left == 0 && nullptr == __right.__locale_; }
0123
0124 friend bool operator==(std::nullptr_t, const __locale_t& __right) { return nullptr == __right.__locale_; }
0125
0126 friend bool operator!=(const __locale_t& __left, const __locale_t& __right) { return !(__left == __right); }
0127
0128 friend bool operator!=(const __locale_t& __left, int __right) { return !(__left == __right); }
0129
0130 friend bool operator!=(const __locale_t& __left, long long __right) { return !(__left == __right); }
0131
0132 friend bool operator!=(const __locale_t& __left, std::nullptr_t __right) { return !(__left == __right); }
0133
0134 friend bool operator!=(int __left, const __locale_t& __right) { return !(__left == __right); }
0135
0136 friend bool operator!=(std::nullptr_t __left, const __locale_t& __right) { return !(__left == __right); }
0137
0138 operator bool() const { return __locale_ != nullptr; }
0139
0140 const char* __get_locale() const { return __locale_str_; }
0141
0142 operator ::_locale_t() const { return __locale_; }
0143
0144 __lconv_t* __store_lconv(const __lconv_t* __input_lc) {
0145 delete __lc_;
0146 __lc_ = new __lconv_storage(__input_lc);
0147 return __lc_->__get();
0148 }
0149
0150 private:
0151 ::_locale_t __locale_;
0152 const char* __locale_str_;
0153 __lconv_storage* __lc_ = nullptr;
0154 };
0155
0156 #if defined(_LIBCPP_BUILDING_LIBRARY)
0157 _LIBCPP_EXPORTED_FROM_ABI __locale_t __newlocale(int __mask, const char* __locale, __locale_t __base);
0158 inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::_free_locale(__loc); }
0159 inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, const char* __locale) {
0160 char* __new_locale = ::setlocale(__category, __locale);
0161 if (__new_locale == nullptr)
0162 std::__throw_bad_alloc();
0163 return __new_locale;
0164 }
0165 _LIBCPP_EXPORTED_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc);
0166 #endif
0167
0168
0169
0170
0171
0172
0173 #if defined(_LIBCPP_MSVCRT)
0174 inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
0175 return ::_strtof_l(__nptr, __endptr, __loc);
0176 }
0177 inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
0178 return ::_strtold_l(__nptr, __endptr, __loc);
0179 }
0180 #else
0181 _LIBCPP_EXPORTED_FROM_ABI float __strtof(const char*, char**, __locale_t);
0182 _LIBCPP_EXPORTED_FROM_ABI long double __strtold(const char*, char**, __locale_t);
0183 #endif
0184
0185 inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
0186 return ::_strtod_l(__nptr, __endptr, __loc);
0187 }
0188
0189 inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
0190 return ::_strtoi64_l(__nptr, __endptr, __base, __loc);
0191 }
0192 inline _LIBCPP_HIDE_FROM_ABI unsigned long long
0193 __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
0194 return ::_strtoui64_l(__nptr, __endptr, __base, __loc);
0195 }
0196
0197
0198
0199
0200 #if defined(_LIBCPP_BUILDING_LIBRARY)
0201 inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return _islower_l(__c, __loc); }
0202
0203 inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return _isupper_l(__c, __loc); }
0204 #endif
0205
0206 inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return _isdigit_l(__c, __loc); }
0207
0208 inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return _isxdigit_l(__c, __loc); }
0209
0210 #if defined(_LIBCPP_BUILDING_LIBRARY)
0211 inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return ::_toupper_l(__c, __loc); }
0212
0213 inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t __loc) { return ::_tolower_l(__c, __loc); }
0214
0215 inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) {
0216 return ::_strcoll_l(__s1, __s2, __loc);
0217 }
0218
0219 inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) {
0220 return ::_strxfrm_l(__dest, __src, __n, __loc);
0221 }
0222
0223 # if _LIBCPP_HAS_WIDE_CHARACTERS
0224 inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) {
0225 return ::_iswctype_l(__c, __type, __loc);
0226 }
0227 inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return ::_iswspace_l(__c, __loc); }
0228 inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return ::_iswprint_l(__c, __loc); }
0229 inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t __loc) { return ::_iswcntrl_l(__c, __loc); }
0230 inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t __loc) { return ::_iswupper_l(__c, __loc); }
0231 inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t __loc) { return ::_iswlower_l(__c, __loc); }
0232 inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t __loc) { return ::_iswalpha_l(__c, __loc); }
0233
0234 inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t ) { return (__c == L' ' || __c == L'\t'); }
0235 inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t __loc) { return ::_iswdigit_l(__c, __loc); }
0236 inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t __loc) { return ::_iswpunct_l(__c, __loc); }
0237 inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t __loc) { return ::_iswxdigit_l(__c, __loc); }
0238 inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t __loc) { return ::_towupper_l(__c, __loc); }
0239 inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t __loc) { return ::_towlower_l(__c, __loc); }
0240
0241 inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) {
0242 return ::_wcscoll_l(__ws1, __ws2, __loc);
0243 }
0244
0245 inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) {
0246 return ::_wcsxfrm_l(__dest, __src, __n, __loc);
0247 }
0248 # endif
0249
0250 # if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
0251 _LIBCPP_EXPORTED_FROM_ABI size_t __strftime(char*, size_t, const char*, const struct tm*, __locale_t);
0252 # else
0253 inline _LIBCPP_HIDE_FROM_ABI size_t
0254 __strftime(char* __ret, size_t __n, const char* __format, const struct tm* __tm, __locale_t __loc) {
0255 return ::_strftime_l(__ret, __n, __format, __tm, __loc);
0256 }
0257 # endif
0258
0259
0260
0261
0262 _LIBCPP_EXPORTED_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t);
0263 _LIBCPP_EXPORTED_FROM_ABI wint_t __btowc(int, __locale_t);
0264 _LIBCPP_EXPORTED_FROM_ABI int __wctob(wint_t, __locale_t);
0265 _LIBCPP_EXPORTED_FROM_ABI size_t
0266 __wcsnrtombs(char* __restrict, const wchar_t** __restrict, size_t, size_t, mbstate_t* __restrict, __locale_t);
0267 _LIBCPP_EXPORTED_FROM_ABI size_t __wcrtomb(char* __restrict, wchar_t, mbstate_t* __restrict, __locale_t);
0268 _LIBCPP_EXPORTED_FROM_ABI size_t
0269 __mbsnrtowcs(wchar_t* __restrict, const char** __restrict, size_t, size_t, mbstate_t* __restrict, __locale_t);
0270 _LIBCPP_EXPORTED_FROM_ABI size_t
0271 __mbrtowc(wchar_t* __restrict, const char* __restrict, size_t, mbstate_t* __restrict, __locale_t);
0272
0273 inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) {
0274 return ::_mbtowc_l(__pwc, __pmb, __max, __loc);
0275 }
0276
0277 _LIBCPP_EXPORTED_FROM_ABI size_t __mbrlen(const char* __restrict, size_t, mbstate_t* __restrict, __locale_t);
0278
0279 _LIBCPP_EXPORTED_FROM_ABI size_t
0280 __mbsrtowcs(wchar_t* __restrict, const char** __restrict, size_t, mbstate_t* __restrict, __locale_t);
0281 #endif
0282
0283 _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf(
0284 char* __ret, size_t __n, __locale_t __loc, const char* __format, ...);
0285
0286 _LIBCPP_EXPORTED_FROM_ABI
0287 _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(char** __ret, __locale_t __loc, const char* __format, ...);
0288
0289 _LIBCPP_DIAGNOSTIC_PUSH
0290 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat")
0291 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
0292 #ifdef _LIBCPP_COMPILER_CLANG_BASED
0293 # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__)
0294 #else
0295 # define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...)
0296 #endif
0297
0298 template <class... _Args>
0299 _LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf(
0300 const char* __dest, __locale_t __loc, const char* __format, _Args&&... __args) {
0301 return ::_sscanf_l(__dest, __format, __loc, std::forward<_Args>(__args)...);
0302 }
0303 _LIBCPP_DIAGNOSTIC_POP
0304 #undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT
0305
0306 #if defined(_LIBCPP_BUILDING_LIBRARY)
0307 struct __locale_guard {
0308 _LIBCPP_HIDE_FROM_ABI __locale_guard(__locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
0309
0310
0311
0312 const char* __lc = __locale::__setlocale(LC_ALL, nullptr);
0313
0314
0315
0316
0317 if (std::strcmp(__l.__get_locale(), __lc) != 0) {
0318 __locale_all = _strdup(__lc);
0319 if (__locale_all == nullptr)
0320 __throw_bad_alloc();
0321 __locale::__setlocale(LC_ALL, __l.__get_locale());
0322 }
0323 }
0324 _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
0325
0326
0327
0328
0329 if (__locale_all != nullptr) {
0330 __locale::__setlocale(LC_ALL, __locale_all);
0331 free(__locale_all);
0332 }
0333 _configthreadlocale(__status);
0334 }
0335 int __status;
0336 char* __locale_all = nullptr;
0337 };
0338 #endif
0339
0340 }
0341 _LIBCPP_END_NAMESPACE_STD
0342
0343 #endif