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

Last change on this file since 5453 was 5453, 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#include "windef.h"
11#ifndef USE_INLINE_UNICODEFUNCS
12#include <heapstring.h>
13#endif
14
15#ifndef __cplusplus
16#undef inline
17#define inline
18#endif
19
20/* code page info common to SBCS and DBCS */
21struct cp_info
22{
23 unsigned int codepage; /* codepage id */
24 unsigned int char_size; /* char size (1 or 2 bytes) */
25 WCHAR def_char; /* default char value (can be double-byte) */
26 WCHAR def_unicode_char; /* default Unicode char value */
27 const char *name; /* code page name */
28};
29
30struct sbcs_table
31{
32 struct cp_info info;
33 const WCHAR *cp2uni; /* code page -> Unicode map */
34 const unsigned char *uni2cp_low; /* Unicode -> code page map */
35 const unsigned short *uni2cp_high;
36};
37
38struct dbcs_table
39{
40 struct cp_info info;
41 const WCHAR *cp2uni; /* code page -> Unicode map */
42 const unsigned char *cp2uni_leadbytes;
43 const unsigned short *uni2cp_low; /* Unicode -> code page map */
44 const unsigned short *uni2cp_high;
45 unsigned char lead_bytes[12]; /* lead bytes ranges */
46};
47
48union cptable
49{
50 struct cp_info info;
51 struct sbcs_table sbcs;
52 struct dbcs_table dbcs;
53};
54
55extern const union cptable *cp_get_table( unsigned int codepage );
56extern const union cptable *cp_enum_table( unsigned int index );
57
58extern int cp_mbstowcs( const union cptable *table, int flags,
59 const char *src, int srclen,
60 WCHAR *dst, int dstlen );
61extern int cp_wcstombs( const union cptable *table, int flags,
62 const WCHAR *src, int srclen,
63 char *dst, int dstlen, const char *defchar, int *used );
64extern int utf8_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
65extern int utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
66
67static inline int is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
68{
69 return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
70}
71
72#ifdef USE_INLINE_UNICODEFUNCS
73static inline WCHAR tolowerW( WCHAR ch )
74{
75 extern const WCHAR casemap_lower[];
76 return ch + casemap_lower[casemap_lower[ch >> 8] + (ch & 0xff)];
77}
78
79static inline WCHAR toupperW( WCHAR ch )
80{
81 extern const WCHAR casemap_upper[];
82 return ch + casemap_upper[casemap_upper[ch >> 8] + (ch & 0xff)];
83}
84#endif
85
86/* the character type contains the C1_* flags in the low 12 bits */
87/* and the C2_* type in the high 4 bits */
88static inline unsigned short get_char_typeW( WCHAR ch )
89{
90 extern const unsigned short wctype_table[];
91 return wctype_table[wctype_table[ch >> 8] + (ch & 0xff)];
92}
93
94/* some useful string manipulation routines */
95
96#ifdef USE_INLINE_UNICODEFUNCS
97static inline unsigned int strlenW( const WCHAR *str )
98{
99#if defined(__i386__) && defined(__GNUC__)
100 int dummy, res;
101 __asm__ __volatile__( "cld\n\t"
102 "repnz\n\t"
103 "scasw\n\t"
104 "notl %0"
105 : "=c" (res), "=&D" (dummy)
106 : "0" (0xffffffff), "1" (str), "a" (0) );
107 return res - 1;
108#else
109 const WCHAR *s = str;
110 while (*s) s++;
111 return s - str;
112#endif
113}
114
115static inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
116{
117#if defined(__i386__) && defined(__GNUC__)
118 int dummy1, dummy2, dummy3;
119 __asm__ __volatile__( "cld\n"
120 "1:\tlodsw\n\t"
121 "stosw\n\t"
122 "testw %%ax,%%ax\n\t"
123 "jne 1b"
124 : "=&S" (dummy1), "=&D" (dummy2), "=&a" (dummy3)
125 : "0" (src), "1" (dst)
126 : "memory" );
127#else
128 WCHAR *p = dst;
129 while ((*p++ = *src++));
130#endif
131 return dst;
132}
133
134static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
135{
136 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
137 return *str1 - *str2;
138}
139
140static inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
141{
142 if (n <= 0) return 0;
143 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
144 return *str1 - *str2;
145}
146
147static inline WCHAR *strncpyW( WCHAR *str1, const WCHAR *str2, int n )
148{
149 WCHAR *ret = str1;
150 while (n-- > 0) if (!(*str1++ = *str2++)) break;
151 while (n-- > 0) *str1++ = 0;
152 return ret;
153}
154
155static inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
156{
157 strcpyW( dst + strlenW(dst), src );
158 return dst;
159}
160
161static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
162{
163 for ( ; *str; str++) if (*str == ch) return (WCHAR *)str;
164 return NULL;
165}
166
167static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
168{
169 WCHAR *ret = NULL;
170 for ( ; *str; str++) if (*str == ch) ret = (WCHAR *)str;
171 return ret;
172}
173
174static inline WCHAR *strlwrW( WCHAR *str )
175{
176 WCHAR *ret = str;
177 while ((*str = tolowerW(*str))) str++;
178 return ret;
179}
180
181static inline WCHAR *struprW( WCHAR *str )
182{
183 WCHAR *ret = str;
184 while ((*str = toupperW(*str))) str++;
185 return ret;
186}
187#endif
188
189extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
190extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
191extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
192
193#endif /* __WINE_UNICODE_H */
Note: See TracBrowser for help on using the repository browser.