Howard Hinnant | 92a0700 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Howard Hinnant | 14fa9f9 | 2011-09-29 20:33:10 +0000 | [diff] [blame] | 2 | //===--------------------- support/win32/locale_win32.h -------------------===// |
Howard Hinnant | 92a0700 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
Howard Hinnant | 14fa9f9 | 2011-09-29 20:33:10 +0000 | [diff] [blame] | 11 | #ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H |
| 12 | #define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 13 | |
Howard Hinnant | 3c466fc | 2011-09-29 13:33:15 +0000 | [diff] [blame] | 14 | // ctype mask table defined in msvcrt.dll |
| 15 | extern "C" unsigned short __declspec(dllimport) _ctype[]; |
| 16 | |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 17 | #include "support/win32/support.h" |
Howard Hinnant | ef5aa93 | 2013-09-17 01:34:47 +0000 | [diff] [blame] | 18 | #include <stdio.h> |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 19 | #include <memory> |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 20 | #include <xlocinfo.h> // _locale_t |
| 21 | #define locale_t _locale_t |
| 22 | #define LC_COLLATE_MASK _M_COLLATE |
| 23 | #define LC_CTYPE_MASK _M_CTYPE |
| 24 | #define LC_MONETARY_MASK _M_MONETARY |
| 25 | #define LC_NUMERIC_MASK _M_NUMERIC |
| 26 | #define LC_TIME_MASK _M_TIME |
| 27 | #define LC_MESSAGES_MASK _M_MESSAGES |
| 28 | #define LC_ALL_MASK ( LC_COLLATE_MASK \ |
| 29 | | LC_CTYPE_MASK \ |
| 30 | | LC_MESSAGES_MASK \ |
| 31 | | LC_MONETARY_MASK \ |
| 32 | | LC_NUMERIC_MASK \ |
| 33 | | LC_TIME_MASK ) |
| 34 | #define freelocale _free_locale |
| 35 | // FIXME: base currently unused. Needs manual work to construct the new locale |
| 36 | locale_t newlocale( int mask, const char * locale, locale_t base ); |
| 37 | locale_t uselocale( locale_t newloc ); |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 38 | lconv *localeconv_l( locale_t loc ); |
Howard Hinnant | ef5aa93 | 2013-09-17 01:34:47 +0000 | [diff] [blame] | 39 | size_t mbrlen_l( const char *__restrict s, size_t n, |
| 40 | mbstate_t *__restrict ps, locale_t loc); |
| 41 | size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src, |
| 42 | size_t len, mbstate_t *__restrict ps, locale_t loc ); |
| 43 | size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps, |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 44 | locale_t loc); |
Howard Hinnant | ef5aa93 | 2013-09-17 01:34:47 +0000 | [diff] [blame] | 45 | size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s, |
| 46 | size_t n, mbstate_t *__restrict ps, locale_t loc); |
| 47 | size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src, |
| 48 | size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc); |
| 49 | size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src, |
| 50 | size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc); |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 51 | wint_t btowc_l( int c, locale_t loc ); |
| 52 | int wctob_l( wint_t c, locale_t loc ); |
| 53 | typedef _VSTD::remove_pointer<locale_t>::type __locale_struct; |
| 54 | typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 55 | inline _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 56 | decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l ) |
| 57 | { |
| 58 | __locale_raii __current( uselocale(__l), uselocale ); |
| 59 | return MB_CUR_MAX; |
| 60 | } |
| 61 | |
| 62 | // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 63 | #define mbtowc_l _mbtowc_l |
Howard Hinnant | 92a0700 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 64 | #define strtoll_l _strtoi64_l |
| 65 | #define strtoull_l _strtoui64_l |
| 66 | // FIXME: current msvcrt does not know about long double |
| 67 | #define strtold_l _strtod_l |
Howard Hinnant | a5733b3 | 2013-04-12 20:22:57 +0000 | [diff] [blame] | 68 | |
| 69 | inline _LIBCPP_INLINE_VISIBILITY |
| 70 | int |
| 71 | islower_l(int c, _locale_t loc) |
| 72 | { |
| 73 | return _islower_l((int)c, loc); |
| 74 | } |
| 75 | |
| 76 | inline _LIBCPP_INLINE_VISIBILITY |
| 77 | int |
| 78 | isupper_l(int c, _locale_t loc) |
| 79 | { |
| 80 | return _isupper_l((int)c, loc); |
| 81 | } |
| 82 | |
Howard Hinnant | 92a0700 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 83 | #define isdigit_l _isdigit_l |
| 84 | #define isxdigit_l _isxdigit_l |
Howard Hinnant | 6cd05ee | 2011-09-23 16:11:27 +0000 | [diff] [blame] | 85 | #define strcoll_l _strcoll_l |
| 86 | #define strxfrm_l _strxfrm_l |
| 87 | #define wcscoll_l _wcscoll_l |
| 88 | #define wcsxfrm_l _wcsxfrm_l |
| 89 | #define toupper_l _toupper_l |
| 90 | #define tolower_l _tolower_l |
| 91 | #define iswspace_l _iswspace_l |
| 92 | #define iswprint_l _iswprint_l |
| 93 | #define iswcntrl_l _iswcntrl_l |
| 94 | #define iswupper_l _iswupper_l |
| 95 | #define iswlower_l _iswlower_l |
| 96 | #define iswalpha_l _iswalpha_l |
| 97 | #define iswdigit_l _iswdigit_l |
| 98 | #define iswpunct_l _iswpunct_l |
| 99 | #define iswxdigit_l _iswxdigit_l |
| 100 | #define towupper_l _towupper_l |
| 101 | #define towlower_l _towlower_l |
| 102 | #define strftime_l _strftime_l |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 103 | #define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) |
| 104 | #define vsscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ ) |
| 105 | #define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ ) |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 106 | #define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ ) |
| 107 | #define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ ) |
Yaron Keren | 15c04be | 2013-11-18 21:12:14 +0000 | [diff] [blame] | 108 | int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...); |
Howard Hinnant | efbe406 | 2011-09-28 21:39:20 +0000 | [diff] [blame] | 109 | int asprintf_l( char **ret, locale_t loc, const char *format, ... ); |
| 110 | int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap ); |
| 111 | |
| 112 | |
| 113 | // not-so-pressing FIXME: use locale to determine blank characters |
Howard Hinnant | 6cd05ee | 2011-09-23 16:11:27 +0000 | [diff] [blame] | 114 | inline int isblank_l( int c, locale_t /*loc*/ ) |
| 115 | { |
| 116 | return ( c == ' ' || c == '\t' ); |
| 117 | } |
| 118 | inline int iswblank_l( wint_t c, locale_t /*loc*/ ) |
| 119 | { |
| 120 | return ( c == L' ' || c == L'\t' ); |
| 121 | } |
Howard Hinnant | 6cd05ee | 2011-09-23 16:11:27 +0000 | [diff] [blame] | 122 | |
Howard Hinnant | ef5aa93 | 2013-09-17 01:34:47 +0000 | [diff] [blame] | 123 | #if defined(_LIBCPP_MSVCRT) |
Howard Hinnant | 9f8884e | 2011-10-27 16:24:42 +0000 | [diff] [blame] | 124 | inline int isblank( int c, locale_t /*loc*/ ) |
| 125 | { return ( c == ' ' || c == '\t' ); } |
| 126 | inline int iswblank( wint_t c, locale_t /*loc*/ ) |
| 127 | { return ( c == L' ' || c == L'\t' ); } |
Howard Hinnant | ef5aa93 | 2013-09-17 01:34:47 +0000 | [diff] [blame] | 128 | #endif // _LIBCPP_MSVCRT |
Howard Hinnant | 14fa9f9 | 2011-09-29 20:33:10 +0000 | [diff] [blame] | 129 | #endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H |