locale_win32.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // -*- C++ -*-
  2. //===--------------------- support/win32/locale_win32.h -------------------===//
  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. #ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
  11. #define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
  12. // ctype mask table defined in msvcrt.dll
  13. extern "C" unsigned short __declspec(dllimport) _ctype[];
  14. #include "support/win32/support.h"
  15. #include "support/win32/locale_mgmt_win32.h"
  16. #include <stdio.h>
  17. #include <memory>
  18. lconv *localeconv_l( locale_t loc );
  19. size_t mbrlen_l( const char *__restrict s, size_t n,
  20. mbstate_t *__restrict ps, locale_t loc);
  21. size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
  22. size_t len, mbstate_t *__restrict ps, locale_t loc );
  23. size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
  24. locale_t loc);
  25. size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
  26. size_t n, mbstate_t *__restrict ps, locale_t loc);
  27. size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
  28. size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc);
  29. size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
  30. size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc);
  31. wint_t btowc_l( int c, locale_t loc );
  32. int wctob_l( wint_t c, locale_t loc );
  33. typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
  34. typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
  35. inline _LIBCPP_ALWAYS_INLINE
  36. decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
  37. {
  38. __locale_raii __current( uselocale(__l), uselocale );
  39. return MB_CUR_MAX;
  40. }
  41. // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
  42. #define mbtowc_l _mbtowc_l
  43. #define strtoll_l _strtoi64_l
  44. #define strtoull_l _strtoui64_l
  45. // FIXME: current msvcrt does not know about long double
  46. #define strtold_l _strtod_l
  47. inline _LIBCPP_INLINE_VISIBILITY
  48. int
  49. islower_l(int c, _locale_t loc)
  50. {
  51. return _islower_l((int)c, loc);
  52. }
  53. inline _LIBCPP_INLINE_VISIBILITY
  54. int
  55. isupper_l(int c, _locale_t loc)
  56. {
  57. return _isupper_l((int)c, loc);
  58. }
  59. #define isdigit_l _isdigit_l
  60. #define isxdigit_l _isxdigit_l
  61. #define strcoll_l _strcoll_l
  62. #define strxfrm_l _strxfrm_l
  63. #define wcscoll_l _wcscoll_l
  64. #define wcsxfrm_l _wcsxfrm_l
  65. #define toupper_l _toupper_l
  66. #define tolower_l _tolower_l
  67. #define iswspace_l _iswspace_l
  68. #define iswprint_l _iswprint_l
  69. #define iswcntrl_l _iswcntrl_l
  70. #define iswupper_l _iswupper_l
  71. #define iswlower_l _iswlower_l
  72. #define iswalpha_l _iswalpha_l
  73. #define iswdigit_l _iswdigit_l
  74. #define iswpunct_l _iswpunct_l
  75. #define iswxdigit_l _iswxdigit_l
  76. #define towupper_l _towupper_l
  77. #define towlower_l _towlower_l
  78. #define strftime_l _strftime_l
  79. #define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ )
  80. #define vsscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ )
  81. #define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ )
  82. #define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ )
  83. #define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ )
  84. int snprintf_l(char *ret, size_t n, locale_t loc, const char *format, ...);
  85. int asprintf_l( char **ret, locale_t loc, const char *format, ... );
  86. int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap );
  87. // not-so-pressing FIXME: use locale to determine blank characters
  88. inline int isblank_l( int c, locale_t /*loc*/ )
  89. {
  90. return ( c == ' ' || c == '\t' );
  91. }
  92. inline int iswblank_l( wint_t c, locale_t /*loc*/ )
  93. {
  94. return ( c == L' ' || c == L'\t' );
  95. }
  96. #if defined(_LIBCPP_MSVCRT)
  97. inline int isblank( int c, locale_t /*loc*/ )
  98. { return ( c == ' ' || c == '\t' ); }
  99. inline int iswblank( wint_t c, locale_t /*loc*/ )
  100. { return ( c == L' ' || c == L'\t' ); }
  101. #endif // _LIBCPP_MSVCRT
  102. #endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H