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

Last change on this file since 5604 was 5604, 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 *p = 0;
114#endif
115 return dst;
116}
117
118static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 )
119{
120 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
121 return *str1 - *str2;
122}
123
124static inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
125{
126 if (n <= 0) return 0;
127 while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
128 return *str1 - *str2;
129}
130
131static inline WCHAR *strncpyW( WCHAR *str1, const WCHAR *str2, int n )
132{
133 WCHAR *ret = str1;
134 while (n-- > 0) if (!(*str1++ = *str2++)) break;
135 while (n-- > 0) *str1++ = 0;
136 return ret;
137}
138
139static inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
140{
141 strcpyW( dst + strlenW(dst), src );
142 return dst;
143}
144
145static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch )
146{
147 for ( ; *str; str++) if (*str == ch) return (WCHAR *)str;
148 return NULL;
149}
150
151static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
152{
153 WCHAR *ret = NULL;
154 for ( ; *str; str++) if (*str == ch) ret = (WCHAR *)str;
155 return ret;
156}
157
158static inline WCHAR *strlwrW( WCHAR *str )
159{
160 WCHAR *ret = str;
161 while(*str) {
162 *str = tolowerW(*str);
163 str++;
164 }
165 return ret;
166}
167
168static inline WCHAR *struprW( WCHAR *str )
169{
170 WCHAR *ret = str;
171 while(*str) {
172 *str = toupperW(*str);
173 str++;
174 }
175 return ret;
176}
177
178extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
179extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
180extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
181extern unsigned short get_char_typeW( WCHAR ch );
182
183#endif //RC_INVOKED
184
185#endif /* __WINE_UNICODE_H */
Note: See TracBrowser for help on using the repository browser.