1 | /*
|
---|
2 | * Wine internal Unicode definitions
|
---|
3 | *
|
---|
4 | * Copyright 2000 Alexandre Julliard
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | /*
|
---|
22 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
23 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
24 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
25 | * a choice of LGPL license versions is made available with the language indicating
|
---|
26 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
27 | * of the LGPL is applied is otherwise unspecified.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef __WINE_WINE_UNICODE_H
|
---|
31 | #define __WINE_WINE_UNICODE_H
|
---|
32 |
|
---|
33 | #include <stdarg.h>
|
---|
34 |
|
---|
35 | #include <windef.h>
|
---|
36 | #include <winbase.h>
|
---|
37 | #include <winnls.h>
|
---|
38 |
|
---|
39 | #ifdef __WINE_WINE_TEST_H
|
---|
40 | #error This file should not be used in Wine tests
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #ifdef __cplusplus
|
---|
44 | extern "C" {
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #ifndef WINE_UNICODE_API
|
---|
48 | # if defined(_MSC_VER) || defined(__MINGW32__)
|
---|
49 | # define WINE_UNICODE_API DECLSPEC_IMPORT
|
---|
50 | # else
|
---|
51 | # define WINE_UNICODE_API
|
---|
52 | # endif
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | /*#ifndef WINE_UNICODE_INLINE
|
---|
56 | #define WINE_UNICODE_INLINE extern inline
|
---|
57 | #endif*/
|
---|
58 |
|
---|
59 | /* code page info common to SBCS and DBCS */
|
---|
60 | struct cp_info
|
---|
61 | {
|
---|
62 | unsigned int codepage; /* codepage id */
|
---|
63 | unsigned int char_size; /* char size (1 or 2 bytes) */
|
---|
64 | WCHAR def_char; /* default char value (can be double-byte) */
|
---|
65 | WCHAR def_unicode_char; /* default Unicode char value */
|
---|
66 | const char *name; /* code page name */
|
---|
67 | };
|
---|
68 |
|
---|
69 | struct sbcs_table
|
---|
70 | {
|
---|
71 | struct cp_info info;
|
---|
72 | const WCHAR *cp2uni; /* code page -> Unicode map */
|
---|
73 | const WCHAR *cp2uni_glyphs; /* code page -> Unicode map with glyph chars */
|
---|
74 | const unsigned char *uni2cp_low; /* Unicode -> code page map */
|
---|
75 | const unsigned short *uni2cp_high;
|
---|
76 | };
|
---|
77 |
|
---|
78 | struct dbcs_table
|
---|
79 | {
|
---|
80 | struct cp_info info;
|
---|
81 | const WCHAR *cp2uni; /* code page -> Unicode map */
|
---|
82 | const unsigned char *cp2uni_leadbytes;
|
---|
83 | const unsigned short *uni2cp_low; /* Unicode -> code page map */
|
---|
84 | const unsigned short *uni2cp_high;
|
---|
85 | unsigned char lead_bytes[12]; /* lead bytes ranges */
|
---|
86 | };
|
---|
87 |
|
---|
88 | union cptable
|
---|
89 | {
|
---|
90 | struct cp_info info;
|
---|
91 | struct sbcs_table sbcs;
|
---|
92 | struct dbcs_table dbcs;
|
---|
93 | };
|
---|
94 |
|
---|
95 | extern const union cptable *wine_cp_get_table( unsigned int codepage );
|
---|
96 | extern const union cptable *wine_cp_enum_table( unsigned int index );
|
---|
97 |
|
---|
98 | extern int wine_cp_mbstowcs( const union cptable *table, int flags,
|
---|
99 | const char *src, int srclen,
|
---|
100 | WCHAR *dst, int dstlen );
|
---|
101 | extern int wine_cp_wcstombs( const union cptable *table, int flags,
|
---|
102 | const WCHAR *src, int srclen,
|
---|
103 | char *dst, int dstlen, const char *defchar, int *used );
|
---|
104 | extern int wine_cpsymbol_mbstowcs( const char *src, int srclen, WCHAR *dst, int dstlen );
|
---|
105 | extern int wine_cpsymbol_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
|
---|
106 | extern int wine_utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
|
---|
107 | extern int wine_utf8_wcstombs( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
|
---|
108 |
|
---|
109 | extern int wine_compare_string( int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2 );
|
---|
110 | extern int wine_get_sortkey( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
|
---|
111 | extern int wine_fold_string( int flags, const WCHAR *src, int srclen , WCHAR *dst, int dstlen );
|
---|
112 |
|
---|
113 | extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
|
---|
114 | extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
|
---|
115 | extern int memicmpW( const WCHAR *str1, const WCHAR *str2, int n );
|
---|
116 | extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
|
---|
117 | extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
|
---|
118 | extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
|
---|
119 | extern int sprintfW( WCHAR *str, const WCHAR *format, ... );
|
---|
120 | extern int snprintfW( WCHAR *str, size_t len, const WCHAR *format, ... );
|
---|
121 | extern int vsprintfW( WCHAR *str, const WCHAR *format, va_list valist );
|
---|
122 | extern int vsnprintfW( WCHAR *str, size_t len, const WCHAR *format, va_list valist );
|
---|
123 |
|
---|
124 | #ifdef WINE_UNICODE_INLINE
|
---|
125 |
|
---|
126 | WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch );
|
---|
127 | WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
|
---|
128 | {
|
---|
129 | return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
|
---|
130 | }
|
---|
131 |
|
---|
132 | WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch );
|
---|
133 | WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch )
|
---|
134 | {
|
---|
135 | extern WINE_UNICODE_API const WCHAR wine_casemap_lower[];
|
---|
136 | return ch + wine_casemap_lower[wine_casemap_lower[ch >> 8] + (ch & 0xff)];
|
---|
137 | }
|
---|
138 |
|
---|
139 | WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch );
|
---|
140 | WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch )
|
---|
141 | {
|
---|
142 | extern WINE_UNICODE_API const WCHAR wine_casemap_upper[];
|
---|
143 | return ch + wine_casemap_upper[wine_casemap_upper[ch >> 8] + (ch & 0xff)];
|
---|
144 | }
|
---|
145 |
|
---|
146 | /* the character type contains the C1_* flags in the low 12 bits */
|
---|
147 | /* and the C2_* type in the high 4 bits */
|
---|
148 | WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch );
|
---|
149 | WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch )
|
---|
150 | {
|
---|
151 | extern WINE_UNICODE_API const unsigned short wine_wctype_table[];
|
---|
152 | return wine_wctype_table[wine_wctype_table[ch >> 8] + (ch & 0xff)];
|
---|
153 | }
|
---|
154 |
|
---|
155 | WINE_UNICODE_INLINE int iscntrlW( WCHAR wc );
|
---|
156 | WINE_UNICODE_INLINE int iscntrlW( WCHAR wc )
|
---|
157 | {
|
---|
158 | return get_char_typeW(wc) & C1_CNTRL;
|
---|
159 | }
|
---|
160 |
|
---|
161 | WINE_UNICODE_INLINE int ispunctW( WCHAR wc );
|
---|
162 | WINE_UNICODE_INLINE int ispunctW( WCHAR wc )
|
---|
163 | {
|
---|
164 | return get_char_typeW(wc) & C1_PUNCT;
|
---|
165 | }
|
---|
166 |
|
---|
167 | WINE_UNICODE_INLINE int isspaceW( WCHAR wc );
|
---|
168 | WINE_UNICODE_INLINE int isspaceW( WCHAR wc )
|
---|
169 | {
|
---|
170 | return get_char_typeW(wc) & C1_SPACE;
|
---|
171 | }
|
---|
172 |
|
---|
173 | WINE_UNICODE_INLINE int isdigitW( WCHAR wc );
|
---|
174 | WINE_UNICODE_INLINE int isdigitW( WCHAR wc )
|
---|
175 | {
|
---|
176 | return get_char_typeW(wc) & C1_DIGIT;
|
---|
177 | }
|
---|
178 |
|
---|
179 | WINE_UNICODE_INLINE int isxdigitW( WCHAR wc );
|
---|
180 | WINE_UNICODE_INLINE int isxdigitW( WCHAR wc )
|
---|
181 | {
|
---|
182 | return get_char_typeW(wc) & C1_XDIGIT;
|
---|
183 | }
|
---|
184 |
|
---|
185 | WINE_UNICODE_INLINE int islowerW( WCHAR wc );
|
---|
186 | WINE_UNICODE_INLINE int islowerW( WCHAR wc )
|
---|
187 | {
|
---|
188 | return get_char_typeW(wc) & C1_LOWER;
|
---|
189 | }
|
---|
190 |
|
---|
191 | WINE_UNICODE_INLINE int isupperW( WCHAR wc );
|
---|
192 | WINE_UNICODE_INLINE int isupperW( WCHAR wc )
|
---|
193 | {
|
---|
194 | return get_char_typeW(wc) & C1_UPPER;
|
---|
195 | }
|
---|
196 |
|
---|
197 | WINE_UNICODE_INLINE int isalnumW( WCHAR wc );
|
---|
198 | WINE_UNICODE_INLINE int isalnumW( WCHAR wc )
|
---|
199 | {
|
---|
200 | return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
|
---|
201 | }
|
---|
202 |
|
---|
203 | WINE_UNICODE_INLINE int isalphaW( WCHAR wc );
|
---|
204 | WINE_UNICODE_INLINE int isalphaW( WCHAR wc )
|
---|
205 | {
|
---|
206 | return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
|
---|
207 | }
|
---|
208 |
|
---|
209 | WINE_UNICODE_INLINE int isgraphW( WCHAR wc );
|
---|
210 | WINE_UNICODE_INLINE int isgraphW( WCHAR wc )
|
---|
211 | {
|
---|
212 | return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
|
---|
213 | }
|
---|
214 |
|
---|
215 | WINE_UNICODE_INLINE int isprintW( WCHAR wc );
|
---|
216 | WINE_UNICODE_INLINE int isprintW( WCHAR wc )
|
---|
217 | {
|
---|
218 | return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /* some useful string manipulation routines */
|
---|
222 |
|
---|
223 | WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str );
|
---|
224 | WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str )
|
---|
225 | {
|
---|
226 | const WCHAR *s = str;
|
---|
227 | while (*s) s++;
|
---|
228 | return s - str;
|
---|
229 | }
|
---|
230 |
|
---|
231 | WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src );
|
---|
232 | WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
|
---|
233 | {
|
---|
234 | WCHAR *p = dst;
|
---|
235 | while ((*p++ = *src++));
|
---|
236 | return dst;
|
---|
237 | }
|
---|
238 |
|
---|
239 | /* strncpy doesn't do what you think, don't use it */
|
---|
240 | #define strncpyW(d,s,n) error do_not_use_strncpyW_use_lstrcpynW_or_memcpy_instead
|
---|
241 |
|
---|
242 | WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 );
|
---|
243 | WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 )
|
---|
244 | {
|
---|
245 | while (*str1 && (*str1 == *str2)) { str1++; str2++; }
|
---|
246 | return *str1 - *str2;
|
---|
247 | }
|
---|
248 |
|
---|
249 | WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n );
|
---|
250 | WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
|
---|
251 | {
|
---|
252 | if (n <= 0) return 0;
|
---|
253 | while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
|
---|
254 | return *str1 - *str2;
|
---|
255 | }
|
---|
256 |
|
---|
257 | WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src );
|
---|
258 | WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
|
---|
259 | {
|
---|
260 | strcpyW( dst + strlenW(dst), src );
|
---|
261 | return dst;
|
---|
262 | }
|
---|
263 |
|
---|
264 | WINE_UNICODE_INLINE WCHAR *strchrW( const WCHAR *str, WCHAR ch );
|
---|
265 | WINE_UNICODE_INLINE WCHAR *strchrW( const WCHAR *str, WCHAR ch )
|
---|
266 | {
|
---|
267 | do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
|
---|
268 | return NULL;
|
---|
269 | }
|
---|
270 |
|
---|
271 | WINE_UNICODE_INLINE WCHAR *strrchrW( const WCHAR *str, WCHAR ch );
|
---|
272 | WINE_UNICODE_INLINE WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
|
---|
273 | {
|
---|
274 | WCHAR *ret = NULL;
|
---|
275 | do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
|
---|
276 | return ret;
|
---|
277 | }
|
---|
278 |
|
---|
279 | WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept );
|
---|
280 | WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
|
---|
281 | {
|
---|
282 | for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
|
---|
283 | return NULL;
|
---|
284 | }
|
---|
285 |
|
---|
286 | WINE_UNICODE_INLINE size_t strspnW( const WCHAR *str, const WCHAR *accept );
|
---|
287 | WINE_UNICODE_INLINE size_t strspnW( const WCHAR *str, const WCHAR *accept )
|
---|
288 | {
|
---|
289 | const WCHAR *ptr;
|
---|
290 | for (ptr = str; *ptr; ptr++) if (!strchrW( accept, *ptr )) break;
|
---|
291 | return ptr - str;
|
---|
292 | }
|
---|
293 |
|
---|
294 | WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject );
|
---|
295 | WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject )
|
---|
296 | {
|
---|
297 | const WCHAR *ptr;
|
---|
298 | for (ptr = str; *ptr; ptr++) if (strchrW( reject, *ptr )) break;
|
---|
299 | return ptr - str;
|
---|
300 | }
|
---|
301 |
|
---|
302 | WINE_UNICODE_INLINE WCHAR *strlwrW( WCHAR *str );
|
---|
303 | WINE_UNICODE_INLINE WCHAR *strlwrW( WCHAR *str )
|
---|
304 | {
|
---|
305 | WCHAR *ret = str;
|
---|
306 | while ((*str = tolowerW(*str))) str++;
|
---|
307 | return ret;
|
---|
308 | }
|
---|
309 |
|
---|
310 | WINE_UNICODE_INLINE WCHAR *struprW( WCHAR *str );
|
---|
311 | WINE_UNICODE_INLINE WCHAR *struprW( WCHAR *str )
|
---|
312 | {
|
---|
313 | WCHAR *ret = str;
|
---|
314 | while ((*str = toupperW(*str))) str++;
|
---|
315 | return ret;
|
---|
316 | }
|
---|
317 |
|
---|
318 | WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n );
|
---|
319 | WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
|
---|
320 | {
|
---|
321 | const WCHAR *end;
|
---|
322 | for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return (WCHAR *)(ULONG_PTR)ptr;
|
---|
323 | return NULL;
|
---|
324 | }
|
---|
325 |
|
---|
326 | WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n );
|
---|
327 | WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n )
|
---|
328 | {
|
---|
329 | const WCHAR *end;
|
---|
330 | WCHAR *ret = NULL;
|
---|
331 | for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = (WCHAR *)(ULONG_PTR)ptr;
|
---|
332 | return ret;
|
---|
333 | }
|
---|
334 |
|
---|
335 | WINE_UNICODE_INLINE long int atolW( const WCHAR *str );
|
---|
336 | WINE_UNICODE_INLINE long int atolW( const WCHAR *str )
|
---|
337 | {
|
---|
338 | return strtolW( str, (WCHAR **)0, 10 );
|
---|
339 | }
|
---|
340 |
|
---|
341 | WINE_UNICODE_INLINE int atoiW( const WCHAR *str );
|
---|
342 | WINE_UNICODE_INLINE int atoiW( const WCHAR *str )
|
---|
343 | {
|
---|
344 | return (int)atolW( str );
|
---|
345 | }
|
---|
346 | #endif //#ifdef WINE_UNICODE_INLINE
|
---|
347 |
|
---|
348 | #undef WINE_UNICODE_INLINE
|
---|
349 |
|
---|
350 | #ifdef __cplusplus
|
---|
351 | }
|
---|
352 | #endif
|
---|
353 |
|
---|
354 | #endif /* __WINE_WINE_UNICODE_H */
|
---|