libwine: Get the reverse mapping of the Unicode default char to check for invalid chars.

We can't assume that wctomb(Unicode default char) is identical to the Ansi
default char.
This commit is contained in:
Alexandre Julliard 2009-02-23 15:16:35 +01:00
parent 5a0079f6ca
commit b38b207625
1 changed files with 10 additions and 7 deletions

View File

@ -44,10 +44,12 @@ static inline int check_invalid_chars_sbcs( const struct sbcs_table *table, int
const unsigned char *src, unsigned int srclen )
{
const WCHAR * const cp2uni = (flags & MB_USEGLYPHCHARS) ? table->cp2uni_glyphs : table->cp2uni;
const WCHAR def_unicode_char = table->info.def_unicode_char;
const unsigned char def_char = table->uni2cp_low[table->uni2cp_high[def_unicode_char >> 8]
+ (def_unicode_char & 0xff)];
while (srclen)
{
if (cp2uni[*src] == table->info.def_unicode_char && *src != table->info.def_char)
break;
if (cp2uni[*src] == def_unicode_char && *src != def_char) break;
src++;
srclen--;
}
@ -151,20 +153,21 @@ static inline int check_invalid_chars_dbcs( const struct dbcs_table *table,
{
const WCHAR * const cp2uni = table->cp2uni;
const unsigned char * const cp2uni_lb = table->cp2uni_leadbytes;
const WCHAR def_unicode_char = table->info.def_unicode_char;
const unsigned short def_char = table->uni2cp_low[table->uni2cp_high[def_unicode_char >> 8]
+ (def_unicode_char & 0xff)];
while (srclen)
{
unsigned char off = cp2uni_lb[*src];
if (off) /* multi-byte char */
{
if (srclen == 1) break; /* partial char, error */
if (cp2uni[(off << 8) + src[1]] == table->info.def_unicode_char &&
((src[0] << 8) | src[1]) != table->info.def_char) break;
if (cp2uni[(off << 8) + src[1]] == def_unicode_char &&
((src[0] << 8) | src[1]) != def_char) break;
src++;
srclen--;
}
else if (cp2uni[*src] == table->info.def_unicode_char &&
*src != table->info.def_char) break;
else if (cp2uni[*src] == def_unicode_char && *src != def_char) break;
src++;
srclen--;
}