Added support for WC_NO_BEST_FIT_CHAR and default char parameters in

cp_wcstombs.
Minor cosmetic fixes.
This commit is contained in:
Alexandre Julliard 2000-06-10 04:29:16 +00:00
parent 70b699a1a1
commit 6659308fe9
58 changed files with 190 additions and 72 deletions

View File

@ -12,7 +12,7 @@ struct cp_info
{
unsigned int codepage; /* codepage id */
unsigned int char_size; /* char size (1 or 2 bytes) */
char def_char[2]; /* default char value */
unsigned short def_char; /* default char value (can be double-byte) */
unsigned short def_unicode_char; /* default Unicode char value */
const char *name; /* code page name */
};
@ -50,11 +50,30 @@ extern int cp_mbstowcs( const union cptable *table, int flags,
unsigned short *dst, int dstlen );
extern int cp_wcstombs( const union cptable *table, int flags,
const unsigned short *src, int srclen,
char *dst, int dstlen );
char *dst, int dstlen, const char *defchar, int *used );
static inline int is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
{
return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
}
static inline unsigned int strlenW( const unsigned short *str )
{
#if defined(__i386__) && defined(__GNUC__)
int dummy, res;
__asm__( "cld\n\t"
"repne\n\t"
"scasw\n\t"
"notl %0"
: "=c" (res), "=&D" (dummy)
: "0" (0xffffffff), "1" (str), "a" (0) );
return res - 1;
#else
const unsigned short *s = str;
while (*s) s++;
return s - str;
#endif
}
#endif /* __WINE_UNICODE_H */

View File

