wined3d: Add sincos support to arb shaders.
[wine] / include / wine / unicode.h
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 #ifndef __WINE_WINE_UNICODE_H
22 #define __WINE_WINE_UNICODE_H
23
24 #include <stdarg.h>
25
26 #include <windef.h>
27 #include <winbase.h>
28 #include <winnls.h>
29
30 #ifdef __WINE_WINE_TEST_H
31 #error This file should not be used in Wine tests
32 #endif
33
34 #ifndef WINE_UNICODE_API
35 #define WINE_UNICODE_API DECLSPEC_IMPORT
36 #endif
37
38 #ifndef WINE_UNICODE_INLINE
39 #define WINE_UNICODE_INLINE extern inline
40 #endif
41
42 /* code page info common to SBCS and DBCS */
43 struct cp_info
44 {
45     unsigned int          codepage;          /* codepage id */
46     unsigned int          char_size;         /* char size (1 or 2 bytes) */
47     WCHAR                 def_char;          /* default char value (can be double-byte) */
48     WCHAR                 def_unicode_char;  /* default Unicode char value */
49     const char           *name;              /* code page name */
50 };
51
52 struct sbcs_table
53 {
54     struct cp_info        info;
55     const WCHAR          *cp2uni;            /* code page -> Unicode map */
56     const WCHAR          *cp2uni_glyphs;     /* code page -> Unicode map with glyph chars */
57     const unsigned char  *uni2cp_low;        /* Unicode -> code page map */
58     const unsigned short *uni2cp_high;
59 };
60
61 struct dbcs_table
62 {
63     struct cp_info        info;
64     const WCHAR          *cp2uni;            /* code page -> Unicode map */
65     const unsigned char  *cp2uni_leadbytes;
66     const unsigned short *uni2cp_low;        /* Unicode -> code page map */
67     const unsigned short *uni2cp_high;
68     unsigned char         lead_bytes[12];    /* lead bytes ranges */
69 };
70
71 union cptable
72 {
73     struct cp_info    info;
74     struct sbcs_table sbcs;
75     struct dbcs_table dbcs;
76 };
77
78 extern const union cptable *wine_cp_get_table( unsigned int codepage );
79 extern const union cptable *wine_cp_enum_table( unsigned int index );
80
81 extern int wine_cp_mbstowcs( const union cptable *table, int flags,
82                              const char *src, int srclen,
83                              WCHAR *dst, int dstlen );
84 extern int wine_cp_wcstombs( const union cptable *table, int flags,
85                              const WCHAR *src, int srclen,
86                              char *dst, int dstlen, const char *defchar, int *used );
87 extern int wine_cpsymbol_mbstowcs( const char *src, int srclen, WCHAR *dst, int dstlen );
88 extern int wine_cpsymbol_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
89 extern int wine_utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
90 extern int wine_utf8_wcstombs( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
91
92 extern int wine_compare_string( int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2 );
93 extern int wine_get_sortkey( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
94 extern int wine_fold_string( int flags, const WCHAR *src, int srclen , WCHAR *dst, int dstlen );
95
96 extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
97 extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
98 extern int memicmpW( const WCHAR *str1, const WCHAR *str2, int n );
99 extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
100 extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
101 extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
102 extern int sprintfW( WCHAR *str, const WCHAR *format, ... );
103 extern int snprintfW( WCHAR *str, size_t len, const WCHAR *format, ... );
104 extern int vsprintfW( WCHAR *str, const WCHAR *format, va_list valist );
105 extern int vsnprintfW( WCHAR *str, size_t len, const WCHAR *format, va_list valist );
106
107 WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch );
108 WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
109 {
110     return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
111 }
112
113 WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch );
114 WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch )
115 {
116     extern WINE_UNICODE_API const WCHAR wine_casemap_lower[];
117     return ch + wine_casemap_lower[wine_casemap_lower[ch >> 8] + (ch & 0xff)];
118 }
119
120 WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch );
121 WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch )
122 {
123     extern WINE_UNICODE_API const WCHAR wine_casemap_upper[];
124     return ch + wine_casemap_upper[wine_casemap_upper[ch >> 8] + (ch & 0xff)];
125 }
126
127 /* the character type contains the C1_* flags in the low 12 bits */
128 /* and the C2_* type in the high 4 bits */
129 WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch );
130 WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch )
131 {
132     extern WINE_UNICODE_API const unsigned short wine_wctype_table[];
133     return wine_wctype_table[wine_wctype_table[ch >> 8] + (ch & 0xff)];
134 }
135
136 WINE_UNICODE_INLINE int iscntrlW( WCHAR wc );
137 WINE_UNICODE_INLINE int iscntrlW( WCHAR wc )
138 {
139     return get_char_typeW(wc) & C1_CNTRL;
140 }
141
142 WINE_UNICODE_INLINE int ispunctW( WCHAR wc );
143 WINE_UNICODE_INLINE int ispunctW( WCHAR wc )
144 {
145     return get_char_typeW(wc) & C1_PUNCT;
146 }
147
148 WINE_UNICODE_INLINE int isspaceW( WCHAR wc );
149 WINE_UNICODE_INLINE int isspaceW( WCHAR wc )
150 {
151     return get_char_typeW(wc) & C1_SPACE;
152 }
153
154 WINE_UNICODE_INLINE int isdigitW( WCHAR wc );
155 WINE_UNICODE_INLINE int isdigitW( WCHAR wc )
156 {
157     return get_char_typeW(wc) & C1_DIGIT;
158 }
159
160 WINE_UNICODE_INLINE int isxdigitW( WCHAR wc );
161 WINE_UNICODE_INLINE int isxdigitW( WCHAR wc )
162 {
163     return get_char_typeW(wc) & C1_XDIGIT;
164 }
165
166 WINE_UNICODE_INLINE int islowerW( WCHAR wc );
167 WINE_UNICODE_INLINE int islowerW( WCHAR wc )
168 {
169     return get_char_typeW(wc) & C1_LOWER;
170 }
171
172 WINE_UNICODE_INLINE int isupperW( WCHAR wc );
173 WINE_UNICODE_INLINE int isupperW( WCHAR wc )
174 {
175     return get_char_typeW(wc) & C1_UPPER;
176 }
177
178 WINE_UNICODE_INLINE int isalnumW( WCHAR wc );
179 WINE_UNICODE_INLINE int isalnumW( WCHAR wc )
180 {
181     return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
182 }
183
184 WINE_UNICODE_INLINE int isalphaW( WCHAR wc );
185 WINE_UNICODE_INLINE int isalphaW( WCHAR wc )
186 {
187     return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
188 }
189
190 WINE_UNICODE_INLINE int isgraphW( WCHAR wc );
191 WINE_UNICODE_INLINE int isgraphW( WCHAR wc )
192 {
193     return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
194 }
195
196 WINE_UNICODE_INLINE int isprintW( WCHAR wc );
197 WINE_UNICODE_INLINE int isprintW( WCHAR wc )
198 {
199     return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
200 }
201
202 /* some useful string manipulation routines */
203
204 WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str );
205 WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str )
206 {
207     const WCHAR *s = str;
208     while (*s) s++;
209     return s - str;
210 }
211
212 WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src );
213 WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
214 {
215     WCHAR *p = dst;
216     while ((*p++ = *src++));
217     return dst;
218 }
219
220 /* strncpy doesn't do what you think, don't use it */
221 #define strncpyW(d,s,n) error do_not_use_strncpyW_use_lstrcpynW_or_memcpy_instead
222
223 WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 );
224 WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 )
225 {
226     while (*str1 && (*str1 == *str2)) { str1++; str2++; }
227     return *str1 - *str2;
228 }
229
230 WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n );
231 WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
232 {
233     if (n <= 0) return 0;
234     while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
235     return *str1 - *str2;
236 }
237
238 WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src );
239 WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
240 {
241     strcpyW( dst + strlenW(dst), src );
242     return dst;
243 }
244
245 WINE_UNICODE_INLINE WCHAR *strchrW( const WCHAR *str, WCHAR ch );
246 WINE_UNICODE_INLINE WCHAR *strchrW( const WCHAR *str, WCHAR ch )
247 {
248     do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
249     return NULL;
250 }
251
252 WINE_UNICODE_INLINE WCHAR *strrchrW( const WCHAR *str, WCHAR ch );
253 WINE_UNICODE_INLINE WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
254 {
255     WCHAR *ret = NULL;
256     do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
257     return ret;
258 }
259
260 WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept );
261 WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
262 {
263     for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
264     return NULL;
265 }
266
267 WINE_UNICODE_INLINE size_t strspnW( const WCHAR *str, const WCHAR *accept );
268 WINE_UNICODE_INLINE size_t strspnW( const WCHAR *str, const WCHAR *accept )
269 {
270     const WCHAR *ptr;
271     for (ptr = str; *ptr; ptr++) if (!strchrW( accept, *ptr )) break;
272     return ptr - str;
273 }
274
275 WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject );
276 WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject )
277 {
278     const WCHAR *ptr;
279     for (ptr = str; *ptr; ptr++) if (strchrW( reject, *ptr )) break;
280     return ptr - str;
281 }
282
283 WINE_UNICODE_INLINE WCHAR *strlwrW( WCHAR *str );
284 WINE_UNICODE_INLINE WCHAR *strlwrW( WCHAR *str )
285 {
286     WCHAR *ret = str;
287     while ((*str = tolowerW(*str))) str++;
288     return ret;
289 }
290
291 WINE_UNICODE_INLINE WCHAR *struprW( WCHAR *str );
292 WINE_UNICODE_INLINE WCHAR *struprW( WCHAR *str )
293 {
294     WCHAR *ret = str;
295     while ((*str = toupperW(*str))) str++;
296     return ret;
297 }
298
299 WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n );
300 WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
301 {
302     const WCHAR *end;
303     for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return (WCHAR *)(ULONG_PTR)ptr;
304     return NULL;
305 }
306
307 WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n );
308 WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n )
309 {
310     const WCHAR *end;
311     WCHAR *ret = NULL;
312     for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = (WCHAR *)(ULONG_PTR)ptr;
313     return ret;
314 }
315
316 WINE_UNICODE_INLINE long int atolW( const WCHAR *str );
317 WINE_UNICODE_INLINE long int atolW( const WCHAR *str )
318 {
319     return strtolW( str, (WCHAR **)0, 10 );
320 }
321
322 WINE_UNICODE_INLINE int atoiW( const WCHAR *str );
323 WINE_UNICODE_INLINE int atoiW( const WCHAR *str )
324 {
325     return (int)atolW( str );
326 }
327
328 #undef WINE_UNICODE_INLINE
329
330 #endif  /* __WINE_WINE_UNICODE_H */