source: trunk/include/win/wine/unicode.h@ 21307

Last change on this file since 21307 was 21307, checked in by ydario, 16 years ago

Support gcc 4.x for ntdll

File size: 8.2 KB
Line 
1/*
2 * Wine internal Unicode definitions
3 *
4 * Copyright 2000 Alexandre Julliard
5 */
6
7#ifndef __WINE_UNICODE_H
8#define __WINE_UNICODE_H
9
10#ifndef RC_INVOKED
11
12#include <stdarg.h>
13#if !defined(OS2_INCLUDED) && !defined(__WIN32TYPE_H__)
14#include <windef.h>
15#endif
16#include <winnls.h>
17
18
19#ifndef strncasecmp
20#define strncasecmp lstrncmpiA
21#endif
22#ifndef strcasecmp
23#define strcasecmp lstrcmpiA
24#endif
25
26/* code page info common to SBCS and DBCS */
27struct cp_info
28{
29 unsigned int codepage; /* codepage id */
30 unsigned int char_size; /* char size (1 or 2 bytes) */
31 WCHAR def_char; /* default char value (can be double-byte) */
32 WCHAR def_unicode_char; /* default Unicode char value */
33 const char *name; /* code page name */
34};
35
36struct sbcs_table
37{
38 struct cp_info info;
39 const WCHAR *cp2uni; /* code page -> Unicode map */
40 const unsigned char *uni2cp_low; /* Unicode -> code page map */
41 const unsigned short *uni2cp_high;
42};
43
44struct dbcs_table
45{
46 struct cp_info info;
47 const WCHAR *cp2uni; /* code page -> Unicode map */
48 const unsigned char *cp2uni_leadbytes;
49 const unsigned short *uni2cp_low; /* Unicode -> code page map */
50 const unsigned short *uni2cp_high;
51 unsigned char lead_bytes[12]; /* lead bytes ranges */
52};
53
54union cptable
55{
56 struct cp_info info;
57 struct sbcs_table sbcs;
58 struct dbcs_table dbcs;
59};
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65#if defined(__IBMC__) || defined(__IBMCPP__) || defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
66#define static
67#endif
68
69#ifdef __EMX__
70#define _K32CONV _Optlink
71#else
72#define _K32CONV
73#endif
74
75#if defined(__IBMC__) || defined(__IBMCPP__)
76// YD match gcc 4.x prefix
77#define casemap_upper _casemap_upper
78#define casemap_lower _casemap_lower
79#define wctype_table _wctype_table
80#endif
81
82extern _K32CONV const union cptable *cp_get_table( unsigned int codepage );
83extern _K32CONV const union cptable *cp_enum_table( unsigned int index );
84
85extern _K32CONV int cp_mbstowcs( const union cptable *table, int flags,
86 const char *src, int srclen,
87 WCHAR *dst, int dstlen );
88extern _K32CONV int cp_wcstombs( const union cptable *table, int flags,
89 const WCHAR *src, int srclen,
90 char *dst, int dstlen, const char *defchar, int *used );
91extern _K32CONV int utf8_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
92extern _K32CONV int utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
93
94extern _K32CONV int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
95extern _K32CONV int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
96extern _K32CONV WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
97extern _K32CONV long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
98extern _K32CONV unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
99extern _K32CONV int snprintfW( WCHAR *str, unsigned int len, const WCHAR *format, ... );
100extern _K32CONV int vsnprintfW( WCHAR *str, unsigned int len, const WCHAR *format, va_list valist );
101
102static inline int is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
103{
104 return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
105}
106
107static inline WCHAR tolowerW( WCHAR ch )
108{
109 extern const WCHAR casemap_lower[];
110 return ch + casemap_lower[casemap_lower[ch >> 8] + (ch & 0xff)];
111}
112
113static inline WCHAR toupperW( WCHAR ch )
114{
115 extern const WCHAR casemap_upper[];
116 return ch + casemap_upper[casemap_upper[ch >> 8] + (ch & 0xff)];
117}
118
119/* the character type contains the C1_* flags in the low 12 bits */
120/* and the C2_* type in the high 4 bits */
121static inline unsigned short get_char_typeW( WCHAR ch )
122{
123 extern const unsigned short wctype_table[];
124 return wctype_table[wctype_table[ch >> 8] + (ch & 0xff)];
125}
126
127inline static int iscntrlW( WCHAR wc )
128{
129 return get_char_typeW(wc) & C1_CNTRL;
130}
131
132inline static int ispunctW( WCHAR wc )
133{
134 return get_char_typeW(wc) & C1_PUNCT;
135}
136
137inline static int isspaceW( WCHAR wc )
138{
139 return get_char_typeW(wc) & C1_SPACE;
140}
141
142inline static int isdigitW( WCHAR wc )
143{
144 return get_char_typeW(wc) & C1_DIGIT;
145}
146
147inline static int isxdigitW( WCHAR wc )
148{
149 return get_char_typeW(wc) & C1_XDIGIT;
150}
151
152inline static int islowerW( WCHAR wc )
153{
154 return get_char_typeW(wc) & C1_LOWER;
155}
156
157inline static int isupperW( WCHAR wc )
158{
159 return get_char_typeW(wc) & C1_UPPER;
160}
161
162inline static int isalnumW( WCHAR wc )
163{
164 return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
165}
166
167inline static int isalphaW( WCHAR wc )
168{
169 return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
170}
171
172inline static int isgraphW( WCHAR wc )
173{
174 return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
175}
176
177inline static int isprintW( WCHAR wc )
178{
179 return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
180}
181
182
183/* some useful string manipulation routines */
184
185static inline unsigned int strlenW( const WCHAR *str )
186{
187#if defined(__i386__) && defined(__GNUC__)
188 int dummy, res;
189 __asm__ __volatile__( "cld\n\t"
190 "repnz\n\t"
191 "scasw\n\t"
192 "notl %0"
193 : "=c" (res), "=&D" (dummy)
194 : "0" (0xffffffff), "1" (str), "a" (0) );
195 return res - 1;
196#else
197 const WCHAR *s = str;
198 while (*s) s++;
199 return s - str;
200#endif
201}
202
203static inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
204{
205#if defined(__i386__) && defined(__GNUC__)
206 int dummy1, dummy2, dummy3;
207 __asm__ __volatile__( "cld\n"
208 "1:\tlodsw\n\t"
209 "stosw\n\t"
210 "testw %%ax,%%ax\n\t"
211 "jne 1b"
212 : "=&S" (dummy1), "=&D" (dummy2), "=&a" (dummy3)
213 : "0" (src), "1" (dst)
214 : "memory" );
215#else
216 WCHAR *p = dst;
217 while(*src) {
218 *p++ = *src++;
219 }
220 *p = 0;
221#endif
222 return dst;
223}
224
225static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
226{
227 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
228 return *str1 - *str2;
229}
230
231static 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
238static inline WCHAR *strncpyW( WCHAR *str1, const WCHAR *str2, int n )
239{
240 WCHAR *ret = str1;
241 #ifdef __WATCOMC__ /* kso: it's so noisy and I don't find the right pragma... */
242 while (n-- > 0) if ((*str1++ = *str2++) != 0) break;
243 #else
244 while (n-- > 0) if (!(*str1++ = *str2++)) break;
245 #endif
246 while (n-- > 0) *str1++ = 0;
247 return ret;
248}
249
250static inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
251{
252 strcpyW( dst + strlenW(dst), src );
253 return dst;
254}
255
256static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
257{
258 for ( ; *str; str++) if (*str == ch) return (WCHAR *)str;
259 return NULL;
260}
261
262static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
263{
264 WCHAR *ret = NULL;
265 for ( ; *str; str++) if (*str == ch) ret = (WCHAR *)str;
266 return ret;
267}
268
269static inline WCHAR *strlwrW( WCHAR *str )
270{
271 WCHAR *ret = str;
272 while(*str) {
273 *str = tolowerW(*str);
274 str++;
275 }
276 return ret;
277}
278
279static inline WCHAR *struprW( WCHAR *str )
280{
281 WCHAR *ret = str;
282 while(*str) {
283 *str = toupperW(*str);
284 str++;
285 }
286 return ret;
287}
288
289static inline long int atolW( const WCHAR *str )
290{
291 return strtolW( str, (WCHAR **)0, 10 );
292}
293
294static inline int atoiW( const WCHAR *str )
295{
296 return (int)atolW( str );
297}
298
299#if defined(__IBMC__) || defined(__IBMCPP__) || defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
300#undef static
301#endif
302
303#ifdef __cplusplus
304}
305#endif
306
307#endif //RC_INVOKED
308
309#endif /* __WINE_UNICODE_H */
Note: See TracBrowser for help on using the repository browser.