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