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

Last change on this file was 21352, checked in by rlwalsh, 16 years ago

eliminate VACPP warning & info msgs - see Ticket #1

File size: 8.3 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/*RLW*/
102extern _K32CONV int sprintfW( WCHAR *str, const WCHAR *format, ...);
103
104static inline int is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
105{
106 return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
107}
108
109static inline WCHAR tolowerW( WCHAR ch )
110{
111 extern const WCHAR casemap_lower[];
112 return ch + casemap_lower[casemap_lower[ch >> 8] + (ch & 0xff)];
113}
114
115static inline WCHAR toupperW( WCHAR ch )
116{
117 extern const WCHAR casemap_upper[];
118 return ch + casemap_upper[casemap_upper[ch >> 8] + (ch & 0xff)];
119}
120
121/* the character type contains the C1_* flags in the low 12 bits */
122/* and the C2_* type in the high 4 bits */
123static inline unsigned short get_char_typeW( WCHAR ch )
124{
125 extern const unsigned short wctype_table[];
126 return wctype_table[wctype_table[ch >> 8] + (ch & 0xff)];
127}
128
129inline static int iscntrlW( WCHAR wc )
130{
131 return get_char_typeW(wc) & C1_CNTRL;
132}
133
134inline static int ispunctW( WCHAR wc )
135{
136 return get_char_typeW(wc) & C1_PUNCT;
137}
138
139inline static int isspaceW( WCHAR wc )
140{
141 return get_char_typeW(wc) & C1_SPACE;
142}
143
144inline static int isdigitW( WCHAR wc )
145{
146 return get_char_typeW(wc) & C1_DIGIT;
147}
148
149inline static int isxdigitW( WCHAR wc )
150{
151 return get_char_typeW(wc) & C1_XDIGIT;
152}
153
154inline static int islowerW( WCHAR wc )
155{
156 return get_char_typeW(wc) & C1_LOWER;
157}
158
159inline static int isupperW( WCHAR wc )
160{
161 return get_char_typeW(wc) & C1_UPPER;
162}
163
164inline static int isalnumW( WCHAR wc )
165{
166 return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
167}
168
169inline static int isalphaW( WCHAR wc )
170{
171 return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
172}
173
174inline static int isgraphW( WCHAR wc )
175{
176 return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
177}
178
179inline static int isprintW( WCHAR wc )
180{
181 return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
182}
183
184
185/* some useful string manipulation routines */
186
187static inline unsigned int strlenW( const WCHAR *str )
188{
189#if defined(__i386__) && defined(__GNUC__)
190 int dummy, res;
191 __asm__ __volatile__( "cld\n\t"
192 "repnz\n\t"
193 "scasw\n\t"
194 "notl %0"
195 : "=c" (res), "=&D" (dummy)
196 : "0" (0xffffffff), "1" (str), "a" (0) );
197 return res - 1;
198#else
199 const WCHAR *s = str;
200 while (*s) s++;
201 return s - str;
202#endif
203}
204
205static inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
206{
207#if defined(__i386__) && defined(__GNUC__)
208 int dummy1, dummy2, dummy3;
209 __asm__ __volatile__( "cld\n"
210 "1:\tlodsw\n\t"
211 "stosw\n\t"
212 "testw %%ax,%%ax\n\t"
213 "jne 1b"
214 : "=&S" (dummy1), "=&D" (dummy2), "=&a" (dummy3)
215 : "0" (src), "1" (dst)
216 : "memory" );
217#else
218 WCHAR *p = dst;
219 while(*src) {
220 *p++ = *src++;
221 }
222 *p = 0;
223#endif
224 return dst;
225}
226
227static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
228{
229 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
230 return *str1 - *str2;
231}
232
233static inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
234{
235 if (n <= 0) return 0;
236 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
237 return *str1 - *str2;
238}
239
240static inline WCHAR *strncpyW( WCHAR *str1, const WCHAR *str2, int n )
241{
242 WCHAR *ret = str1;
243 #ifdef __WATCOMC__ /* kso: it's so noisy and I don't find the right pragma... */
244 while (n-- > 0) if ((*str1++ = *str2++) != 0) break;
245 #else
246 while (n-- > 0) if (!(*str1++ = *str2++)) break;
247 #endif
248 while (n-- > 0) *str1++ = 0;
249 return ret;
250}
251
252static inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
253{
254 strcpyW( dst + strlenW(dst), src );
255 return dst;
256}
257
258static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
259{
260 for ( ; *str; str++) if (*str == ch) return (WCHAR *)str;
261 return NULL;
262}
263
264static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
265{
266 WCHAR *ret = NULL;
267 for ( ; *str; str++) if (*str == ch) ret = (WCHAR *)str;
268 return ret;
269}
270
271static inline WCHAR *strlwrW( WCHAR *str )
272{
273 WCHAR *ret = str;
274 while(*str) {
275 *str = tolowerW(*str);
276 str++;
277 }
278 return ret;
279}
280
281static inline WCHAR *struprW( WCHAR *str )
282{
283 WCHAR *ret = str;
284 while(*str) {
285 *str = toupperW(*str);
286 str++;
287 }
288 return ret;
289}
290
291static inline long int atolW( const WCHAR *str )
292{
293 return strtolW( str, (WCHAR **)0, 10 );
294}
295
296static inline int atoiW( const WCHAR *str )
297{
298 return (int)atolW( str );
299}
300
301#if defined(__IBMC__) || defined(__IBMCPP__) || defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
302#undef static
303#endif
304
305#ifdef __cplusplus
306}
307#endif
308
309#endif //RC_INVOKED
310
311#endif /* __WINE_UNICODE_H */
Note: See TracBrowser for help on using the repository browser.