2 * Wine internal Unicode definitions
4 * Copyright 2000 Alexandre Julliard
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.
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.
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
21 #ifndef __WINE_WINE_UNICODE_H
22 #define __WINE_WINE_UNICODE_H
29 // Definitions copied from <winnls.h>
30 // We only want to include host headers, so we define them manually
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
49 #ifdef __WINE_WINE_TEST_H
50 #error This file should not be used in Wine tests
57 #ifndef WINE_UNICODE_API
58 #define WINE_UNICODE_API
61 #ifndef WINE_UNICODE_INLINE
62 #define WINE_UNICODE_INLINE static inline
65 /* code page info common to SBCS and DBCS */
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 */
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
;
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 */
97 struct sbcs_table sbcs
;
98 struct dbcs_table dbcs
;
101 extern const union cptable
*wine_cp_get_table( unsigned int codepage
);
102 extern const union cptable
*wine_cp_enum_table( unsigned int index
);
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
);
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
);
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
);
130 WINE_UNICODE_INLINE
int wine_is_dbcs_leadbyte( const union cptable
*table
, unsigned char ch
)
132 return (table
->info
.char_size
== 2) && (table
->dbcs
.cp2uni_leadbytes
[ch
]);
135 WINE_UNICODE_INLINE WCHAR
tolowerW( WCHAR ch
)
137 extern WINE_UNICODE_API
const WCHAR wine_casemap_lower
[];
138 return ch
+ wine_casemap_lower
[wine_casemap_lower
[ch
>> 8] + (ch
& 0xff)];
141 WINE_UNICODE_INLINE WCHAR
toupperW( WCHAR ch
)
143 extern WINE_UNICODE_API
const WCHAR wine_casemap_upper
[];
144 return ch
+ wine_casemap_upper
[wine_casemap_upper
[ch
>> 8] + (ch
& 0xff)];
147 /* the character type contains the C1_* flags in the low 12 bits */
148 /* and the C2_* type in the high 4 bits */
149 WINE_UNICODE_INLINE
unsigned short get_char_typeW( WCHAR ch
)
151 extern WINE_UNICODE_API
const unsigned short wine_wctype_table
[];
152 return wine_wctype_table
[wine_wctype_table
[ch
>> 8] + (ch
& 0xff)];
155 WINE_UNICODE_INLINE
int iscntrlW( WCHAR wc
)
157 return get_char_typeW(wc
) & C1_CNTRL
;
160 WINE_UNICODE_INLINE
int ispunctW( WCHAR wc
)
162 return get_char_typeW(wc
) & C1_PUNCT
;
165 WINE_UNICODE_INLINE
int isspaceW( WCHAR wc
)
167 return get_char_typeW(wc
) & C1_SPACE
;
170 WINE_UNICODE_INLINE
int isdigitW( WCHAR wc
)
172 return get_char_typeW(wc
) & C1_DIGIT
;
175 WINE_UNICODE_INLINE
int isxdigitW( WCHAR wc
)
177 return get_char_typeW(wc
) & C1_XDIGIT
;
180 WINE_UNICODE_INLINE
int islowerW( WCHAR wc
)
182 return get_char_typeW(wc
) & C1_LOWER
;
185 WINE_UNICODE_INLINE
int isupperW( WCHAR wc
)
187 return get_char_typeW(wc
) & C1_UPPER
;
190 WINE_UNICODE_INLINE
int isalnumW( WCHAR wc
)
192 return get_char_typeW(wc
) & (C1_ALPHA
|C1_DIGIT
|C1_LOWER
|C1_UPPER
);
195 WINE_UNICODE_INLINE
int isalphaW( WCHAR wc
)
197 return get_char_typeW(wc
) & (C1_ALPHA
|C1_LOWER
|C1_UPPER
);
200 WINE_UNICODE_INLINE
int isgraphW( WCHAR wc
)
202 return get_char_typeW(wc
) & (C1_ALPHA
|C1_PUNCT
|C1_DIGIT
|C1_LOWER
|C1_UPPER
);
205 WINE_UNICODE_INLINE
int isprintW( WCHAR wc
)
207 return get_char_typeW(wc
) & (C1_ALPHA
|C1_BLANK
|C1_PUNCT
|C1_DIGIT
|C1_LOWER
|C1_UPPER
);
210 /* some useful string manipulation routines */
212 WINE_UNICODE_INLINE
unsigned int strlenW( const WCHAR
*str
)
214 const WCHAR
*s
= str
;
216 return (unsigned int)(s
- str
);
219 WINE_UNICODE_INLINE WCHAR
*strcpyW( WCHAR
*dst
, const WCHAR
*src
)
222 while ((*p
++ = *src
++));
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
229 WINE_UNICODE_INLINE
int strcmpW( const WCHAR
*str1
, const WCHAR
*str2
)
231 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
232 return *str1
- *str2
;
235 WINE_UNICODE_INLINE
int strncmpW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
237 if (n
<= 0) return 0;
238 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
239 return *str1
- *str2
;
242 WINE_UNICODE_INLINE WCHAR
*strcatW( WCHAR
*dst
, const WCHAR
*src
)
244 strcpyW( dst
+ strlenW(dst
), src
);
248 WINE_UNICODE_INLINE WCHAR
*strchrW( const WCHAR
*str
, WCHAR ch
)
250 do { if (*str
== ch
) return (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
254 WINE_UNICODE_INLINE WCHAR
*strrchrW( const WCHAR
*str
, WCHAR ch
)
257 do { if (*str
== ch
) ret
= (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
261 WINE_UNICODE_INLINE WCHAR
*strpbrkW( const WCHAR
*str
, const WCHAR
*accept
)
263 for ( ; *str
; str
++) if (strchrW( accept
, *str
)) return (WCHAR
*)(ULONG_PTR
)str
;
267 WINE_UNICODE_INLINE
size_t strspnW( const WCHAR
*str
, const WCHAR
*accept
)
270 for (ptr
= str
; *ptr
; ptr
++) if (!strchrW( accept
, *ptr
)) break;
274 WINE_UNICODE_INLINE
size_t strcspnW( const WCHAR
*str
, const WCHAR
*reject
)
277 for (ptr
= str
; *ptr
; ptr
++) if (strchrW( reject
, *ptr
)) break;
281 WINE_UNICODE_INLINE WCHAR
*strlwrW( WCHAR
*str
)
284 while ((*str
= tolowerW(*str
))) str
++;
288 WINE_UNICODE_INLINE WCHAR
*struprW( WCHAR
*str
)
291 while ((*str
= toupperW(*str
))) str
++;
295 WINE_UNICODE_INLINE WCHAR
*memchrW( const WCHAR
*ptr
, WCHAR ch
, size_t n
)
298 for (end
= ptr
+ n
; ptr
< end
; ptr
++) if (*ptr
== ch
) return (WCHAR
*)(ULONG_PTR
)ptr
;
302 WINE_UNICODE_INLINE WCHAR
*memrchrW( const WCHAR
*ptr
, WCHAR ch
, size_t n
)
306 for (end
= ptr
+ n
; ptr
< end
; ptr
++) if (*ptr
== ch
) ret
= (WCHAR
*)(ULONG_PTR
)ptr
;
310 WINE_UNICODE_INLINE
long int atolW( const WCHAR
*str
)
312 return strtolW( str
, (WCHAR
**)0, 10 );
315 WINE_UNICODE_INLINE
int atoiW( const WCHAR
*str
)
317 return (int)atolW( str
);
320 #undef WINE_UNICODE_INLINE
326 #endif /* __WINE_WINE_UNICODE_H */