diff --git a/src/intl/charsets.c b/src/intl/charsets.c index aee850fd..290a877c 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -142,6 +142,7 @@ static const unicode_val_T strange_chars[32] = { }; #define SYSTEM_CHARSET_FLAG 128 +#define is_cp_ptr_utf8(cp_ptr) ((cp_ptr)->table == table_utf8) unsigned char * u2cp_(unicode_val_T u, int to, int no_nbsp_hack) @@ -154,7 +155,7 @@ u2cp_(unicode_val_T u, int to, int no_nbsp_hack) to &= ~SYSTEM_CHARSET_FLAG; #ifdef CONFIG_UTF8 - if (codepages[to].table == table_utf8) + if (is_cp_ptr_utf8(&codepages[to])) return encode_utf8(u); #endif /* CONFIG_UTF8 */ @@ -651,7 +652,7 @@ cp2u(int from, unsigned char c) /* UTF-8 is a multibyte codepage and cannot be handled with * this function. */ - assert(codepages[from].table != table_utf8); + assert(!is_cp_ptr_utf8(&codepages[from])); if_assert_failed return UCS_REPLACEMENT_CHARACTER; if (c < 0x80) return c; @@ -664,7 +665,7 @@ cp2utf8(int from, int c) { from &= ~SYSTEM_CHARSET_FLAG; - if (codepages[from].table == table_utf8 || c < 128) + if (is_cp_ptr_utf8(&codepages[from]) || c < 128) return strings[c]; return encode_utf8(cp2u_shared(&codepages[from], c)); @@ -750,7 +751,7 @@ get_translation_table_to_utf8(int from) for (i = 0; i < 128; i++) utf_table[i].u.str = strings[i]; - if (codepages[from].table == table_utf8) { + if (is_cp_ptr_utf8(&codepages[from])) { for (i = 128; i < 256; i++) utf_table[i].u.str = stracpy(strings[i]); return utf_table; @@ -803,7 +804,7 @@ get_translation_table(int from, int to) } if (/*from == to ||*/ from == -1 || to == -1) return NULL; - if (codepages[to].table == table_utf8) + if (is_cp_ptr_utf8(&codepages[to])) return get_translation_table_to_utf8(from); if (from == lfr && to == lto) return table; @@ -811,7 +812,7 @@ get_translation_table(int from, int to) lto = to; new_translation_table(table); - if (codepages[from].table == table_utf8) { + if (is_cp_ptr_utf8(&codepages[from])) { int i; for (i = 0; codepages[to].table[i].c; i++) @@ -910,7 +911,7 @@ get_entity_string(const unsigned char *str, const int strlen, int encoding) #ifdef CONFIG_UTF8 /* TODO: caching UTF-8 */ encoding &= ~SYSTEM_CHARSET_FLAG; - if (codepages[encoding].table == table_utf8) + if (is_cp_ptr_utf8(&codepages[encoding])) goto skip; #endif /* CONFIG_UTF8 */ @@ -1022,7 +1023,7 @@ skip: } #ifdef CONFIG_UTF8 - if (codepages[encoding].table == table_utf8) { + if (is_cp_ptr_utf8(&codepages[encoding])) { return result; } #endif /* CONFIG_UTF8 */ @@ -1354,5 +1355,5 @@ int is_cp_utf8(int cp_index) { cp_index &= ~SYSTEM_CHARSET_FLAG; - return codepages[cp_index].table == table_utf8; + return is_cp_ptr_utf8(&codepages[cp_index]); }