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

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

header updates

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