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

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

header updates

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