widl: Parse attribute custom(guid,expr).
[wine.git] / include / wine / unicode.h
blob8d30e9f44776bb4a6099c72f6abc80134378a352
1 /*
2 * Wine internal Unicode definitions
4 * Copyright 2000 Alexandre Julliard
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.
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.
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
21 #ifndef __WINE_WINE_UNICODE_H
22 #define __WINE_WINE_UNICODE_H
24 #include <stdarg.h>
26 #include <windef.h>
27 #include <winbase.h>
28 #include <winnls.h>
30 #ifdef __WINE_WINE_TEST_H
31 #error This file should not be used in Wine tests
32 #endif
34 #ifdef __WINE_USE_MSVCRT
35 #error This file should not be used with msvcrt headers
36 #endif
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 #ifndef WINE_UNICODE_INLINE
43 #define WINE_UNICODE_INLINE static inline
44 #endif
46 /* code page info common to SBCS and DBCS */
47 struct cp_info
49 unsigned int codepage; /* codepage id */
50 unsigned int char_size; /* char size (1 or 2 bytes) */
51 WCHAR def_char; /* default char value (can be double-byte) */
52 WCHAR def_unicode_char; /* default Unicode char value */
53 const char *name; /* code page name */
56 struct sbcs_table
58 struct cp_info info;
59 const WCHAR *cp2uni; /* code page -> Unicode map */
60 const WCHAR *cp2uni_glyphs; /* code page -> Unicode map with glyph chars */
61 const unsigned char *uni2cp_low; /* Unicode -> code page map */
62 const unsigned short *uni2cp_high;
65 struct dbcs_table
67 struct cp_info info;
68 const WCHAR *cp2uni; /* code page -> Unicode map */
69 const unsigned char *cp2uni_leadbytes;
70 const unsigned short *uni2cp_low; /* Unicode -> code page map */
71 const unsigned short *uni2cp_high;
72 unsigned char lead_bytes[12]; /* lead bytes ranges */
75 union cptable
77 struct cp_info info;
78 struct sbcs_table sbcs;
79 struct dbcs_table dbcs;
82 extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
83 extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
84 extern int memicmpW( const WCHAR *str1, const WCHAR *str2, int n );
85 extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
86 extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
87 extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
88 extern int sprintfW( WCHAR *str, const WCHAR *format, ... );
89 extern int snprintfW( WCHAR *str, size_t len, const WCHAR *format, ... );
90 extern int vsprintfW( WCHAR *str, const WCHAR *format, va_list valist );
91 extern int vsnprintfW( WCHAR *str, size_t len, const WCHAR *format, va_list valist );
93 WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch )
95 extern const WCHAR wine_casemap_lower[];
96 return ch + wine_casemap_lower[wine_casemap_lower[ch >> 8] + (ch & 0xff)];
99 WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch )
101 extern const WCHAR wine_casemap_upper[];
102 return ch + wine_casemap_upper[wine_casemap_upper[ch >> 8] + (ch & 0xff)];
105 /* the character type contains the C1_* flags in the low 12 bits */
106 /* and the C2_* type in the high 4 bits */
107 WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch )
109 extern const unsigned short wine_wctype_table[];
110 return wine_wctype_table[wine_wctype_table[ch >> 8] + (ch & 0xff)];
113 WINE_UNICODE_INLINE int iscntrlW( WCHAR wc )
115 return get_char_typeW(wc) & C1_CNTRL;
118 WINE_UNICODE_INLINE int ispunctW( WCHAR wc )
120 return get_char_typeW(wc) & C1_PUNCT;
123 WINE_UNICODE_INLINE int isspaceW( WCHAR wc )
125 return get_char_typeW(wc) & C1_SPACE;
128 WINE_UNICODE_INLINE int isdigitW( WCHAR wc )
130 return get_char_typeW(wc) & C1_DIGIT;
133 WINE_UNICODE_INLINE int isxdigitW( WCHAR wc )
135 return get_char_typeW(wc) & C1_XDIGIT;
138 WINE_UNICODE_INLINE int islowerW( WCHAR wc )
140 return get_char_typeW(wc) & C1_LOWER;
143 WINE_UNICODE_INLINE int isupperW( WCHAR wc )
145 return get_char_typeW(wc) & C1_UPPER;
148 WINE_UNICODE_INLINE int isalnumW( WCHAR wc )
150 return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
153 WINE_UNICODE_INLINE int isalphaW( WCHAR wc )
155 return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
158 WINE_UNICODE_INLINE int isgraphW( WCHAR wc )
160 return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
163 WINE_UNICODE_INLINE int isprintW( WCHAR wc )
165 return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
168 /* some useful string manipulation routines */
170 WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str )
172 const WCHAR *s = str;
173 while (*s) s++;
174 return s - str;
177 WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
179 WCHAR *p = dst;
180 while ((*p++ = *src++));
181 return dst;
184 /* strncpy doesn't do what you think, don't use it */
185 #define strncpyW(d,s,n) error do_not_use_strncpyW_use_lstrcpynW_or_memcpy_instead
187 WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 )
189 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
190 return *str1 - *str2;
193 WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
195 if (n <= 0) return 0;
196 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
197 return *str1 - *str2;
200 WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
202 strcpyW( dst + strlenW(dst), src );
203 return dst;
206 WINE_UNICODE_INLINE WCHAR *strchrW( const WCHAR *str, WCHAR ch )
208 do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
209 return NULL;
212 WINE_UNICODE_INLINE WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
214 WCHAR *ret = NULL;
215 do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
216 return ret;
219 WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
221 for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
222 return NULL;
225 WINE_UNICODE_INLINE size_t strspnW( const WCHAR *str, const WCHAR *accept )
227 const WCHAR *ptr;
228 for (ptr = str; *ptr; ptr++) if (!strchrW( accept, *ptr )) break;
229 return ptr - str;
232 WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject )
234 const WCHAR *ptr;
235 for (ptr = str; *ptr; ptr++) if (strchrW( reject, *ptr )) break;
236 return ptr - str;
239 WINE_UNICODE_INLINE WCHAR *strlwrW( WCHAR *str )
241 WCHAR *ret;
242 for (ret = str; *str; str++) *str = tolowerW(*str);
243 return ret;
246 WINE_UNICODE_INLINE WCHAR *struprW( WCHAR *str )
248 WCHAR *ret;
249 for (ret = str; *str; str++) *str = toupperW(*str);
250 return ret;
253 WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
255 const WCHAR *end;
256 for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return (WCHAR *)(ULONG_PTR)ptr;
257 return NULL;
260 WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n )
262 const WCHAR *end;
263 WCHAR *ret = NULL;
264 for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = (WCHAR *)(ULONG_PTR)ptr;
265 return ret;
268 WINE_UNICODE_INLINE long int atolW( const WCHAR *str )
270 return strtolW( str, (WCHAR **)0, 10 );
273 WINE_UNICODE_INLINE int atoiW( const WCHAR *str )
275 return (int)atolW( str );
278 #undef WINE_UNICODE_INLINE
280 #ifdef __cplusplus
282 #endif
284 #endif /* __WINE_WINE_UNICODE_H */