xref: /third_party/musl/src/internal/locale_impl.h (revision 570af302)
1#ifndef _LOCALE_IMPL_H
2#define _LOCALE_IMPL_H
3
4#include <locale.h>
5#include <stdlib.h>
6#include "libc.h"
7#include "pthread_impl.h"
8
9#define LOCALE_NAME_MAX 23
10#define VALID 2
11#define INVALID 1
12#define ICU_VALID 3
13
14struct __locale_map {
15	const void *map;
16	size_t map_size;
17	char name[LOCALE_NAME_MAX+1];
18	const struct __locale_map *next;
19	char flag;
20};
21
22extern hidden volatile int __locale_lock[1];
23
24extern hidden const struct __locale_map __c_dot_utf8;
25extern hidden const struct __locale_struct __c_locale;
26extern hidden const struct __locale_struct __c_dot_utf8_locale;
27
28hidden const struct __locale_map *__get_locale(int, const char *);
29hidden const char *__mo_lookup(const void *, size_t, const char *);
30hidden const char *__lctrans(const char *, const struct __locale_map *);
31hidden const char *__lctrans_cur(const char *);
32hidden const char *__lctrans_impl(const char *, const struct __locale_map *);
33hidden int __loc_is_allocated(locale_t);
34hidden char *__gettextdomain(void);
35
36#ifdef FEATURE_ICU_LOCALE
37#define ICU_GET_VERSION_NUM_SYMBOL "GetIcuVersion"
38#define ICU_SET_DATA_DIRECTORY_SYMBOL "SetOhosIcuDirectory"
39#define ICU_UNUM_OPEN_SYMBOL "unum_open"
40#define ICU_UNUM_CLOSE_SYMBOL "unum_close"
41#define ICU_STR_FROM_UTF8_SYMBOL "u_strFromUTF8"
42#define ICU_STR_FROM_UTF32_SYMBOL "u_strFromUTF32"
43#define ICU_UNUM_PARSE_DOUBLE_SYMBOL "unum_parseDouble"
44#define ICU_UNUM_GET_SYMBOL_SYMBOL "unum_getSymbol"
45#define ICU_AUSTRNCPY_SYMBOL "u_austrncpy"
46#ifdef FEATURE_ICU_LOCALE_TMP
47#define ICU_UCHAR_ISALNUM_SYMBOL	"u_isalnum"
48#define ICU_UCHAR_ISALPHA_SYMBOL 	"u_isalpha"
49#define ICU_UCHAR_ISBLANK_SYMBOL 	"u_isblank"
50#define ICU_UCHAR_ISCNTRL_SYMBOL 	"u_iscntrl"
51#define ICU_UCHAR_ISDIGIT_SYMBOL 	"u_isdigit"
52#define ICU_UCHAR_ISGRAPH_SYMBOL 	"u_isgraph"
53#define ICU_UCHAR_ISLOWER_SYMBOL 	"u_islower"
54#define ICU_UCHAR_ISPRINT_SYMBOL 	"u_isprint"
55#define ICU_UCHAR_ISPUNCT_SYMBOL 	"u_ispunct"
56#define ICU_UCHAR_ISSPACE_SYMBOL 	"u_isspace"
57#define ICU_UCHAR_ISUPPER_SYMBOL 	"u_isupper"
58#define ICU_UCHAR_ISXDIGIT_SYMBOL 	"u_isxdigit"
59#define ICU_UCHAR_TOLOWER_SYMBOL 	"u_tolower"
60#define ICU_UCHAR_TOUPPER_SYMBOL 	"u_toupper"
61#endif
62
63typedef enum {
64	ICU_UC = 0,
65	ICU_I18N,
66} icu_so_type;
67
68#define MAX_VALID_ICU_NAME_LEN 8
69typedef uint16_t u_char;
70
71hidden void set_icu_directory();
72hidden void get_icu_symbol(icu_so_type type, void **icu_symbol_handle, const char *symbol_name);
73hidden void get_valid_icu_locale_name(const char *name, const char *icu_name, int icu_name_len);
74hidden void *icu_unum_open(char *icu_locale_name, int *cur_status);
75hidden void icu_unum_close(void *fmt);
76hidden double icu_parse_double(void *fmt, u_char *ustr, int32_t *parse_pos, int *cur_status);
77
78typedef char *(*f_icuuc_get_icu_version)(void);
79typedef void (*f_icuuc_u_set_data_directory)(void);
80typedef void *(*f_icu18n_unum_open)(int, void *, int32_t, const char *, void *, void *);
81typedef void (*f_icu18n_unum_close)(void *);
82typedef void *(*f_icu18n_u_str_from_utf8)(u_char *, int32_t, int32_t *, const char *, int32_t, int *);
83typedef void *(*f_icu18n_u_str_from_utf32)(u_char *, int32_t, int32_t *, const wchar_t *, int32_t, int *);
84typedef double (*f_icu18n_unum_parse_double)(void *, u_char *, int32_t, int32_t *, int *);
85typedef int32_t(*f_icu18n_unum_get_symbol)(const void *, int, u_char *, int32_t, int *);
86typedef char *(*f_icuuc_u_austrncpy)(char *, const u_char *, int32_t);
87#ifdef FEATURE_ICU_LOCALE_TMP
88typedef int(*f_icu18n_u_isalnum)(int c);
89typedef int(*f_icu18n_u_isalpha)(int c);
90typedef int(*f_icu18n_u_isblank)(int c);
91typedef int(*f_icu18n_u_iscntrl)(int c);
92typedef int(*f_icu18n_u_isdigit)(int c);
93typedef int(*f_icu18n_u_isgraph)(int c);
94typedef int(*f_icu18n_u_islower)(int c);
95typedef int(*f_icu18n_u_isprint)(int c);
96typedef int(*f_icu18n_u_ispunct)(int c);
97typedef int(*f_icu18n_u_isspace)(int c);
98typedef int(*f_icu18n_u_isupper)(int c);
99typedef int(*f_icu18n_u_isxdigit)(int c);
100typedef int(*f_icu18n_u_tolower)(int c);
101typedef int(*f_icu18n_u_toupper)(int c);
102#endif
103
104struct icu_opt_func {
105	f_icuuc_get_icu_version get_icu_version;
106	f_icuuc_u_set_data_directory set_data_directory;
107	f_icu18n_unum_open unum_open;
108	f_icu18n_unum_close unum_close;
109	f_icu18n_u_str_from_utf8 u_str_from_utf8;
110	f_icu18n_u_str_from_utf32 u_str_from_utf32;
111	f_icu18n_unum_parse_double unum_parse_double;
112	f_icu18n_unum_get_symbol unum_get_symbol;
113	f_icuuc_u_austrncpy u_austrncpy;
114#ifdef FEATURE_ICU_LOCALE_TMP
115	f_icu18n_u_isalnum u_isalnum;
116	f_icu18n_u_isalpha u_isalpha;
117	f_icu18n_u_isblank u_isblank;
118	f_icu18n_u_iscntrl u_iscntrl;
119	f_icu18n_u_isdigit u_isdigit;
120	f_icu18n_u_isgraph u_isgraph;
121	f_icu18n_u_islower u_islower;
122	f_icu18n_u_isprint u_isprint;
123	f_icu18n_u_ispunct u_ispunct;
124	f_icu18n_u_isspace u_isspace;
125	f_icu18n_u_isupper u_isupper;
126	f_icu18n_u_isxdigit u_isxdigit;
127	f_icu18n_u_tolower u_tolower;
128	f_icu18n_u_toupper u_toupper;
129#endif
130};
131extern hidden struct icu_opt_func g_icu_opt_func;
132
133#define DLSYM_ICU_SUCC 0
134#define DLSYM_ICU_FAIL 1
135#define ICU_ERROR (-1)
136#endif
137
138#define LOC_MAP_FAILED ((const struct __locale_map *)-1)
139
140#define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)])
141#define LCTRANS_CUR(msg) __lctrans_cur(msg)
142
143#define C_LOCALE ((locale_t)&__c_locale)
144#define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale)
145
146#define CURRENT_LOCALE (__pthread_self()->locale)
147
148#define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE])
149
150#undef MB_CUR_MAX
151#define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1)
152
153#endif
154