VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/unicode.h@ 16410

最後變更 在這個檔案從16410是 16410,由 vboxsync 提交於 16 年 前

export the Wine stuff to OSE

  • 屬性 svn:eol-style 設為 native
檔案大小: 11.0 KB
 
1/*
2 * Wine internal Unicode definitions
3 *
4 * Copyright 2000 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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
19 */
20
21#ifndef __WINE_WINE_UNICODE_H
22#define __WINE_WINE_UNICODE_H
23
24#include <stdarg.h>
25
26#include <windef.h>
27#include <winbase.h>
28#include <winnls.h>
29
30#ifdef __WINE_WINE_TEST_H
31#error This file should not be used in Wine tests
32#endif
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#ifndef WINE_UNICODE_API
39# if defined(_MSC_VER) || defined(__MINGW32__)
40# define WINE_UNICODE_API DECLSPEC_IMPORT
41# else
42# define WINE_UNICODE_API
43# endif
44#endif
45
46/*#ifndef WINE_UNICODE_INLINE
47#define WINE_UNICODE_INLINE extern inline
48#endif*/
49
50/* code page info common to SBCS and DBCS */
51struct cp_info
52{
53 unsigned int codepage; /* codepage id */
54 unsigned int char_size; /* char size (1 or 2 bytes) */
55 WCHAR def_char; /* default char value (can be double-byte) */
56 WCHAR def_unicode_char; /* default Unicode char value */
57 const char *name; /* code page name */
58};
59
60struct sbcs_table
61{
62 struct cp_info info;
63 const WCHAR *cp2uni; /* code page -> Unicode map */
64 const WCHAR *cp2uni_glyphs; /* code page -> Unicode map with glyph chars */
65 const unsigned char *uni2cp_low; /* Unicode -> code page map */
66 const unsigned short *uni2cp_high;
67};
68
69struct dbcs_table
70{
71 struct cp_info info;
72 const WCHAR *cp2uni; /* code page -> Unicode map */
73 const unsigned char *cp2uni_leadbytes;
74 const unsigned short *uni2cp_low; /* Unicode -> code page map */
75 const unsigned short *uni2cp_high;
76 unsigned char lead_bytes[12]; /* lead bytes ranges */
77};
78
79union cptable
80{
81 struct cp_info info;
82 struct sbcs_table sbcs;
83 struct dbcs_table dbcs;
84};
85
86extern const union cptable *wine_cp_get_table( unsigned int codepage );
87extern const union cptable *wine_cp_enum_table( unsigned int index );
88
89extern int wine_cp_mbstowcs( const union cptable *table, int flags,
90 const char *src, int srclen,
91 WCHAR *dst, int dstlen );
92extern int wine_cp_wcstombs( const union cptable *table, int flags,
93 const WCHAR *src, int srclen,
94 char *dst, int dstlen, const char *defchar, int *used );
95extern int wine_cpsymbol_mbstowcs( const char *src, int srclen, WCHAR *dst, int dstlen );
96extern int wine_cpsymbol_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
97extern int wine_utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
98extern int wine_utf8_wcstombs( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
99
100extern int wine_compare_string( int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2 );
101extern int wine_get_sortkey( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
102extern int wine_fold_string( int flags, const WCHAR *src, int srclen , WCHAR *dst, int dstlen );
103
104extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
105extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
106extern int memicmpW( const WCHAR *str1, const WCHAR *str2, int n );
107extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
108extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
109extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
110extern int sprintfW( WCHAR *str, const WCHAR *format, ... );
111extern int snprintfW( WCHAR *str, size_t len, const WCHAR *format, ... );
112extern int vsprintfW( WCHAR *str, const WCHAR *format, va_list valist );
113extern int vsnprintfW( WCHAR *str, size_t len, const WCHAR *format, va_list valist );
114
115#ifdef WINE_UNICODE_INLINE
116
117WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch );
118WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
119{
120 return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
121}
122
123WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch );
124WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch )
125{
126 extern WINE_UNICODE_API const WCHAR wine_casemap_lower[];
127 return ch + wine_casemap_lower[wine_casemap_lower[ch >> 8] + (ch & 0xff)];
128}
129
130WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch );
131WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch )
132{
133 extern WINE_UNICODE_API const WCHAR wine_casemap_upper[];
134 return ch + wine_casemap_upper[wine_casemap_upper[ch >> 8] + (ch & 0xff)];
135}
136
137/* the character type contains the C1_* flags in the low 12 bits */
138/* and the C2_* type in the high 4 bits */
139WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch );
140WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch )
141{
142 extern WINE_UNICODE_API const unsigned short wine_wctype_table[];
143 return wine_wctype_table[wine_wctype_table[ch >> 8] + (ch & 0xff)];
144}
145
146WINE_UNICODE_INLINE int iscntrlW( WCHAR wc );
147WINE_UNICODE_INLINE int iscntrlW( WCHAR wc )
148{
149 return get_char_typeW(wc) & C1_CNTRL;
150}
151
152WINE_UNICODE_INLINE int ispunctW( WCHAR wc );
153WINE_UNICODE_INLINE int ispunctW( WCHAR wc )
154{
155 return get_char_typeW(wc) & C1_PUNCT;
156}
157
158WINE_UNICODE_INLINE int isspaceW( WCHAR wc );
159WINE_UNICODE_INLINE int isspaceW( WCHAR wc )
160{
161 return get_char_typeW(wc) & C1_SPACE;
162}
163
164WINE_UNICODE_INLINE int isdigitW( WCHAR wc );
165WINE_UNICODE_INLINE int isdigitW( WCHAR wc )
166{
167 return get_char_typeW(wc) & C1_DIGIT;
168}
169
170WINE_UNICODE_INLINE int isxdigitW( WCHAR wc );
171WINE_UNICODE_INLINE int isxdigitW( WCHAR wc )
172{
173 return get_char_typeW(wc) & C1_XDIGIT;
174}
175
176WINE_UNICODE_INLINE int islowerW( WCHAR wc );
177WINE_UNICODE_INLINE int islowerW( WCHAR wc )
178{
179 return get_char_typeW(wc) & C1_LOWER;
180}
181
182WINE_UNICODE_INLINE int isupperW( WCHAR wc );
183WINE_UNICODE_INLINE int isupperW( WCHAR wc )
184{
185 return get_char_typeW(wc) & C1_UPPER;
186}
187
188WINE_UNICODE_INLINE int isalnumW( WCHAR wc );
189WINE_UNICODE_INLINE int isalnumW( WCHAR wc )
190{
191 return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
192}
193
194WINE_UNICODE_INLINE int isalphaW( WCHAR wc );
195WINE_UNICODE_INLINE int isalphaW( WCHAR wc )
196{
197 return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
198}
199
200WINE_UNICODE_INLINE int isgraphW( WCHAR wc );
201WINE_UNICODE_INLINE int isgraphW( WCHAR wc )
202{
203 return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
204}
205
206WINE_UNICODE_INLINE int isprintW( WCHAR wc );
207WINE_UNICODE_INLINE int isprintW( WCHAR wc )
208{
209 return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
210}
211
212/* some useful string manipulation routines */
213
214WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str );
215WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str )
216{
217 const WCHAR *s = str;
218 while (*s) s++;
219 return s - str;
220}
221
222WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src );
223WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
224{
225 WCHAR *p = dst;
226 while ((*p++ = *src++));
227 return dst;
228}
229
230/* strncpy doesn't do what you think, don't use it */
231#define strncpyW(d,s,n) error do_not_use_strncpyW_use_lstrcpynW_or_memcpy_instead
232
233WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 );
234WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 )
235{
236 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
237 return *str1 - *str2;
238}
239
240WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n );
241WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
242{
243 if (n <= 0) return 0;
244 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
245 return *str1 - *str2;
246}
247
248WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src );
249WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
250{
251 strcpyW( dst + strlenW(dst), src );
252 return dst;
253}
254
255WINE_UNICODE_INLINE WCHAR *strchrW( const WCHAR *str, WCHAR ch );
256WINE_UNICODE_INLINE WCHAR *strchrW( const WCHAR *str, WCHAR ch )
257{
258 do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
259 return NULL;
260}
261
262WINE_UNICODE_INLINE WCHAR *strrchrW( const WCHAR *str, WCHAR ch );
263WINE_UNICODE_INLINE WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
264{
265 WCHAR *ret = NULL;
266 do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
267 return ret;
268}
269
270WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept );
271WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
272{
273 for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
274 return NULL;
275}
276
277WINE_UNICODE_INLINE size_t strspnW( const WCHAR *str, const WCHAR *accept );
278WINE_UNICODE_INLINE size_t strspnW( const WCHAR *str, const WCHAR *accept )
279{
280 const WCHAR *ptr;
281 for (ptr = str; *ptr; ptr++) if (!strchrW( accept, *ptr )) break;
282 return ptr - str;
283}
284
285WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject );
286WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject )
287{
288 const WCHAR *ptr;
289 for (ptr = str; *ptr; ptr++) if (strchrW( reject, *ptr )) break;
290 return ptr - str;
291}
292
293WINE_UNICODE_INLINE WCHAR *strlwrW( WCHAR *str );
294WINE_UNICODE_INLINE WCHAR *strlwrW( WCHAR *str )
295{
296 WCHAR *ret = str;
297 while ((*str = tolowerW(*str))) str++;
298 return ret;
299}
300
301WINE_UNICODE_INLINE WCHAR *struprW( WCHAR *str );
302WINE_UNICODE_INLINE WCHAR *struprW( WCHAR *str )
303{
304 WCHAR *ret = str;
305 while ((*str = toupperW(*str))) str++;
306 return ret;
307}
308
309WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n );
310WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
311{
312 const WCHAR *end;
313 for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return (WCHAR *)(ULONG_PTR)ptr;
314 return NULL;
315}
316
317WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n );
318WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n )
319{
320 const WCHAR *end;
321 WCHAR *ret = NULL;
322 for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = (WCHAR *)(ULONG_PTR)ptr;
323 return ret;
324}
325
326WINE_UNICODE_INLINE long int atolW( const WCHAR *str );
327WINE_UNICODE_INLINE long int atolW( const WCHAR *str )
328{
329 return strtolW( str, (WCHAR **)0, 10 );
330}
331
332WINE_UNICODE_INLINE int atoiW( const WCHAR *str );
333WINE_UNICODE_INLINE int atoiW( const WCHAR *str )
334{
335 return (int)atolW( str );
336}
337#endif //#ifdef WINE_UNICODE_INLINE
338
339#undef WINE_UNICODE_INLINE
340
341#ifdef __cplusplus
342}
343#endif
344
345#endif /* __WINE_WINE_UNICODE_H */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette