diff options
Diffstat (limited to 'include/support/win32/locale_win32.h')
-rw-r--r-- | include/support/win32/locale_win32.h | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/include/support/win32/locale_win32.h b/include/support/win32/locale_win32.h index b2b3ac4c799b..aebfff22ecf0 100644 --- a/include/support/win32/locale_win32.h +++ b/include/support/win32/locale_win32.h @@ -14,6 +14,7 @@ #include <__config> #include <stdio.h> #include <xlocinfo.h> // _locale_t +#include <__nullptr> #define LC_COLLATE_MASK _M_COLLATE #define LC_CTYPE_MASK _M_CTYPE @@ -28,13 +29,77 @@ | LC_NUMERIC_MASK \ | LC_TIME_MASK ) -#define locale_t _locale_t +class locale_t { +public: + locale_t() + : __locale(nullptr), __locale_str(nullptr) {} + locale_t(std::nullptr_t) + : __locale(nullptr), __locale_str(nullptr) {} + locale_t(_locale_t __locale, const char* __locale_str) + : __locale(__locale), __locale_str(__locale_str) {} + + friend bool operator==(const locale_t& __left, const locale_t& __right) { + return __left.__locale == __right.__locale; + } + + friend bool operator==(const locale_t& __left, int __right) { + return __left.__locale == nullptr && __right == 0; + } + + friend bool operator==(const locale_t& __left, std::nullptr_t) { + return __left.__locale == nullptr; + } + + friend bool operator==(int __left, const locale_t& __right) { + return __left == 0 && nullptr == __right.__locale; + } + + friend bool operator==(std::nullptr_t, const locale_t& __right) { + return nullptr == __right.__locale; + } + + friend bool operator!=(const locale_t& __left, const locale_t& __right) { + return !(__left == __right); + } + + friend bool operator!=(const locale_t& __left, int __right) { + return !(__left == __right); + } + + friend bool operator!=(const locale_t& __left, std::nullptr_t __right) { + return !(__left == __right); + } + + friend bool operator!=(int __left, const locale_t& __right) { + return !(__left == __right); + } + + friend bool operator!=(std::nullptr_t __left, const locale_t& __right) { + return !(__left == __right); + } + + operator bool() const { + return __locale != nullptr; + } + + const char* __get_locale() const { return __locale_str; } + + operator _locale_t() const { + return __locale; + } +private: + _locale_t __locale; + const char* __locale_str; +}; // Locale management functions #define freelocale _free_locale // FIXME: base currently unused. Needs manual work to construct the new locale locale_t newlocale( int mask, const char * locale, locale_t base ); -locale_t uselocale( locale_t newloc ); +// uselocale can't be implemented on Windows because Windows allows partial modification +// of thread-local locale and so _get_current_locale() returns a copy while uselocale does +// not create any copies. +// We can still implement raii even without uselocale though. lconv *localeconv_l( locale_t loc ); @@ -100,9 +165,12 @@ isupper_l(int c, _locale_t loc) #define iswxdigit_l _iswxdigit_l #define towupper_l _towupper_l #define towlower_l _towlower_l +#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 +#define strftime_l( __s, __l, __f, __tm, __loc ) strftime( __s, __l, __f, __tm ) +#else #define strftime_l _strftime_l +#endif #define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) -#define vsscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) #define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ ) #define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ ) #define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ ) |