2 * Wine internal Unicode definitions
4 * Copyright 2000 Alexandre Julliard
7 #ifndef __WINE_UNICODE_H
8 #define __WINE_UNICODE_H
12 /* code page info common to SBCS and DBCS */
15 unsigned int codepage
; /* codepage id */
16 unsigned int char_size
; /* char size (1 or 2 bytes) */
17 WCHAR def_char
; /* default char value (can be double-byte) */
18 WCHAR def_unicode_char
; /* default Unicode char value */
19 const char *name
; /* code page name */
25 const WCHAR
*cp2uni
; /* code page -> Unicode map */
26 const unsigned char *uni2cp_low
; /* Unicode -> code page map */
27 const unsigned short *uni2cp_high
;
33 const WCHAR
*cp2uni
; /* code page -> Unicode map */
34 const unsigned char *cp2uni_leadbytes
;
35 const unsigned short *uni2cp_low
; /* Unicode -> code page map */
36 const unsigned short *uni2cp_high
;
37 unsigned char lead_bytes
[12]; /* lead bytes ranges */
43 struct sbcs_table sbcs
;
44 struct dbcs_table dbcs
;
47 extern const union cptable
*cp_get_table( unsigned int codepage
);
48 extern const union cptable
*cp_enum_table( unsigned int index
);
50 extern int cp_mbstowcs( const union cptable
*table
, int flags
,
51 const char *src
, int srclen
,
52 WCHAR
*dst
, int dstlen
);
53 extern int cp_wcstombs( const union cptable
*table
, int flags
,
54 const WCHAR
*src
, int srclen
,
55 char *dst
, int dstlen
, const char *defchar
, int *used
);
56 extern int utf8_wcstombs( const WCHAR
*src
, int srclen
, char *dst
, int dstlen
);
57 extern int utf8_mbstowcs( int flags
, const char *src
, int srclen
, WCHAR
*dst
, int dstlen
);
59 static inline int is_dbcs_leadbyte( const union cptable
*table
, unsigned char ch
)
61 return (table
->info
.char_size
== 2) && (table
->dbcs
.cp2uni_leadbytes
[ch
]);
64 static inline WCHAR
tolowerW( WCHAR ch
)
66 extern const WCHAR casemap_lower
[];
67 return ch
+ casemap_lower
[casemap_lower
[ch
>> 8] + (ch
& 0xff)];
70 static inline WCHAR
toupperW( WCHAR ch
)
72 extern const WCHAR casemap_upper
[];
73 return ch
+ casemap_upper
[casemap_upper
[ch
>> 8] + (ch
& 0xff)];
76 /* the character type contains the C1_* flags in the low 12 bits */
77 /* and the C2_* type in the high 4 bits */
78 static inline unsigned short get_char_typeW( WCHAR ch
)
80 extern const unsigned short wctype_table
[];
81 return wctype_table
[wctype_table
[ch
>> 8] + (ch
& 0xff)];
84 /* some useful string manipulation routines */
86 static inline unsigned int strlenW( const WCHAR
*str
)
88 #if defined(__i386__) && defined(__GNUC__)
90 __asm__
__volatile__( "cld\n\t"
94 : "=c" (res
), "=&D" (dummy
)
95 : "0" (0xffffffff), "1" (str
), "a" (0) );
104 static inline WCHAR
*strcpyW( WCHAR
*dst
, const WCHAR
*src
)
106 #if defined(__i386__) && defined(__GNUC__)
107 int dummy1
, dummy2
, dummy3
;
108 __asm__
__volatile__( "cld\n"
111 "testw %%ax,%%ax\n\t"
113 : "=&S" (dummy1
), "=&D" (dummy2
), "=&a" (dummy3
)
114 : "0" (src
), "1" (dst
)
118 while ((*p
++ = *src
++));
123 static inline int strcmpW( const WCHAR
*str1
, const WCHAR
*str2
)
125 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
126 return *str1
- *str2
;
129 static inline int strncmpW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
131 if (n
<= 0) return 0;
132 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
133 return *str1
- *str2
;
136 static inline WCHAR
*strncpyW( WCHAR
*str1
, const WCHAR
*str2
, int n
)
139 while (n
-- > 0) if (!(*str1
++ = *str2
++)) break;
140 while (n
-- > 0) *str1
++ = 0;
144 static inline WCHAR
*strcatW( WCHAR
*dst
, const WCHAR
*src
)
146 strcpyW( dst
+ strlenW(dst
), src
);
150 static inline WCHAR
*strchrW( const WCHAR
*str
, WCHAR ch
)
152 for ( ; *str
; str
++) if (*str
== ch
) return (WCHAR
*)str
;
156 static inline WCHAR
*strrchrW( const WCHAR
*str
, WCHAR ch
)
159 for ( ; *str
; str
++) if (*str
== ch
) ret
= (WCHAR
*)str
;
163 static inline WCHAR
*strlwrW( WCHAR
*str
)
166 while ((*str
= tolowerW(*str
))) str
++;
170 static inline WCHAR
*struprW( WCHAR
*str
)
173 while ((*str
= toupperW(*str
))) str
++;
177 extern int strcmpiW( const WCHAR
*str1
, const WCHAR
*str2
);
178 extern int strncmpiW( const WCHAR
*str1
, const WCHAR
*str2
, int n
);
179 extern WCHAR
*strstrW( const WCHAR
*str
, const WCHAR
*sub
);
181 #endif /* __WINE_UNICODE_H */