blob: e035420fb582b041a9753fea6101afca4a784c78 [file] [log] [blame]
Howard Hinnant3c78ca02011-09-22 19:10:18 +00001// -*- C++ -*-
Howard Hinnant8909cdf2011-09-29 20:33:10 +00002//===--------------------- support/win32/locale_win32.h -------------------===//
Howard Hinnant3c78ca02011-09-22 19:10:18 +00003//
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 Hinnant8909cdf2011-09-29 20:33:10 +000011#ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
12#define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
Howard Hinnant34388892011-09-28 21:39:20 +000013
Howard Hinnant0c06e582011-09-29 13:33:15 +000014// ctype mask table defined in msvcrt.dll
15extern "C" unsigned short __declspec(dllimport) _ctype[];
16
Howard Hinnant34388892011-09-28 21:39:20 +000017#include "support/win32/support.h"
18#include <memory>
19#include <xlocinfo.h> // _locale_t
Howard Hinnant3c78ca02011-09-22 19:10:18 +000020#define locale_t _locale_t
Howard Hinnant34388892011-09-28 21:39:20 +000021#define LC_COLLATE_MASK _M_COLLATE
22#define LC_CTYPE_MASK _M_CTYPE
23#define LC_MONETARY_MASK _M_MONETARY
24#define LC_NUMERIC_MASK _M_NUMERIC
25#define LC_TIME_MASK _M_TIME
26#define LC_MESSAGES_MASK _M_MESSAGES
27#define LC_ALL_MASK ( LC_COLLATE_MASK \
28 | LC_CTYPE_MASK \
29 | LC_MESSAGES_MASK \
30 | LC_MONETARY_MASK \
31 | LC_NUMERIC_MASK \
32 | LC_TIME_MASK )
33#define freelocale _free_locale
34// FIXME: base currently unused. Needs manual work to construct the new locale
35locale_t newlocale( int mask, const char * locale, locale_t base );
36locale_t uselocale( locale_t newloc );
37lconv *localeconv_l( locale_t loc );
38size_t mbrlen_l( const char *__restrict__ s, size_t n,
39 mbstate_t *__restrict__ ps, locale_t loc);
40size_t mbsrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
41 size_t len, mbstate_t *__restrict__ ps, locale_t loc );
42size_t wcrtomb_l( char *__restrict__ s, wchar_t wc, mbstate_t *__restrict__ ps,
43 locale_t loc);
44size_t mbrtowc_l( wchar_t *__restrict__ pwc, const char *__restrict__ s,
45 size_t n, mbstate_t *__restrict__ ps, locale_t loc);
46size_t mbsnrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
47 size_t nms, size_t len, mbstate_t *__restrict__ ps, locale_t loc);
48size_t wcsnrtombs_l( char *__restrict__ dst, const wchar_t **__restrict__ src,
49 size_t nwc, size_t len, mbstate_t *__restrict__ ps, locale_t loc);
50wint_t btowc_l( int c, locale_t loc );
51int wctob_l( wint_t c, locale_t loc );
52typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
53typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
54_LIBCPP_ALWAYS_INLINE inline
55decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
56{
57 __locale_raii __current( uselocale(__l), uselocale );
58 return MB_CUR_MAX;
59}
60
61// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
62#include <stdio.h>
63#define mbtowc_l _mbtowc_l
Howard Hinnant3c78ca02011-09-22 19:10:18 +000064#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 Hinnant0c06e582011-09-29 13:33:15 +000068#define islower_l _islower_l
69#define isupper_l _isupper_l
Howard Hinnant3c78ca02011-09-22 19:10:18 +000070#define isdigit_l _isdigit_l
71#define isxdigit_l _isxdigit_l
Howard Hinnantdbe81112011-09-23 16:11:27 +000072#define strcoll_l _strcoll_l
73#define strxfrm_l _strxfrm_l
74#define wcscoll_l _wcscoll_l
75#define wcsxfrm_l _wcsxfrm_l
76#define toupper_l _toupper_l
77#define tolower_l _tolower_l
78#define iswspace_l _iswspace_l
79#define iswprint_l _iswprint_l
80#define iswcntrl_l _iswcntrl_l
81#define iswupper_l _iswupper_l
82#define iswlower_l _iswlower_l
83#define iswalpha_l _iswalpha_l
84#define iswdigit_l _iswdigit_l
85#define iswpunct_l _iswpunct_l
86#define iswxdigit_l _iswxdigit_l
87#define towupper_l _towupper_l
88#define towlower_l _towlower_l
89#define strftime_l _strftime_l
Howard Hinnant34388892011-09-28 21:39:20 +000090#define sscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ )
91#define vsscanf_l( __s, __l, __f, ...) _sscanf_l( __s, __f, __l, __VA_ARGS__ )
92#define sprintf_l( __s, __l, __f, ... ) _sprintf_l( __s, __f, __l, __VA_ARGS__ )
93#define snprintf_l( __s, __n, __l, __f, ... ) _snprintf_l( __s, __n, __f, __l, __VA_ARGS__ )
94#define vsprintf_l( __s, __l, __f, ... ) _vsprintf_l( __s, __f, __l, __VA_ARGS__ )
95#define vsnprintf_l( __s, __n, __l, __f, ... ) _vsnprintf_l( __s, __n, __f, __l, __VA_ARGS__ )
96int asprintf_l( char **ret, locale_t loc, const char *format, ... );
97int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap );
98
99
100// not-so-pressing FIXME: use locale to determine blank characters
Howard Hinnantdbe81112011-09-23 16:11:27 +0000101inline int isblank_l( int c, locale_t /*loc*/ )
102{
103 return ( c == ' ' || c == '\t' );
104}
105inline int iswblank_l( wint_t c, locale_t /*loc*/ )
106{
107 return ( c == L' ' || c == L'\t' );
108}
Howard Hinnantdbe81112011-09-23 16:11:27 +0000109
Howard Hinnant9563a092011-10-27 16:24:42 +0000110#ifdef _MSC_VER
111inline int isblank( int c, locale_t /*loc*/ )
112{ return ( c == ' ' || c == '\t' ); }
113inline int iswblank( wint_t c, locale_t /*loc*/ )
114{ return ( c == L' ' || c == L'\t' ); }
115#endif // _MSC_VER
Howard Hinnant8909cdf2011-09-29 20:33:10 +0000116#endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H