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