Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:33

0001 // -*- C++ -*-
0002 //===-----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_WIN32_H
0011 #define _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_WIN32_H
0012 
0013 #include <__cxx03/__config>
0014 #include <__cxx03/cstddef>
0015 #include <__cxx03/locale.h> // _locale_t
0016 #include <__cxx03/stdio.h>
0017 #include <__cxx03/string>
0018 
0019 #define _X_ALL LC_ALL
0020 #define _X_COLLATE LC_COLLATE
0021 #define _X_CTYPE LC_CTYPE
0022 #define _X_MONETARY LC_MONETARY
0023 #define _X_NUMERIC LC_NUMERIC
0024 #define _X_TIME LC_TIME
0025 #define _X_MAX LC_MAX
0026 #define _X_MESSAGES 6
0027 #define _NCAT (_X_MESSAGES + 1)
0028 
0029 #define _CATMASK(n) ((1 << (n)) >> 1)
0030 #define _M_COLLATE _CATMASK(_X_COLLATE)
0031 #define _M_CTYPE _CATMASK(_X_CTYPE)
0032 #define _M_MONETARY _CATMASK(_X_MONETARY)
0033 #define _M_NUMERIC _CATMASK(_X_NUMERIC)
0034 #define _M_TIME _CATMASK(_X_TIME)
0035 #define _M_MESSAGES _CATMASK(_X_MESSAGES)
0036 #define _M_ALL (_CATMASK(_NCAT) - 1)
0037 
0038 #define LC_COLLATE_MASK _M_COLLATE
0039 #define LC_CTYPE_MASK _M_CTYPE
0040 #define LC_MONETARY_MASK _M_MONETARY
0041 #define LC_NUMERIC_MASK _M_NUMERIC
0042 #define LC_TIME_MASK _M_TIME
0043 #define LC_MESSAGES_MASK _M_MESSAGES
0044 #define LC_ALL_MASK                                                                                                    \
0045   (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK | LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK)
0046 
0047 class __lconv_storage {
0048 public:
0049   __lconv_storage(const lconv* __lc_input) {
0050     __lc_ = *__lc_input;
0051 
0052     __decimal_point_     = __lc_input->decimal_point;
0053     __thousands_sep_     = __lc_input->thousands_sep;
0054     __grouping_          = __lc_input->grouping;
0055     __int_curr_symbol_   = __lc_input->int_curr_symbol;
0056     __currency_symbol_   = __lc_input->currency_symbol;
0057     __mon_decimal_point_ = __lc_input->mon_decimal_point;
0058     __mon_thousands_sep_ = __lc_input->mon_thousands_sep;
0059     __mon_grouping_      = __lc_input->mon_grouping;
0060     __positive_sign_     = __lc_input->positive_sign;
0061     __negative_sign_     = __lc_input->negative_sign;
0062 
0063     __lc_.decimal_point     = const_cast<char*>(__decimal_point_.c_str());
0064     __lc_.thousands_sep     = const_cast<char*>(__thousands_sep_.c_str());
0065     __lc_.grouping          = const_cast<char*>(__grouping_.c_str());
0066     __lc_.int_curr_symbol   = const_cast<char*>(__int_curr_symbol_.c_str());
0067     __lc_.currency_symbol   = const_cast<char*>(__currency_symbol_.c_str());
0068     __lc_.mon_decimal_point = const_cast<char*>(__mon_decimal_point_.c_str());
0069     __lc_.mon_thousands_sep = const_cast<char*>(__mon_thousands_sep_.c_str());
0070     __lc_.mon_grouping      = const_cast<char*>(__mon_grouping_.c_str());
0071     __lc_.positive_sign     = const_cast<char*>(__positive_sign_.c_str());
0072     __lc_.negative_sign     = const_cast<char*>(__negative_sign_.c_str());
0073   }
0074 
0075   lconv* __get() { return &__lc_; }
0076 
0077 private:
0078   lconv __lc_;
0079   std::string __decimal_point_;
0080   std::string __thousands_sep_;
0081   std::string __grouping_;
0082   std::string __int_curr_symbol_;
0083   std::string __currency_symbol_;
0084   std::string __mon_decimal_point_;
0085   std::string __mon_thousands_sep_;
0086   std::string __mon_grouping_;
0087   std::string __positive_sign_;
0088   std::string __negative_sign_;
0089 };
0090 
0091 class locale_t {
0092 public:
0093   locale_t() : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
0094   locale_t(std::nullptr_t) : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {}
0095   locale_t(_locale_t __xlocale, const char* __xlocale_str)
0096       : __locale_(__xlocale), __locale_str_(__xlocale_str), __lc_(nullptr) {}
0097   locale_t(const locale_t& __l) : __locale_(__l.__locale_), __locale_str_(__l.__locale_str_), __lc_(nullptr) {}
0098 
0099   ~locale_t() { delete __lc_; }
0100 
0101   locale_t& operator=(const locale_t& __l) {
0102     __locale_     = __l.__locale_;
0103     __locale_str_ = __l.__locale_str_;
0104     // __lc_ not copied
0105     return *this;
0106   }
0107 
0108   friend bool operator==(const locale_t& __left, const locale_t& __right) {
0109     return __left.__locale_ == __right.__locale_;
0110   }
0111 
0112   friend bool operator==(const locale_t& __left, int __right) { return __left.__locale_ == nullptr && __right == 0; }
0113 
0114   friend bool operator==(const locale_t& __left, long long __right) {
0115     return __left.__locale_ == nullptr && __right == 0;
0116   }
0117 
0118   friend bool operator==(const locale_t& __left, std::nullptr_t) { return __left.__locale_ == nullptr; }
0119 
0120   friend bool operator==(int __left, const locale_t& __right) { return __left == 0 && nullptr == __right.__locale_; }
0121 
0122   friend bool operator==(std::nullptr_t, const locale_t& __right) { return nullptr == __right.__locale_; }
0123 
0124   friend bool operator!=(const locale_t& __left, const locale_t& __right) { return !(__left == __right); }
0125 
0126   friend bool operator!=(const locale_t& __left, int __right) { return !(__left == __right); }
0127 
0128   friend bool operator!=(const locale_t& __left, long long __right) { return !(__left == __right); }
0129 
0130   friend bool operator!=(const locale_t& __left, std::nullptr_t __right) { return !(__left == __right); }
0131 
0132   friend bool operator!=(int __left, const locale_t& __right) { return !(__left == __right); }
0133 
0134   friend bool operator!=(std::nullptr_t __left, const locale_t& __right) { return !(__left == __right); }
0135 
0136   operator bool() const { return __locale_ != nullptr; }
0137 
0138   const char* __get_locale() const { return __locale_str_; }
0139 
0140   operator _locale_t() const { return __locale_; }
0141 
0142   lconv* __store_lconv(const lconv* __input_lc) {
0143     delete __lc_;
0144     __lc_ = new __lconv_storage(__input_lc);
0145     return __lc_->__get();
0146   }
0147 
0148 private:
0149   _locale_t __locale_;
0150   const char* __locale_str_;
0151   __lconv_storage* __lc_ = nullptr;
0152 };
0153 
0154 // Locale management functions
0155 #define freelocale _free_locale
0156 // FIXME: base currently unused. Needs manual work to construct the new locale
0157 locale_t newlocale(int __mask, const char* __locale, locale_t __base);
0158 // uselocale can't be implemented on Windows because Windows allows partial modification
0159 // of thread-local locale and so _get_current_locale() returns a copy while uselocale does
0160 // not create any copies.
0161 // We can still implement raii even without uselocale though.
0162 
0163 lconv* localeconv_l(locale_t& __loc);
0164 size_t mbrlen_l(const char* __restrict __s, size_t __n, mbstate_t* __restrict __ps, locale_t __loc);
0165 size_t mbsrtowcs_l(
0166     wchar_t* __restrict __dst, const char** __restrict __src, size_t __len, mbstate_t* __restrict __ps, locale_t __loc);
0167 size_t wcrtomb_l(char* __restrict __s, wchar_t __wc, mbstate_t* __restrict __ps, locale_t __loc);
0168 size_t mbrtowc_l(
0169     wchar_t* __restrict __pwc, const char* __restrict __s, size_t __n, mbstate_t* __restrict __ps, locale_t __loc);
0170 size_t mbsnrtowcs_l(wchar_t* __restrict __dst,
0171                     const char** __restrict __src,
0172                     size_t __nms,
0173                     size_t __len,
0174                     mbstate_t* __restrict __ps,
0175                     locale_t __loc);
0176 size_t wcsnrtombs_l(char* __restrict __dst,
0177                     const wchar_t** __restrict __src,
0178                     size_t __nwc,
0179                     size_t __len,
0180                     mbstate_t* __restrict __ps,
0181                     locale_t __loc);
0182 wint_t btowc_l(int __c, locale_t __loc);
0183 int wctob_l(wint_t __c, locale_t __loc);
0184 
0185 decltype(MB_CUR_MAX) MB_CUR_MAX_L(locale_t __l);
0186 
0187 // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
0188 #define mbtowc_l _mbtowc_l
0189 #define strtoll_l _strtoi64_l
0190 #define strtoull_l _strtoui64_l
0191 #define strtod_l _strtod_l
0192 #if defined(_LIBCPP_MSVCRT)
0193 #  define strtof_l _strtof_l
0194 #  define strtold_l _strtold_l
0195 #else
0196 _LIBCPP_EXPORTED_FROM_ABI float strtof_l(const char*, char**, locale_t);
0197 _LIBCPP_EXPORTED_FROM_ABI long double strtold_l(const char*, char**, locale_t);
0198 #endif
0199 inline _LIBCPP_HIDE_FROM_ABI int islower_l(int __c, _locale_t __loc) { return _islower_l((int)__c, __loc); }
0200 
0201 inline _LIBCPP_HIDE_FROM_ABI int isupper_l(int __c, _locale_t __loc) { return _isupper_l((int)__c, __loc); }
0202 
0203 #define isdigit_l _isdigit_l
0204 #define isxdigit_l _isxdigit_l
0205 #define strcoll_l _strcoll_l
0206 #define strxfrm_l _strxfrm_l
0207 #define wcscoll_l _wcscoll_l
0208 #define wcsxfrm_l _wcsxfrm_l
0209 #define toupper_l _toupper_l
0210 #define tolower_l _tolower_l
0211 #define iswspace_l _iswspace_l
0212 #define iswprint_l _iswprint_l
0213 #define iswcntrl_l _iswcntrl_l
0214 #define iswupper_l _iswupper_l
0215 #define iswlower_l _iswlower_l
0216 #define iswalpha_l _iswalpha_l
0217 #define iswdigit_l _iswdigit_l
0218 #define iswpunct_l _iswpunct_l
0219 #define iswxdigit_l _iswxdigit_l
0220 #define towupper_l _towupper_l
0221 #define towlower_l _towlower_l
0222 #if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800
0223 _LIBCPP_EXPORTED_FROM_ABI size_t strftime_l(char* ret, size_t n, const char* format, const struct tm* tm, locale_t loc);
0224 #else
0225 #  define strftime_l _strftime_l
0226 #endif
0227 #define sscanf_l(__s, __l, __f, ...) _sscanf_l(__s, __f, __l, __VA_ARGS__)
0228 _LIBCPP_EXPORTED_FROM_ABI int snprintf_l(char* __ret, size_t __n, locale_t __loc, const char* __format, ...);
0229 _LIBCPP_EXPORTED_FROM_ABI int asprintf_l(char** __ret, locale_t __loc, const char* __format, ...);
0230 _LIBCPP_EXPORTED_FROM_ABI int vasprintf_l(char** __ret, locale_t __loc, const char* __format, va_list __ap);
0231 
0232 // not-so-pressing FIXME: use locale to determine blank characters
0233 inline int iswblank_l(wint_t __c, locale_t /*loc*/) { return (__c == L' ' || __c == L'\t'); }
0234 
0235 #endif // _LIBCPP___CXX03___LOCALE_LOCALE_BASE_API_WIN32_H