@ -153,11 +153,11 @@
#define CP_UTF7 65000
#define CP_UTF8 65001
#define WC_DEFAULTCHECK 0x00000100
#define WC_COMPOSITECHECK 0x00000200
#define WC_DISCARDNS 0x00000010
#define WC_SEPCHARS 0x00000020
#define WC_DEFAULTCHAR 0x00000040
#define WC_DISCARDNS 0x00000010
#define WC_SEPCHARS 0x00000020
#define WC_DEFAULTCHAR 0x00000040
#define WC_COMPOSITECHECK 0x00000200
#define WC_NO_BEST_FIT_CHARS 0x00000400
#define MAKELCID(l, s) (MAKELONG(l, s))

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_037 =
{
{ 37, 1, { 0x3f, 0x00 }, 0x003f, "IBM EBCDIC US Canada" },
{ 37, 1, 0x003f, 0x003f, "IBM EBCDIC US Canada" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_10000 =
{
{ 10000, 1, { 0x3f, 0x00 }, 0x003f, "Mac Roman" },
{ 10000, 1, 0x003f, 0x003f, "Mac Roman" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_10006 =
{
{ 10006, 1, { 0x3f, 0x00 }, 0x003f, "Mac Greek" },
{ 10006, 1, 0x003f, 0x003f, "Mac Greek" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_10007 =
{
{ 10007, 1, { 0x3f, 0x00 }, 0x003f, "Mac Cyrillic" },
{ 10007, 1, 0x003f, 0x003f, "Mac Cyrillic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_10029 =
{
{ 10029, 1, { 0x3f, 0x00 }, 0x003f, "Mac Latin 2" },
{ 10029, 1, 0x003f, 0x003f, "Mac Latin 2" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1006 =
{
{ 1006, 1, { 0x3f, 0x00 }, 0x003f, "IBM Arabic" },
{ 1006, 1, 0x003f, 0x003f, "IBM Arabic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_10079 =
{
{ 10079, 1, { 0x3f, 0x00 }, 0x003f, "Mac Icelandic" },
{ 10079, 1, 0x003f, 0x003f, "Mac Icelandic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_10081 =
{
{ 10081, 1, { 0x3f, 0x00 }, 0x003f, "Mac Turkish" },
{ 10081, 1, 0x003f, 0x003f, "Mac Turkish" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1026 =
{
{ 1026, 1, { 0x3f, 0x00 }, 0x003f, "IBM EBCDIC Latin 5 Turkish" },
{ 1026, 1, 0x003f, 0x003f, "IBM EBCDIC Latin 5 Turkish" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1250 =
{
{ 1250, 1, { 0x3f, 0x00 }, 0x003f, "ANSI Eastern Europe" },
{ 1250, 1, 0x003f, 0x003f, "ANSI Eastern Europe" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1251 =
{
{ 1251, 1, { 0x3f, 0x00 }, 0x003f, "ANSI Cyrillic" },
{ 1251, 1, 0x003f, 0x003f, "ANSI Cyrillic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1252 =
{
{ 1252, 1, { 0x3f, 0x00 }, 0x003f, "ANSI Latin 1" },
{ 1252, 1, 0x003f, 0x003f, "ANSI Latin 1" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1253 =
{
{ 1253, 1, { 0x3f, 0x00 }, 0x003f, "ANSI Greek" },
{ 1253, 1, 0x003f, 0x003f, "ANSI Greek" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1254 =
{
{ 1254, 1, { 0x3f, 0x00 }, 0x003f, "ANSI Turkish" },
{ 1254, 1, 0x003f, 0x003f, "ANSI Turkish" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1255 =
{
{ 1255, 1, { 0x3f, 0x00 }, 0x003f, "ANSI Hebrew" },
{ 1255, 1, 0x003f, 0x003f, "ANSI Hebrew" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1256 =
{
{ 1256, 1, { 0x3f, 0x00 }, 0x003f, "ANSI Arabic" },
{ 1256, 1, 0x003f, 0x003f, "ANSI Arabic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1257 =
{
{ 1257, 1, { 0x3f, 0x00 }, 0x003f, "ANSI Baltic" },
{ 1257, 1, 0x003f, 0x003f, "ANSI Baltic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_1258 =
{
{ 1258, 1, { 0x3f, 0x00 }, 0x003f, "ANSI/OEM Viet Nam" },
{ 1258, 1, 0x003f, 0x003f, "ANSI/OEM Viet Nam" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_20866 =
{
{ 20866, 1, { 0x3f, 0x00 }, 0x003f, "Russian KOI8" },
{ 20866, 1, 0x003f, 0x003f, "Russian KOI8" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28591 =
{
{ 28591, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-1 Latin 1" },
{ 28591, 1, 0x003f, 0x003f, "ISO 8859-1 Latin 1" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28592 =
{
{ 28592, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-2 Eastern Europe" },
{ 28592, 1, 0x003f, 0x003f, "ISO 8859-2 Eastern Europe" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28593 =
{
{ 28593, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-3 Turkish" },
{ 28593, 1, 0x003f, 0x003f, "ISO 8859-3 Turkish" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28594 =
{
{ 28594, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-4 Baltic" },
{ 28594, 1, 0x003f, 0x003f, "ISO 8859-4 Baltic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28595 =
{
{ 28595, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-5 Cyrillic" },
{ 28595, 1, 0x003f, 0x003f, "ISO 8859-5 Cyrillic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28596 =
{
{ 28596, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-6 Arabic" },
{ 28596, 1, 0x003f, 0x003f, "ISO 8859-6 Arabic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28597 =
{
{ 28597, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-7 Greek" },
{ 28597, 1, 0x003f, 0x003f, "ISO 8859-7 Greek" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28598 =
{
{ 28598, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-8 Hebrew" },
{ 28598, 1, 0x003f, 0x003f, "ISO 8859-8 Hebrew" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_28599 =
{
{ 28599, 1, { 0x3f, 0x00 }, 0x003f, "ISO 8859-9 Latin 5" },
{ 28599, 1, 0x003f, 0x003f, "ISO 8859-9 Latin 5" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_424 =
{
{ 424, 1, { 0x3f, 0x00 }, 0x003f, "IBM EBCDIC Hebrew" },
{ 424, 1, 0x003f, 0x003f, "IBM EBCDIC Hebrew" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_437 =
{
{ 437, 1, { 0x3f, 0x00 }, 0x003f, "OEM United States" },
{ 437, 1, 0x003f, 0x003f, "OEM United States" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_500 =
{
{ 500, 1, { 0x3f, 0x00 }, 0x003f, "IBM EBCDIC International" },
{ 500, 1, 0x003f, 0x003f, "IBM EBCDIC International" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_737 =
{
{ 737, 1, { 0x3f, 0x00 }, 0x003f, "OEM Greek 437G" },
{ 737, 1, 0x003f, 0x003f, "OEM Greek 437G" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_775 =
{
{ 775, 1, { 0x3f, 0x00 }, 0x003f, "OEM Baltic" },
{ 775, 1, 0x003f, 0x003f, "OEM Baltic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_850 =
{
{ 850, 1, { 0x3f, 0x00 }, 0x003f, "OEM Multilingual Latin 1" },
{ 850, 1, 0x003f, 0x003f, "OEM Multilingual Latin 1" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_852 =
{
{ 852, 1, { 0x3f, 0x00 }, 0x003f, "OEM Slovak Latin 2" },
{ 852, 1, 0x003f, 0x003f, "OEM Slovak Latin 2" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_855 =
{
{ 855, 1, { 0x3f, 0x00 }, 0x003f, "OEM Cyrillic" },
{ 855, 1, 0x003f, 0x003f, "OEM Cyrillic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_856 =
{
{ 856, 1, { 0x3f, 0x00 }, 0x003f, "Hebrew PC" },
{ 856, 1, 0x003f, 0x003f, "Hebrew PC" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_857 =
{
{ 857, 1, { 0x3f, 0x00 }, 0x003f, "OEM Turkish" },
{ 857, 1, 0x003f, 0x003f, "OEM Turkish" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_860 =
{
{ 860, 1, { 0x3f, 0x00 }, 0x003f, "OEM Portuguese" },
{ 860, 1, 0x003f, 0x003f, "OEM Portuguese" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_861 =
{
{ 861, 1, { 0x3f, 0x00 }, 0x003f, "OEM Icelandic" },
{ 861, 1, 0x003f, 0x003f, "OEM Icelandic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_862 =
{
{ 862, 1, { 0x3f, 0x00 }, 0x003f, "OEM Hebrew" },
{ 862, 1, 0x003f, 0x003f, "OEM Hebrew" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_863 =
{
{ 863, 1, { 0x3f, 0x00 }, 0x003f, "OEM Canadian French" },
{ 863, 1, 0x003f, 0x003f, "OEM Canadian French" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_864 =
{
{ 864, 1, { 0x3f, 0x00 }, 0x003f, "OEM Arabic" },
{ 864, 1, 0x003f, 0x003f, "OEM Arabic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_865 =
{
{ 865, 1, { 0x3f, 0x00 }, 0x003f, "OEM Nordic" },
{ 865, 1, 0x003f, 0x003f, "OEM Nordic" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_866 =
{
{ 866, 1, { 0x3f, 0x00 }, 0x003f, "OEM Russian" },
{ 866, 1, 0x003f, 0x003f, "OEM Russian" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_869 =
{
{ 869, 1, { 0x3f, 0x00 }, 0x003f, "OEM Greek" },
{ 869, 1, 0x003f, 0x003f, "OEM Greek" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_874 =
{
{ 874, 1, { 0x3f, 0x00 }, 0x003f, "ANSI/OEM Thai" },
{ 874, 1, 0x003f, 0x003f, "ANSI/OEM Thai" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -643,7 +643,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_875 =
{
{ 875, 1, { 0x3f, 0x00 }, 0x003f, "IBM EBCDIC Greek" },
{ 875, 1, 0x003f, 0x003f, "IBM EBCDIC Greek" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -676,7 +676,7 @@ static const unsigned short uni2cp_high[256] =
const struct sbcs_table cptable_878 =
{
{ 878, 1, { 0x3f, 0x00 }, 0x003f, "Russian KOI8" },
{ 878, 1, 0x003f, 0x003f, "Russian KOI8" },
cp2uni,
uni2cp_low,
uni2cp_high

View File

@ -5200,10 +5200,10 @@ static const unsigned short uni2cp_high[256] =
const struct dbcs_table cptable_932 =
{
{ 932, 2, { 0x3f, 0x00 }, 0x003f, "ANSI/OEM Japanese Shift-JIS" },
{ 932, 2, 0x003f, 0x003f, "ANSI/OEM Japanese Shift-JIS" },
cp2uni,
cp2uni_leadbytes,
uni2cp_low,
uni2cp_high,
{ 0x81, 0x9f, 0xe0, 0xfc, }
{ 0x81, 0x9f, 0xe0, 0xfc, 0x00, 0x00 }
};

View File

@ -7840,10 +7840,10 @@ static const unsigned short uni2cp_high[256] =
const struct dbcs_table cptable_936 =
{
{ 936, 2, { 0x3f, 0x00 }, 0x003f, "ANSI/OEM Simplified Chinese GBK" },
{ 936, 2, 0x003f, 0x003f, "ANSI/OEM Simplified Chinese GBK" },
cp2uni,
cp2uni_leadbytes,
uni2cp_low,
uni2cp_high,
{ 0x81, 0xfe, }
{ 0x81, 0xfe, 0x00, 0x00 }
};

View File

@ -9259,10 +9259,10 @@ static const unsigned short uni2cp_high[256] =
const struct dbcs_table cptable_949 =
{
{ 949, 2, { 0x3f, 0x00 }, 0x003f, "ANSI/OEM Korean Unified Hangul" },
{ 949, 2, 0x003f, 0x003f, "ANSI/OEM Korean Unified Hangul" },
cp2uni,
cp2uni_leadbytes,
uni2cp_low,
uni2cp_high,
{ 0x81, 0xfe, }
{ 0x81, 0xfe, 0x00, 0x00 }
};

View File

@ -6553,10 +6553,10 @@ static const unsigned short uni2cp_high[256] =
const struct dbcs_table cptable_950 =
{
{ 950, 2, { 0x3f, 0x00 }, 0x003f, "ANSI/OEM Traditional Chinese Big5" },
{ 950, 2, 0x003f, 0x003f, "ANSI/OEM Traditional Chinese Big5" },
cp2uni,
cp2uni_leadbytes,
uni2cp_low,
uni2cp_high,
{ 0x81, 0xfe, }
{ 0x81, 0xfe, 0x00, 0x00 }
};

View File

@ -328,7 +328,7 @@ sub DUMP_SBCS_TABLE
# output the code page descriptor
printf OUTPUT "const struct sbcs_table cptable_%03d =\n{\n", $codepage;
printf OUTPUT " { %d, 1, { 0x%02x, 0x00 }, 0x%04x, \"%s\" },\n",
printf OUTPUT " { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
$codepage, $DEF_CHAR, $DEF_CHAR, $name;
printf OUTPUT " cp2uni,\n";
printf OUTPUT " uni2cp_low,\n";
@ -471,7 +471,7 @@ sub DUMP_DBCS_TABLE
# output the code page descriptor
printf OUTPUT "const struct dbcs_table cptable_%03d =\n{\n", $codepage;
printf OUTPUT " { %d, 2, { 0x%02x, 0x00 }, 0x%04x, \"%s\" },\n",
printf OUTPUT " { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
$codepage, $DEF_CHAR, $DEF_CHAR, $name;
printf OUTPUT " cp2uni,\n";
printf OUTPUT " cp2uni_leadbytes,\n";
@ -503,7 +503,7 @@ sub DUMP_LB_RANGES
}
}
if ($on) { printf OUTPUT "0xff, "; }
printf OUTPUT "}\n";
printf OUTPUT "0x00, 0x00 }\n";
}

View File

@ -16,7 +16,7 @@ static inline int check_invalid_chars_sbcs( const struct sbcs_table *table,
const unsigned short * const cp2uni = table->cp2uni;
while (srclen)
{
if (cp2uni[*src] == table->info.def_unicode_char && *src != table->info.def_char[0])
if (cp2uni[*src] == table->info.def_unicode_char && *src != table->info.def_char)
break;
src++;
srclen--;
@ -102,13 +102,12 @@ static inline int check_invalid_chars_dbcs( const struct dbcs_table *table,
{
if (srclen == 1) break; /* partial char, error */
if (cp2uni[(off << 8) + src[1]] == table->info.def_unicode_char &&
(src[0] != table->info.def_char[0] || src[1] != table->info.def_char[1]))
break;
((src[0] << 8) | src[1]) != table->info.def_char) break;
src++;
srclen--;
}
else if (cp2uni[*src] == table->info.def_unicode_char &&
(*src != table->info.def_char[0] || table->info.def_char[1])) break;
*src != table->info.def_char) break;
src++;
srclen--;
}

View File

@ -55,6 +55,44 @@ static inline int wcstombs_sbcs( const struct sbcs_table *table,
}
}
/* slow version of wcstombs_sbcs that handles the various flags */
static int wcstombs_sbcs_slow( const struct sbcs_table *table, int flags,
const unsigned short *src, unsigned int srclen,
char *dst, unsigned int dstlen,
const char *defchar, int *used )
{
const unsigned short * const cp2uni = table->cp2uni;
const unsigned char * const uni2cp_low = table->uni2cp_low;
const unsigned short * const uni2cp_high = table->uni2cp_high;
const unsigned char table_default = table->info.def_char & 0xff;
int ret = srclen, tmp;
if (dstlen < srclen)
{
/* buffer too small: fill it up to dstlen and return error */
srclen = dstlen;
ret = -1;
}
if (!defchar) defchar = &table_default;
if (!used) used = &tmp; /* avoid checking on every char */
while (srclen)
{
unsigned char ch = uni2cp_low[uni2cp_high[*src >> 8] + (*src & 0xff)];
if (((flags & WC_NO_BEST_FIT_CHARS) && (cp2uni[ch] != *src)) ||
(ch == table_default && *src != table->info.def_unicode_char))
{
ch = *defchar;
*used = 1;
}
*dst++ = ch;
src++;
srclen--;
}
return ret;
}
/* query necessary dst length for src string */
static inline int get_length_dbcs( const struct dbcs_table *table,
const unsigned short *src, unsigned int srclen )
@ -94,20 +132,82 @@ static inline int wcstombs_dbcs( const struct dbcs_table *table,
return dstlen - len;
}
/* slow version of wcstombs_dbcs that handles the various flags */
static int wcstombs_dbcs_slow( const struct dbcs_table *table, int flags,
const unsigned short *src, unsigned int srclen,
char *dst, unsigned int dstlen,
const char *defchar, int *used )
{
const unsigned short * const uni2cp_low = table->uni2cp_low;
const unsigned short * const uni2cp_high = table->uni2cp_high;
const unsigned short * const cp2uni = table->cp2uni;
const unsigned char * const cp2uni_lb = table->cp2uni_leadbytes;
unsigned short defchar_value = table->info.def_char;
int len, tmp;
if (defchar) defchar_value = defchar[1] ? ((defchar[0] << 8) | defchar[1]) : defchar[0];
if (!used) used = &tmp; /* avoid checking on every char */
for (len = dstlen; srclen && len; len--, srclen--, src++)
{
unsigned short res = uni2cp_low[uni2cp_high[*src >> 8] + (*src & 0xff)];
if (res == table->info.def_char && *src != table->info.def_unicode_char)
{
res = defchar_value;
*used = 1;
}
else if (flags & WC_NO_BEST_FIT_CHARS)
{
/* check if char maps back to the same Unicode value */
if (res & 0xff00)
{
unsigned char off = cp2uni_lb[res >> 8];
if (cp2uni[(off << 8) + (res & 0xff)] != *src)
{
res = defchar_value;
*used = 1;
}
}
else if (cp2uni[res & 0xff] != *src)
{
res = defchar_value;
*used = 1;
}
}
if (res & 0xff00)
{
if (len == 1) break; /* do not output a partial char */
len--;
*dst++ = res >> 8;
}
*dst++ = (char)res;
}
if (srclen) return -1; /* overflow */
return dstlen - len;
}
/* wide char to multi byte string conversion */
/* return -1 on dst buffer overflow */
int cp_wcstombs( const union cptable *table, int flags,
const unsigned short *src, int srclen,
char *dst, int dstlen )
char *dst, int dstlen, const char *defchar, int *used )
{
if (table->info.char_size == 1)
{
if (!dstlen) return srclen;
if (flags || defchar || used)
return wcstombs_sbcs_slow( &table->sbcs, flags, src, srclen,
dst, dstlen, defchar, used );
return wcstombs_sbcs( &table->sbcs, src, srclen, dst, dstlen );
}
else /* mbcs */
{
if (!dstlen) return get_length_dbcs( &table->dbcs, src, srclen );
if (flags || defchar || used)
return wcstombs_dbcs_slow( &table->dbcs, flags, src, srclen,
dst, dstlen, defchar, used );
return wcstombs_sbcs( &table->sbcs, src, srclen, dst, dstlen );
}
}