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

Last change on this file since 5456 was 5456, checked in by sandervl, 24 years ago

header updates

File size: 5.4 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 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 */
20struct 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
29struct 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
37struct 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
47union cptable
48{
49 struct cp_info info;
50 struct sbcs_table sbcs;
51 struct dbcs_table dbcs;
52};
53
54extern const union cptable *cp_get_table( unsigned int codepage );
55extern const union cptable *cp_enum_table( unsigned int index );
56
57extern int cp_mbstowcs( const union cptable *table, int flags,
58 const char *src, int srclen,
59 WCHAR *dst, int dstlen );
60extern 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 );
63extern int utf8_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
64extern int utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
65
66static inline int is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
67{
68 return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
69}
70
71static inline WCHAR tolowerW( WCHAR ch )
72{
73 extern const WCHAR casemap_lower[];
74 return ch + casemap_lower[casemap_lower[ch >> 8] + (ch & 0xff)];
75}
76
77static inline WCHAR toupperW( WCHAR ch )
78{
79 extern const WCHAR casemap_upper[];
80 return ch + casemap_upper[casemap_upper[ch >> 8] + (ch & 0xff)];
81}
82
83/* the character type contains the C1_* flags in the low 12 bits */
84/* and the C2_* type in the high 4 bits */
85static inline unsigned short get_char_typeW( WCHAR ch )
86{
87 extern const unsigned short wctype_table[];
88 return wctype_table[wctype_table[ch >> 8] + (ch & 0xff)];
89}
90
91/* some useful string manipulation routines */
92
93static inline unsigned int strlenW( const WCHAR *str )
94{
95#if defined(__i386__) && defined(__GNUC__)
96 int dummy, res;
97 __asm__ __volatile__( "cld\n\t"
98 "repnz\n\t"
99 "scasw\n\t"
100 "notl %0"
101 : "=c" (res), "=&D" (dummy)
102 : "0" (0xffffffff), "1" (str), "a" (0) );
103 return res - 1;
104#else
105 const WCHAR *s = str;
106 while (*s) s++;
107 return s - str;
108#endif
109}
110
111static inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
112{
113#if defined(__i386__) && defined(__GNUC__)
114 int dummy1, dummy2, dummy3;
115 __asm__ __volatile__( "cld\n"
116 "1:\tlodsw\n\t"
117 "stosw\n\t"
118 "testw %%ax,%%ax\n\t"
119 "jne 1b"
120 : "=&S" (dummy1), "=&D" (dummy2), "=&a" (dummy3)
121 : "0" (src), "1" (dst)
122 : "memory" );
123#else
124 WCHAR *p = dst;
125 while(*src) {
126 *p++ = *src++;
127 }
128#endif
129 return dst;
130}
131
132static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
133{
134 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
135 return *str1 - *str2;
136}
137
138static inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
139{
140 if (n <= 0) return 0;
141 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
142 return *str1 - *str2;
143}
144
145static inline WCHAR *strncpyW( WCHAR *str1, const WCHAR *str2, int n )
146{
147 WCHAR *ret = str1;
148 while (n-- > 0) if (!(*str1++ = *str2++)) break;
149 while (n-- > 0) *str1++ = 0;
150 return ret;
151}
152
153static inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
154{
155 strcpyW( dst + strlenW(dst), src );
156 return dst;
157}
158
159static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
160{
161 for ( ; *str; str++) if (*str == ch) return (WCHAR *)str;
162 return NULL;
163}
164
165static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
166{
167 WCHAR *ret = NULL;
168 for ( ; *str; str++) if (*str == ch) ret = (WCHAR *)str;
169 return ret;
170}
171
172static inline WCHAR *strlwrW( WCHAR *str )
173{
174 WCHAR *ret = str;
175 while(*str) {
176 *str = tolowerW(*str);
177 str++;
178 }
179 return ret;
180}
181
182static inline WCHAR *struprW( WCHAR *str )
183{
184 WCHAR *ret = str;
185 while(*str) {
186 *str = toupperW(*str);
187 str++;
188 }
189 return ret;
190}
191
192extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
193extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
194extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
195
196#endif /* __WINE_UNICODE_H */
Note: See TracBrowser for help on using the repository browser.