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