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

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