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

Last change on this file since 8420 was 8420, checked in by sandervl, 23 years ago

header updates

File size: 5.9 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#if !defined(OS2_INCLUDED) && !defined(__WIN32TYPE_H__)
13#include <windef.h>
14#endif
15#include <winnls.h>
16
17#ifndef strncasecmp
18#define strncasecmp lstrncmpiA
19#endif
20
21/* code page info common to SBCS and DBCS */
22struct cp_info
23{
24 unsigned int codepage; /* codepage id */
25 unsigned int char_size; /* char size (1 or 2 bytes) */
26 WCHAR def_char; /* default char value (can be double-byte) */
27 WCHAR def_unicode_char; /* default Unicode char value */
28 const char *name; /* code page name */
29};
30
31struct sbcs_table
32{
33 struct cp_info info;
34 const WCHAR *cp2uni; /* code page -> Unicode map */
35 const unsigned char *uni2cp_low; /* Unicode -> code page map */
36 const unsigned short *uni2cp_high;
37};
38
39struct dbcs_table
40{
41 struct cp_info info;
42 const WCHAR *cp2uni; /* code page -> Unicode map */
43 const unsigned char *cp2uni_leadbytes;
44 const unsigned short *uni2cp_low; /* Unicode -> code page map */
45 const unsigned short *uni2cp_high;
46 unsigned char lead_bytes[12]; /* lead bytes ranges */
47};
48
49union cptable
50{
51 struct cp_info info;
52 struct sbcs_table sbcs;
53 struct dbcs_table dbcs;
54};
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60#if defined(__IBMC__) || defined(__IBMCPP__) || defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
61#define static
62#endif
63
64extern const union cptable *cp_get_table( unsigned int codepage );
65extern const union cptable *cp_enum_table( unsigned int index );
66
67extern int cp_mbstowcs( const union cptable *table, int flags,
68 const char *src, int srclen,
69 WCHAR *dst, int dstlen );
70extern int cp_wcstombs( const union cptable *table, int flags,
71 const WCHAR *src, int srclen,
72 char *dst, int dstlen, const char *defchar, int *used );
73extern int utf8_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
74extern int utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
75
76extern WCHAR WINAPI tolowerW( WCHAR ch );
77extern WCHAR WINAPI toupperW( WCHAR ch );
78
79extern unsigned short get_char_typeW( WCHAR ch );
80
81static inline int is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
82{
83 return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
84}
85
86inline static int isdigitW( WCHAR wc )
87{
88 return get_char_typeW(wc) & C1_DIGIT;
89}
90
91inline static int isxdigitW( WCHAR wc )
92{
93 return get_char_typeW(wc) & C1_XDIGIT;
94}
95
96inline static int isspaceW( WCHAR wc )
97{
98 return get_char_typeW(wc) & C1_SPACE;
99}
100
101#define islowerW(a) IsCharLowerW(a)
102#define isupperW(a) IsCharUpperW(a)
103#define isalnumW(a) IsCharAlphaNumericW(a)
104#define isalphaW(a) IsCharAlphaW(a)
105
106
107/* some useful string manipulation routines */
108
109static inline unsigned int strlenW( const WCHAR *str )
110{
111#if defined(__i386__) && defined(__GNUC__)
112 int dummy, res;
113 __asm__ __volatile__( "cld\n\t"
114 "repnz\n\t"
115 "scasw\n\t"
116 "notl %0"
117 : "=c" (res), "=&D" (dummy)
118 : "0" (0xffffffff), "1" (str), "a" (0) );
119 return res - 1;
120#else
121 const WCHAR *s = str;
122 while (*s) s++;
123 return s - str;
124#endif
125}
126
127static inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
128{
129#if defined(__i386__) && defined(__GNUC__)
130 int dummy1, dummy2, dummy3;
131 __asm__ __volatile__( "cld\n"
132 "1:\tlodsw\n\t"
133 "stosw\n\t"
134 "testw %%ax,%%ax\n\t"
135 "jne 1b"
136 : "=&S" (dummy1), "=&D" (dummy2), "=&a" (dummy3)
137 : "0" (src), "1" (dst)
138 : "memory" );
139#else
140 WCHAR *p = dst;
141 while(*src) {
142 *p++ = *src++;
143 }
144 *p = 0;
145#endif
146 return dst;
147}
148
149static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
150{
151 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
152 return *str1 - *str2;
153}
154
155static inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
156{
157 if (n <= 0) return 0;
158 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
159 return *str1 - *str2;
160}
161
162static inline WCHAR *strncpyW( WCHAR *str1, const WCHAR *str2, int n )
163{
164 WCHAR *ret = str1;
165 #ifdef __WATCOMC__ /* kso: it's so noisy and I don't find the right pragma... */
166 while (n-- > 0) if ((*str1++ = *str2++) != 0) break;
167 #else
168 while (n-- > 0) if (!(*str1++ = *str2++)) break;
169 #endif
170 while (n-- > 0) *str1++ = 0;
171 return ret;
172}
173
174static inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
175{
176 strcpyW( dst + strlenW(dst), src );
177 return dst;
178}
179
180static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
181{
182 for ( ; *str; str++) if (*str == ch) return (WCHAR *)str;
183 return NULL;
184}
185
186static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
187{
188 WCHAR *ret = NULL;
189 for ( ; *str; str++) if (*str == ch) ret = (WCHAR *)str;
190 return ret;
191}
192
193static inline WCHAR *strlwrW( WCHAR *str )
194{
195 WCHAR *ret = str;
196 while(*str) {
197 *str = tolowerW(*str);
198 str++;
199 }
200 return ret;
201}
202
203static inline WCHAR *struprW( WCHAR *str )
204{
205 WCHAR *ret = str;
206 while(*str) {
207 *str = toupperW(*str);
208 str++;
209 }
210 return ret;
211}
212
213extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
214extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
215extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
216
217
218#if defined(__IBMC__) || defined(__IBMCPP__) || defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
219#undef static
220#endif
221
222#ifdef __cplusplus
223}
224#endif
225
226#endif //RC_INVOKED
227
228#endif /* __WINE_UNICODE_H */
Note: See TracBrowser for help on using the repository browser.