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
30 #ifdef __WINE_WINE_TEST_H
31 #error This file should not be used in Wine tests
34 #ifndef WINE_UNICODE_API
35 #define WINE_UNICODE_API DECLSPEC_IMPORT
38 /* code page info common to SBCS and DBCS */
41 unsigned int codepage; /* codepage id */
42 unsigned int char_size; /* char size (1 or 2 bytes) */
43 WCHAR def_char; /* default char value (can be double-byte) */
44 WCHAR def_unicode_char; /* default Unicode char value */
45 const char *name; /* code page name */
51 const WCHAR *cp2uni; /* code page -> Unicode map */
52 const unsigned char *uni2cp_low; /* Unicode -> code page map */
53 const unsigned short *uni2cp_high;
59 const WCHAR *cp2uni; /* code page -> Unicode map */
60 const unsigned char *cp2uni_leadbytes;
61 const unsigned short *uni2cp_low; /* Unicode -> code page map */
62 const unsigned short *uni2cp_high;
63 unsigned char lead_bytes[12]; /* lead bytes ranges */
69 struct sbcs_table sbcs;
70 struct dbcs_table dbcs;
73 extern const union cptable *wine_cp_get_table( unsigned int codepage );
74 extern const union cptable *wine_cp_enum_table( unsigned int index );
76 extern int wine_cp_mbstowcs( const union cptable *table, int flags,
77 const char *src, int srclen,
78 WCHAR *dst, int dstlen );
79 extern int wine_cp_wcstombs( const union cptable *table, int flags,
80 const WCHAR *src, int srclen,
81 char *dst, int dstlen, const char *defchar, int *used );
82 extern int wine_cpsymbol_mbstowcs( const char *src, int srclen, WCHAR *dst, int dstlen );
83 extern int wine_cpsymbol_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
84 extern int wine_utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
85 extern int wine_utf8_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
87 extern int wine_compare_string( int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2 );
88 extern int wine_get_sortkey( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
89 extern int wine_fold_string( int flags, const WCHAR *src, int srclen , WCHAR *dst, int dstlen );
91 extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
92 extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
93 extern int memicmpW( const WCHAR *str1, const WCHAR *str2, int n );
94 extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
95 extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
96 extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
97 extern int sprintfW( WCHAR *str, const WCHAR *format, ... );
98 extern int snprintfW( WCHAR *str, size_t len, const WCHAR *format, ... );
99 extern int vsprintfW( WCHAR *str, const WCHAR *format, va_list valist );
100 extern int vsnprintfW( WCHAR *str, size_t len, const WCHAR *format, va_list valist );
102 extern inline int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch );
103 extern inline int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
105 return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
108 extern inline WCHAR tolowerW( WCHAR ch );
109 extern inline WCHAR tolowerW( WCHAR ch )
111 extern WINE_UNICODE_API const WCHAR wine_casemap_lower[];
112 return ch + wine_casemap_lower[wine_casemap_lower[ch >> 8] + (ch & 0xff)];
115 extern inline WCHAR toupperW( WCHAR ch );
116 extern inline WCHAR toupperW( WCHAR ch )
118 extern WINE_UNICODE_API const WCHAR wine_casemap_upper[];
119 return ch + wine_casemap_upper[wine_casemap_upper[ch >> 8] + (ch & 0xff)];
122 /* the character type contains the C1_* flags in the low 12 bits */
123 /* and the C2_* type in the high 4 bits */
124 extern inline unsigned short get_char_typeW( WCHAR ch );
125 extern inline unsigned short get_char_typeW( WCHAR ch )
127 extern WINE_UNICODE_API const unsigned short wine_wctype_table[];
128 return wine_wctype_table[wine_wctype_table[ch >> 8] + (ch & 0xff)];
131 extern inline int iscntrlW( WCHAR wc );
132 extern inline int iscntrlW( WCHAR wc )
134 return get_char_typeW(wc) & C1_CNTRL;
137 extern inline int ispunctW( WCHAR wc );
138 extern inline int ispunctW( WCHAR wc )
140 return get_char_typeW(wc) & C1_PUNCT;
143 extern inline int isspaceW( WCHAR wc );
144 extern inline int isspaceW( WCHAR wc )
146 return get_char_typeW(wc) & C1_SPACE;
149 extern inline int isdigitW( WCHAR wc );
150 extern inline int isdigitW( WCHAR wc )
152 return get_char_typeW(wc) & C1_DIGIT;
155 extern inline int isxdigitW( WCHAR wc );
156 extern inline int isxdigitW( WCHAR wc )
158 return get_char_typeW(wc) & C1_XDIGIT;
161 extern inline int islowerW( WCHAR wc );
162 extern inline int islowerW( WCHAR wc )
164 return get_char_typeW(wc) & C1_LOWER;
167 extern inline int isupperW( WCHAR wc );
168 extern inline int isupperW( WCHAR wc )
170 return get_char_typeW(wc) & C1_UPPER;
173 extern inline int isalnumW( WCHAR wc );
174 extern inline int isalnumW( WCHAR wc )
176 return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
179 extern inline int isalphaW( WCHAR wc );
180 extern inline int isalphaW( WCHAR wc )
182 return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
185 extern inline int isgraphW( WCHAR wc );
186 extern inline int isgraphW( WCHAR wc )
188 return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
191 extern inline int isprintW( WCHAR wc );
192 extern inline int isprintW( WCHAR wc )
194 return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
197 /* some useful string manipulation routines */
199 extern inline unsigned int strlenW( const WCHAR *str );
200 extern inline unsigned int strlenW( const WCHAR *str )
202 const WCHAR *s = str;
207 extern inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src );
208 extern inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
211 while ((*p++ = *src++));
215 /* strncpy doesn't do what you think, don't use it */
216 #define strncpyW(d,s,n) error do_not_use_strncpyW_use_lstrcpynW_or_memcpy_instead
218 extern inline int strcmpW( const WCHAR *str1, const WCHAR *str2 );
219 extern inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
221 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
222 return *str1 - *str2;
225 extern inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n );
226 extern inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
228 if (n <= 0) return 0;
229 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
230 return *str1 - *str2;
233 extern inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src );
234 extern inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
236 strcpyW( dst + strlenW(dst), src );
240 extern inline WCHAR *strchrW( const WCHAR *str, WCHAR ch );
241 extern inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
243 do { if (*str == ch) return (WCHAR *)str; } while (*str++);
247 extern inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch );
248 extern inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
251 do { if (*str == ch) ret = (WCHAR *)str; } while (*str++);
255 extern inline WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept );
256 extern inline WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
258 for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)str;
262 extern inline size_t strspnW( const WCHAR *str, const WCHAR *accept );
263 extern inline size_t strspnW( const WCHAR *str, const WCHAR *accept )
266 for (ptr = str; *ptr; ptr++) if (!strchrW( accept, *ptr )) break;
270 extern inline size_t strcspnW( const WCHAR *str, const WCHAR *reject );
271 extern inline size_t strcspnW( const WCHAR *str, const WCHAR *reject )
274 for (ptr = str; *ptr; ptr++) if (strchrW( reject, *ptr )) break;
278 extern inline WCHAR *strlwrW( WCHAR *str );
279 extern inline WCHAR *strlwrW( WCHAR *str )
282 while ((*str = tolowerW(*str))) str++;
286 extern inline WCHAR *struprW( WCHAR *str );
287 extern inline WCHAR *struprW( WCHAR *str )
290 while ((*str = toupperW(*str))) str++;
294 extern inline WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n );
295 extern inline WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
298 for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return (WCHAR *)ptr;
302 extern inline WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n );
303 extern inline WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n )
305 const WCHAR *end, *ret = NULL;
306 for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = ptr;
310 extern inline long int atolW( const WCHAR *str );
311 extern inline long int atolW( const WCHAR *str )
313 return strtolW( str, (WCHAR **)0, 10 );
316 extern inline int atoiW( const WCHAR *str );
317 extern inline int atoiW( const WCHAR *str )
319 return (int)atolW( str );
322 #endif /* __WINE_WINE_UNICODE_H */