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

Last change on this file since 10367 was 9962, checked in by sandervl, 22 years ago

PF: Added vsnprintfW/snprintfW funcs for syncing with latest wine NTDLL

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