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

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

header updates

File size: 5.8 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
96#define islowerW(a) IsCharLowerW(a)
97#define isupperW(a) IsCharUpperW(a)
98#define isalnumW(a) IsCharAlphaNumericW(a)
99#define isalphaW(a) IsCharAlphaW(a)
100
101
102/* some useful string manipulation routines */
103
104static inline unsigned int strlenW( const WCHAR *str )
105{
106#if defined(__i386__) && defined(__GNUC__)
107 int dummy, res;
108 __asm__ __volatile__( "cld\n\t"
109 "repnz\n\t"
110 "scasw\n\t"
111 "notl %0"
112 : "=c" (res), "=&D" (dummy)
113 : "0" (0xffffffff), "1" (str), "a" (0) );
114 return res - 1;
115#else
116 const WCHAR *s = str;
117 while (*s) s++;
118 return s - str;
119#endif
120}
121
122static inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
123{
124#if defined(__i386__) && defined(__GNUC__)
125 int dummy1, dummy2, dummy3;
126 __asm__ __volatile__( "cld\n"
127 "1:\tlodsw\n\t"
128 "stosw\n\t"
129 "testw %%ax,%%ax\n\t"
130 "jne 1b"
131 : "=&S" (dummy1), "=&D" (dummy2), "=&a" (dummy3)
132 : "0" (src), "1" (dst)
133 : "memory" );
134#else
135 WCHAR *p = dst;
136 while(*src) {
137 *p++ = *src++;
138 }
139 *p = 0;
140#endif
141 return dst;
142}
143
144static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
145{
146 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
147 return *str1 - *str2;
148}
149
150static inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
151{
152 if (n <= 0) return 0;
153 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
154 return *str1 - *str2;
155}
156
157static inline WCHAR *strncpyW( WCHAR *str1, const WCHAR *str2, int n )
158{
159 WCHAR *ret = str1;
160 #ifdef __WATCOMC__ /* kso: it's so noisy and I don't find the right pragma... */
161 while (n-- > 0) if ((*str1++ = *str2++) != 0) break;
162 #else
163 while (n-- > 0) if (!(*str1++ = *str2++)) break;
164 #endif
165 while (n-- > 0) *str1++ = 0;
166 return ret;
167}
168
169static inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
170{
171 strcpyW( dst + strlenW(dst), src );
172 return dst;
173}
174
175static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
176{
177 for ( ; *str; str++) if (*str == ch) return (WCHAR *)str;
178 return NULL;
179}
180
181static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
182{
183 WCHAR *ret = NULL;
184 for ( ; *str; str++) if (*str == ch) ret = (WCHAR *)str;
185 return ret;
186}
187
188static inline WCHAR *strlwrW( WCHAR *str )
189{
190 WCHAR *ret = str;
191 while(*str) {
192 *str = tolowerW(*str);
193 str++;
194 }
195 return ret;
196}
197
198static inline WCHAR *struprW( WCHAR *str )
199{
200 WCHAR *ret = str;
201 while(*str) {
202 *str = toupperW(*str);
203 str++;
204 }
205 return ret;
206}
207
208extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
209extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
210extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
211
212
213#if defined(__IBMC__) || defined(__IBMCPP__) || defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__)
214#undef static
215#endif
216
217#ifdef __cplusplus
218}
219#endif
220
221#endif //RC_INVOKED
222
223#endif /* __WINE_UNICODE_H */
Note: See TracBrowser for help on using the repository browser.