ReactOS  0.4.12-dev-919-gfc3b8d5
unicode.h
Go to the documentation of this file.
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 <ctype.h>
25 #include <stdarg.h>
26 #include <string.h>
27 #include <typedefs.h>
28 
29 // Definitions copied from <winnls.h>
30 // We only want to include host headers, so we define them manually
31 #define C1_UPPER 1
32 #define C1_LOWER 2
33 #define C1_DIGIT 4
34 #define C1_SPACE 8
35 #define C1_PUNCT 16
36 #define C1_CNTRL 32
37 #define C1_BLANK 64
38 #define C1_XDIGIT 128
39 #define C1_ALPHA 256
40 #define MB_COMPOSITE 2
41 #define MB_ERR_INVALID_CHARS 8
42 #define MB_USEGLYPHCHARS 0x04
43 #define WC_COMPOSITECHECK 512
44 #define WC_DISCARDNS 16
45 #define WC_DEFAULTCHAR 64
46 #define WC_NO_BEST_FIT_CHARS 1024
47 #define WC_ERR_INVALID_CHARS 0x0080
48 
49 #ifdef __WINE_WINE_TEST_H
50 #error This file should not be used in Wine tests
51 #endif
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 #ifndef WINE_UNICODE_API
58 #define WINE_UNICODE_API
59 #endif
60 
61 #ifndef WINE_UNICODE_INLINE
62 #define WINE_UNICODE_INLINE static inline
63 #endif
64 
65 /* code page info common to SBCS and DBCS */
66 struct cp_info
67 {
68  unsigned int codepage; /* codepage id */
69  unsigned int char_size; /* char size (1 or 2 bytes) */
70  WCHAR def_char; /* default char value (can be double-byte) */
71  WCHAR def_unicode_char; /* default Unicode char value */
72  const char *name; /* code page name */
73 };
74 
75 struct sbcs_table
76 {
77  struct cp_info info;
78  const WCHAR *cp2uni; /* code page -> Unicode map */
79  const WCHAR *cp2uni_glyphs; /* code page -> Unicode map with glyph chars */
80  const unsigned char *uni2cp_low; /* Unicode -> code page map */
81  const unsigned short *uni2cp_high;
82 };
83 
84 struct dbcs_table
85 {
86  struct cp_info info;
87  const WCHAR *cp2uni; /* code page -> Unicode map */
88  const unsigned char *cp2uni_leadbytes;
89  const unsigned short *uni2cp_low; /* Unicode -> code page map */
90  const unsigned short *uni2cp_high;
91  unsigned char lead_bytes[12]; /* lead bytes ranges */
92 };
93 
94 union cptable
95 {
96  struct cp_info info;
97  struct sbcs_table sbcs;
98  struct dbcs_table dbcs;
99 };
100 
101 extern const union cptable *wine_cp_get_table( unsigned int codepage );
102 extern const union cptable *wine_cp_enum_table( unsigned int index );
103 
104 extern int wine_cp_mbstowcs( const union cptable *table, int flags,
105  const char *src, int srclen,
106  WCHAR *dst, int dstlen );
107 extern int wine_cp_wcstombs( const union cptable *table, int flags,
108  const WCHAR *src, int srclen,
109  char *dst, int dstlen, const char *defchar, int *used );
110 extern int wine_cpsymbol_mbstowcs( const char *src, int srclen, WCHAR *dst, int dstlen );
111 extern int wine_cpsymbol_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
112 extern int wine_utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
113 extern int wine_utf8_wcstombs( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
114 
115 extern int wine_compare_string( int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2 );
116 extern int wine_get_sortkey( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
117 extern int wine_fold_string( int flags, const WCHAR *src, int srclen , WCHAR *dst, int dstlen );
118 
119 extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
120 extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
121 extern int memicmpW( const WCHAR *str1, const WCHAR *str2, int n );
122 extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
123 extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
124 extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
125 extern int sprintfW( WCHAR *str, const WCHAR *format, ... );
126 extern int snprintfW( WCHAR *str, size_t len, const WCHAR *format, ... );
127 extern int vsprintfW( WCHAR *str, const WCHAR *format, va_list valist );
128 extern int vsnprintfW( WCHAR *str, size_t len, const WCHAR *format, va_list valist );
129 
130 WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
131 {
132  return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
133 }
134 
136 {
138  return ch + wine_casemap_lower[wine_casemap_lower[ch >> 8] + (ch & 0xff)];
139 }
140 
142 {
144  return ch + wine_casemap_upper[wine_casemap_upper[ch >> 8] + (ch & 0xff)];
145 }
146 
147 /* the character type contains the C1_* flags in the low 12 bits */
148 /* and the C2_* type in the high 4 bits */
150 {
151  extern WINE_UNICODE_API const unsigned short wine_wctype_table[];
152  return wine_wctype_table[wine_wctype_table[ch >> 8] + (ch & 0xff)];
153 }
154 
156 {
157  return get_char_typeW(wc) & C1_CNTRL;
158 }
159 
161 {
162  return get_char_typeW(wc) & C1_PUNCT;
163 }
164 
166 {
167  return get_char_typeW(wc) & C1_SPACE;
168 }
169 
171 {
172  return get_char_typeW(wc) & C1_DIGIT;
173 }
174 
176 {
177  return get_char_typeW(wc) & C1_XDIGIT;
178 }
179 
181 {
182  return get_char_typeW(wc) & C1_LOWER;
183 }
184 
186 {
187  return get_char_typeW(wc) & C1_UPPER;
188 }
189 
191 {
193 }
194 
196 {
197  return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
198 }
199 
201 {
203 }
204 
206 {
208 }
209 
210 /* some useful string manipulation routines */
211 
212 WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str )
213 {
214  const WCHAR *s = str;
215  while (*s) s++;
216  return (unsigned int)(s - str);
217 }
218 
220 {
221  WCHAR *p = dst;
222  while ((*p++ = *src++));
223  return dst;
224 }
225 
226 /* strncpy doesn't do what you think, don't use it */
227 #define strncpyW(d,s,n) error do_not_use_strncpyW_use_lstrcpynW_or_memcpy_instead
228 
229 WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 )
230 {
231  while (*str1 && (*str1 == *str2)) { str1++; str2++; }
232  return *str1 - *str2;
233 }
234 
235 WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
236 {
237  if (n <= 0) return 0;
238  while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
239  return *str1 - *str2;
240 }
241 
243 {
244  strcpyW( dst + strlenW(dst), src );
245  return dst;
246 }
247 
249 {
250  do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
251  return NULL;
252 }
253 
255 {
256  WCHAR *ret = NULL;
257  do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
258  return ret;
259 }
260 
262 {
263  for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
264  return NULL;
265 }
266 
268 {
269  const WCHAR *ptr;
270  for (ptr = str; *ptr; ptr++) if (!strchrW( accept, *ptr )) break;
271  return ptr - str;
272 }
273 
274 WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject )
275 {
276  const WCHAR *ptr;
277  for (ptr = str; *ptr; ptr++) if (strchrW( reject, *ptr )) break;
278  return ptr - str;
279 }
280 
282 {
283  WCHAR *ret = str;
284  while ((*str = tolowerW(*str))) str++;
285  return ret;
286 }
287 
289 {
290  WCHAR *ret = str;
291  while ((*str = toupperW(*str))) str++;
292  return ret;
293 }
294 
296 {
297  const WCHAR *end;
298  for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return (WCHAR *)(ULONG_PTR)ptr;
299  return NULL;
300 }
301 
303 {
304  const WCHAR *end;
305  WCHAR *ret = NULL;
306  for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = (WCHAR *)(ULONG_PTR)ptr;
307  return ret;
308 }
309 
310 WINE_UNICODE_INLINE long int atolW( const WCHAR *str )
311 {
312  return strtolW( str, (WCHAR **)0, 10 );
313 }
314 
316 {
317  return (int)atolW( str );
318 }
319 
320 #undef WINE_UNICODE_INLINE
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 #endif /* __WINE_WINE_UNICODE_H */
const WCHAR wine_casemap_upper[4570]
Definition: casemap.c:533
int vsnprintfW(WCHAR *str, size_t len, const WCHAR *format, va_list valist)
Definition: string.c:364
const union cptable * wine_cp_get_table(unsigned int codepage)
Definition: cptable.c:188
int wine_get_sortkey(int flags, const WCHAR *src, int srclen, char *dst, int dstlen)
Definition: sortkey.c:33
unsigned long int strtoulW(const WCHAR *nptr, WCHAR **endptr, int base)
Definition: string.c:196
#define C1_XDIGIT
Definition: unicode.h:38
long int strtolW(const WCHAR *nptr, WCHAR **endptr, int base)
Definition: string.c:75
WINE_UNICODE_INLINE int islowerW(WCHAR wc)
Definition: unicode.h:180
int wine_cp_wcstombs(const union cptable *table, int flags, const WCHAR *src, int srclen, char *dst, int dstlen, const char *defchar, int *used)
Definition: wctomb.c:411
#define C1_CNTRL
Definition: unicode.h:36
WINE_UNICODE_INLINE WCHAR * strlwrW(WCHAR *str)
Definition: unicode.h:281
#define WINE_UNICODE_API
Definition: unicode.h:58
const unsigned short * uni2cp_low
Definition: unicode.h:89
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
int strcmpiW(const WCHAR *str1, const WCHAR *str2)
Definition: string.c:33
WCHAR def_char
Definition: unicode.h:70
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
WINE_UNICODE_INLINE int isspaceW(WCHAR wc)
Definition: unicode.h:165
#define C1_BLANK
Definition: unicode.h:37
const unsigned short * uni2cp_high
Definition: unicode.h:90
const WCHAR wine_casemap_lower[4013]
Definition: casemap.c:7
GLdouble n
Definition: glext.h:7729
const WCHAR * cp2uni
Definition: unicode.h:87
int snprintfW(WCHAR *str, size_t len, const WCHAR *format,...)
Definition: string.c:517
WCHAR def_unicode_char
Definition: unicode.h:71
WINE_UNICODE_INLINE size_t strcspnW(const WCHAR *str, const WCHAR *reject)
Definition: unicode.h:274
GLuint GLuint end
Definition: gl.h:1545
int wine_utf8_mbstowcs(int flags, const char *src, int srclen, WCHAR *dst, int dstlen)
Definition: utf8.c:304
int vsprintfW(WCHAR *str, const WCHAR *format, va_list valist)
Definition: string.c:512
unsigned int codepage
Definition: unicode.h:68
WINE_UNICODE_INLINE int isprintW(WCHAR wc)
Definition: unicode.h:205
unsigned char lead_bytes[12]
Definition: unicode.h:91
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
WINE_UNICODE_INLINE int strncmpW(const WCHAR *str1, const WCHAR *str2, int n)
Definition: unicode.h:235
#define C1_LOWER
Definition: unicode.h:32
uint32_t ULONG_PTR
Definition: typedefs.h:63
WINE_UNICODE_INLINE int ispunctW(WCHAR wc)
Definition: unicode.h:160
int wine_compare_string(int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2)
Definition: sortkey.c:358
WINE_UNICODE_INLINE size_t strspnW(const WCHAR *str, const WCHAR *accept)
Definition: unicode.h:267
static PVOID ptr
Definition: dispmode.c:27
int codepage
Definition: win_iconv.c:156
const WCHAR * cp2uni_glyphs
Definition: unicode.h:79
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
unsigned int char_size
Definition: unicode.h:69
char * va_list
Definition: acmsvcex.h:78
WINE_UNICODE_INLINE long int atolW(const WCHAR *str)
Definition: unicode.h:310
GLuint index
Definition: glext.h:6031
const char * name
Definition: unicode.h:72
const unsigned short wine_wctype_table[]
Definition: wctype.c:6
const unsigned char * uni2cp_low
Definition: unicode.h:80
WINE_UNICODE_INLINE WCHAR toupperW(WCHAR ch)
Definition: unicode.h:141
c used
Definition: write.c:2885
#define C1_ALPHA
Definition: unicode.h:39
const unsigned short * uni2cp_high
Definition: unicode.h:81
__wchar_t WCHAR
Definition: xmlstorage.h:180
int wine_fold_string(int flags, const WCHAR *src, int srclen, WCHAR *dst, int dstlen)
Definition: fold.c:118
WINE_UNICODE_INLINE WCHAR * strpbrkW(const WCHAR *str, const WCHAR *accept)
Definition: unicode.h:261
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:51
#define C1_DIGIT
Definition: unicode.h:33
WCHAR * strstrW(const WCHAR *str, const WCHAR *sub)
Definition: string.c:60
#define WINE_UNICODE_INLINE
Definition: unicode.h:62
WINE_UNICODE_INLINE WCHAR tolowerW(WCHAR ch)
Definition: unicode.h:135
WINE_UNICODE_INLINE unsigned short get_char_typeW(WCHAR ch)
Definition: unicode.h:149
GLbitfield flags
Definition: glext.h:7161
WINE_UNICODE_INLINE int isxdigitW(WCHAR wc)
Definition: unicode.h:175
int ret
#define C1_PUNCT
Definition: unicode.h:35
int memicmpW(const WCHAR *str1, const WCHAR *str2, int n)
Definition: string.c:52
#define C1_UPPER
Definition: unicode.h:31
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
GLenum src
Definition: glext.h:6340
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
WINE_UNICODE_INLINE int isalnumW(WCHAR wc)
Definition: unicode.h:190
WINE_UNICODE_INLINE WCHAR * memrchrW(const WCHAR *ptr, WCHAR ch, size_t n)
Definition: unicode.h:302
WINE_UNICODE_INLINE int isupperW(WCHAR wc)
Definition: unicode.h:185
WINE_UNICODE_INLINE WCHAR * strrchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:254
int wine_cp_mbstowcs(const union cptable *table, int flags, const char *src, int srclen, WCHAR *dst, int dstlen)
Definition: mbtowc.c:247
int wine_cpsymbol_mbstowcs(const char *src, int srclen, WCHAR *dst, int dstlen)
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
static DWORD dstlen
Definition: directory.c:51
WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte(const union cptable *table, unsigned char ch)
Definition: unicode.h:130
int wine_cpsymbol_wcstombs(const WCHAR *src, int srclen, char *dst, int dstlen)
const unsigned char * cp2uni_leadbytes
Definition: unicode.h:88
GLenum GLenum dst
Definition: glext.h:6340
WINE_UNICODE_INLINE WCHAR * strcatW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:242
WINE_UNICODE_INLINE int isdigitW(WCHAR wc)
Definition: unicode.h:170
int strncmpiW(const WCHAR *str1, const WCHAR *str2, int n)
Definition: string.c:44
WINE_UNICODE_INLINE int strcmpW(const WCHAR *str1, const WCHAR *str2)
Definition: unicode.h:229
WINE_UNICODE_INLINE int iscntrlW(WCHAR wc)
Definition: unicode.h:155
const WCHAR * cp2uni
Definition: unicode.h:78
#define ULONG_PTR
Definition: config.h:101
#define C1_SPACE
Definition: unicode.h:34
static __ms_va_list valist
Definition: printf.c:59
WINE_UNICODE_INLINE int isalphaW(WCHAR wc)
Definition: unicode.h:195
GLfloat GLfloat p
Definition: glext.h:8902
WINE_UNICODE_INLINE WCHAR * memchrW(const WCHAR *ptr, WCHAR ch, size_t n)
Definition: unicode.h:295
int wine_utf8_wcstombs(int flags, const WCHAR *src, int srclen, char *dst, int dstlen)
Definition: utf8.c:98
WINE_UNICODE_INLINE int isgraphW(WCHAR wc)
Definition: unicode.h:200
struct sbcs_table sbcs
Definition: unicode.h:97
struct dbcs_table dbcs
Definition: unicode.h:98
int sprintfW(WCHAR *str, const WCHAR *format,...)
Definition: string.c:527
const union cptable * wine_cp_enum_table(unsigned int index)
Definition: cptable.c:199
WINE_UNICODE_INLINE int atoiW(const WCHAR *str)
Definition: unicode.h:315
WINE_UNICODE_INLINE WCHAR * struprW(WCHAR *str)
Definition: unicode.h:288