| 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 | #include <winnls.h> | 
|---|
| 16 |  | 
|---|
| 17 | #ifndef strncasecmp | 
|---|
| 18 | #define strncasecmp     lstrncmpiA | 
|---|
| 19 | #endif | 
|---|
| 20 | #ifndef strcasecmp | 
|---|
| 21 | #define strcasecmp      lstrcmpiA | 
|---|
| 22 | #endif | 
|---|
| 23 |  | 
|---|
| 24 | /* code page info common to SBCS and DBCS */ | 
|---|
| 25 | struct cp_info | 
|---|
| 26 | { | 
|---|
| 27 | unsigned int          codepage;          /* codepage id */ | 
|---|
| 28 | unsigned int          char_size;         /* char size (1 or 2 bytes) */ | 
|---|
| 29 | WCHAR                 def_char;          /* default char value (can be double-byte) */ | 
|---|
| 30 | WCHAR                 def_unicode_char;  /* default Unicode char value */ | 
|---|
| 31 | const char           *name;              /* code page name */ | 
|---|
| 32 | }; | 
|---|
| 33 |  | 
|---|
| 34 | struct sbcs_table | 
|---|
| 35 | { | 
|---|
| 36 | struct cp_info        info; | 
|---|
| 37 | const WCHAR          *cp2uni;            /* code page -> Unicode map */ | 
|---|
| 38 | const unsigned char  *uni2cp_low;        /* Unicode -> code page map */ | 
|---|
| 39 | const unsigned short *uni2cp_high; | 
|---|
| 40 | }; | 
|---|
| 41 |  | 
|---|
| 42 | struct dbcs_table | 
|---|
| 43 | { | 
|---|
| 44 | struct cp_info        info; | 
|---|
| 45 | const WCHAR          *cp2uni;            /* code page -> Unicode map */ | 
|---|
| 46 | const unsigned char  *cp2uni_leadbytes; | 
|---|
| 47 | const unsigned short *uni2cp_low;        /* Unicode -> code page map */ | 
|---|
| 48 | const unsigned short *uni2cp_high; | 
|---|
| 49 | unsigned char         lead_bytes[12];    /* lead bytes ranges */ | 
|---|
| 50 | }; | 
|---|
| 51 |  | 
|---|
| 52 | union cptable | 
|---|
| 53 | { | 
|---|
| 54 | struct cp_info    info; | 
|---|
| 55 | struct sbcs_table sbcs; | 
|---|
| 56 | struct dbcs_table dbcs; | 
|---|
| 57 | }; | 
|---|
| 58 |  | 
|---|
| 59 | #ifdef __cplusplus | 
|---|
| 60 | extern "C" { | 
|---|
| 61 | #endif | 
|---|
| 62 |  | 
|---|
| 63 | #if defined(__IBMC__) || defined(__IBMCPP__) || defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__) | 
|---|
| 64 | #define static | 
|---|
| 65 | #endif | 
|---|
| 66 |  | 
|---|
| 67 | extern const union cptable *cp_get_table( unsigned int codepage ); | 
|---|
| 68 | extern const union cptable *cp_enum_table( unsigned int index ); | 
|---|
| 69 |  | 
|---|
| 70 | extern int cp_mbstowcs( const union cptable *table, int flags, | 
|---|
| 71 | const char *src, int srclen, | 
|---|
| 72 | WCHAR *dst, int dstlen ); | 
|---|
| 73 | extern int cp_wcstombs( const union cptable *table, int flags, | 
|---|
| 74 | const WCHAR *src, int srclen, | 
|---|
| 75 | char *dst, int dstlen, const char *defchar, int *used ); | 
|---|
| 76 | extern int utf8_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen ); | 
|---|
| 77 | extern int utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen ); | 
|---|
| 78 |  | 
|---|
| 79 | extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 ); | 
|---|
| 80 | extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n ); | 
|---|
| 81 | extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub ); | 
|---|
| 82 | extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base ); | 
|---|
| 83 | extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base ); | 
|---|
| 84 |  | 
|---|
| 85 | static inline int is_dbcs_leadbyte( const union cptable *table, unsigned char ch ) | 
|---|
| 86 | { | 
|---|
| 87 | return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]); | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | static inline WCHAR tolowerW( WCHAR ch ) | 
|---|
| 91 | { | 
|---|
| 92 | extern const WCHAR casemap_lower[]; | 
|---|
| 93 | return ch + casemap_lower[casemap_lower[ch >> 8] + (ch & 0xff)]; | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | static inline WCHAR toupperW( WCHAR ch ) | 
|---|
| 97 | { | 
|---|
| 98 | extern const WCHAR casemap_upper[]; | 
|---|
| 99 | return ch + casemap_upper[casemap_upper[ch >> 8] + (ch & 0xff)]; | 
|---|
| 100 | } | 
|---|
| 101 |  | 
|---|
| 102 | /* the character type contains the C1_* flags in the low 12 bits */ | 
|---|
| 103 | /* and the C2_* type in the high 4 bits */ | 
|---|
| 104 | static inline unsigned short get_char_typeW( WCHAR ch ) | 
|---|
| 105 | { | 
|---|
| 106 | extern const unsigned short wctype_table[]; | 
|---|
| 107 | return wctype_table[wctype_table[ch >> 8] + (ch & 0xff)]; | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | inline static int iscntrlW( WCHAR wc ) | 
|---|
| 111 | { | 
|---|
| 112 | return get_char_typeW(wc) & C1_CNTRL; | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | inline static int ispunctW( WCHAR wc ) | 
|---|
| 116 | { | 
|---|
| 117 | return get_char_typeW(wc) & C1_PUNCT; | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | inline static int isspaceW( WCHAR wc ) | 
|---|
| 121 | { | 
|---|
| 122 | return get_char_typeW(wc) & C1_SPACE; | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | inline static int isdigitW( WCHAR wc ) | 
|---|
| 126 | { | 
|---|
| 127 | return get_char_typeW(wc) & C1_DIGIT; | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 | inline static int isxdigitW( WCHAR wc ) | 
|---|
| 131 | { | 
|---|
| 132 | return get_char_typeW(wc) & C1_XDIGIT; | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | inline static int islowerW( WCHAR wc ) | 
|---|
| 136 | { | 
|---|
| 137 | return get_char_typeW(wc) & C1_LOWER; | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | inline static int isupperW( WCHAR wc ) | 
|---|
| 141 | { | 
|---|
| 142 | return get_char_typeW(wc) & C1_UPPER; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | inline static int isalnumW( WCHAR wc ) | 
|---|
| 146 | { | 
|---|
| 147 | return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER); | 
|---|
| 148 | } | 
|---|
| 149 |  | 
|---|
| 150 | inline static int isalphaW( WCHAR wc ) | 
|---|
| 151 | { | 
|---|
| 152 | return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER); | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 | inline static int isgraphW( WCHAR wc ) | 
|---|
| 156 | { | 
|---|
| 157 | return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER); | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | inline static int isprintW( WCHAR wc ) | 
|---|
| 161 | { | 
|---|
| 162 | return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER); | 
|---|
| 163 | } | 
|---|
| 164 |  | 
|---|
| 165 |  | 
|---|
| 166 | /* some useful string manipulation routines */ | 
|---|
| 167 |  | 
|---|
| 168 | static inline unsigned int strlenW( const WCHAR *str ) | 
|---|
| 169 | { | 
|---|
| 170 | #if defined(__i386__) && defined(__GNUC__) | 
|---|
| 171 | int dummy, res; | 
|---|
| 172 | __asm__ __volatile__( "cld\n\t" | 
|---|
| 173 | "repnz\n\t" | 
|---|
| 174 | "scasw\n\t" | 
|---|
| 175 | "notl %0" | 
|---|
| 176 | : "=c" (res), "=&D" (dummy) | 
|---|
| 177 | : "0" (0xffffffff), "1" (str), "a" (0) ); | 
|---|
| 178 | return res - 1; | 
|---|
| 179 | #else | 
|---|
| 180 | const WCHAR *s = str; | 
|---|
| 181 | while (*s) s++; | 
|---|
| 182 | return s - str; | 
|---|
| 183 | #endif | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | static inline WCHAR *strcpyW( WCHAR *dst, const WCHAR *src ) | 
|---|
| 187 | { | 
|---|
| 188 | #if defined(__i386__) && defined(__GNUC__) | 
|---|
| 189 | int dummy1, dummy2, dummy3; | 
|---|
| 190 | __asm__ __volatile__( "cld\n" | 
|---|
| 191 | "1:\tlodsw\n\t" | 
|---|
| 192 | "stosw\n\t" | 
|---|
| 193 | "testw %%ax,%%ax\n\t" | 
|---|
| 194 | "jne 1b" | 
|---|
| 195 | : "=&S" (dummy1), "=&D" (dummy2), "=&a" (dummy3) | 
|---|
| 196 | : "0" (src), "1" (dst) | 
|---|
| 197 | : "memory" ); | 
|---|
| 198 | #else | 
|---|
| 199 | WCHAR *p = dst; | 
|---|
| 200 | while(*src) { | 
|---|
| 201 | *p++ = *src++; | 
|---|
| 202 | } | 
|---|
| 203 | *p = 0; | 
|---|
| 204 | #endif | 
|---|
| 205 | return dst; | 
|---|
| 206 | } | 
|---|
| 207 |  | 
|---|
| 208 | static inline int strcmpW( const WCHAR *str1, const WCHAR *str2 ) | 
|---|
| 209 | { | 
|---|
| 210 | while (*str1 && (*str1 == *str2)) { str1++; str2++; } | 
|---|
| 211 | return *str1 - *str2; | 
|---|
| 212 | } | 
|---|
| 213 |  | 
|---|
| 214 | static inline int strncmpW( const WCHAR *str1, const WCHAR *str2, int n ) | 
|---|
| 215 | { | 
|---|
| 216 | if (n <= 0) return 0; | 
|---|
| 217 | while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; } | 
|---|
| 218 | return *str1 - *str2; | 
|---|
| 219 | } | 
|---|
| 220 |  | 
|---|
| 221 | static inline WCHAR *strncpyW( WCHAR *str1, const WCHAR *str2, int n ) | 
|---|
| 222 | { | 
|---|
| 223 | WCHAR *ret = str1; | 
|---|
| 224 | #ifdef __WATCOMC__ /* kso: it's so noisy and I don't find the right pragma... */ | 
|---|
| 225 | while (n-- > 0) if ((*str1++ = *str2++) != 0) break; | 
|---|
| 226 | #else | 
|---|
| 227 | while (n-- > 0) if (!(*str1++ = *str2++)) break; | 
|---|
| 228 | #endif | 
|---|
| 229 | while (n-- > 0) *str1++ = 0; | 
|---|
| 230 | return ret; | 
|---|
| 231 | } | 
|---|
| 232 |  | 
|---|
| 233 | static inline WCHAR *strcatW( WCHAR *dst, const WCHAR *src ) | 
|---|
| 234 | { | 
|---|
| 235 | strcpyW( dst + strlenW(dst), src ); | 
|---|
| 236 | return dst; | 
|---|
| 237 | } | 
|---|
| 238 |  | 
|---|
| 239 | static inline WCHAR *strchrW( const WCHAR *str, WCHAR ch ) | 
|---|
| 240 | { | 
|---|
| 241 | for ( ; *str; str++) if (*str == ch) return (WCHAR *)str; | 
|---|
| 242 | return NULL; | 
|---|
| 243 | } | 
|---|
| 244 |  | 
|---|
| 245 | static inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch ) | 
|---|
| 246 | { | 
|---|
| 247 | WCHAR *ret = NULL; | 
|---|
| 248 | for ( ; *str; str++) if (*str == ch) ret = (WCHAR *)str; | 
|---|
| 249 | return ret; | 
|---|
| 250 | } | 
|---|
| 251 |  | 
|---|
| 252 | static inline WCHAR *strlwrW( WCHAR *str ) | 
|---|
| 253 | { | 
|---|
| 254 | WCHAR *ret = str; | 
|---|
| 255 | while(*str) { | 
|---|
| 256 | *str = tolowerW(*str); | 
|---|
| 257 | str++; | 
|---|
| 258 | } | 
|---|
| 259 | return ret; | 
|---|
| 260 | } | 
|---|
| 261 |  | 
|---|
| 262 | static inline WCHAR *struprW( WCHAR *str ) | 
|---|
| 263 | { | 
|---|
| 264 | WCHAR *ret = str; | 
|---|
| 265 | while(*str) { | 
|---|
| 266 | *str = toupperW(*str); | 
|---|
| 267 | str++; | 
|---|
| 268 | } | 
|---|
| 269 | return ret; | 
|---|
| 270 | } | 
|---|
| 271 |  | 
|---|
| 272 | static inline long int atolW( const WCHAR *str ) | 
|---|
| 273 | { | 
|---|
| 274 | return strtolW( str, (WCHAR **)0, 10 ); | 
|---|
| 275 | } | 
|---|
| 276 |  | 
|---|
| 277 | static inline int atoiW( const WCHAR *str ) | 
|---|
| 278 | { | 
|---|
| 279 | return (int)atolW( str ); | 
|---|
| 280 | } | 
|---|
| 281 |  | 
|---|
| 282 | #if defined(__IBMC__) || defined(__IBMCPP__) || defined(__WATCOMC__) || defined(__WATCOM_CPLUSPLUS__) | 
|---|
| 283 | #undef static | 
|---|
| 284 | #endif | 
|---|
| 285 |  | 
|---|
| 286 | #ifdef __cplusplus | 
|---|
| 287 | } | 
|---|
| 288 | #endif | 
|---|
| 289 |  | 
|---|
| 290 | #endif //RC_INVOKED | 
|---|
| 291 |  | 
|---|
| 292 | #endif  /* __WINE_UNICODE_H */ | 
|---|