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

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

* empty log message *

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