diff --git a/src/intl/charsets.c b/src/intl/charsets.c index 9f788215..047beb1f 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -164,7 +164,7 @@ static const unicode_val_T strange_chars[32] = { #define is_cp_ptr_utf8(cp_ptr) ((cp_ptr)->aliases == aliases_utf8) unsigned char * -u2cp_(unicode_val_T u, int to, int no_nbsp_hack) +u2cp_(unicode_val_T u, int to, enum nbsp_mode nbsp_mode) { int j; int s; @@ -179,14 +179,17 @@ u2cp_(unicode_val_T u, int to, int no_nbsp_hack) #endif /* CONFIG_UTF8 */ /* To mark non breaking spaces, we use a special char NBSP_CHAR. */ - if (u == 0xa0) return no_nbsp_hack ? " " : NBSP_CHAR_STRING; + if (u == 0xa0) { + if (nbsp_mode == NBSP_MODE_HACK) return NBSP_CHAR_STRING; + else /* NBSP_MODE_ASCII */ return " "; + } if (u == 0xad) return ""; if (u < 0xa0) { unicode_val_T strange = strange_chars[u - 0x80]; if (!strange) return NULL; - return u2cp_(strange, to, no_nbsp_hack); + return u2cp_(strange, to, nbsp_mode); } if (u < 0xFFFF) diff --git a/src/intl/charsets.h b/src/intl/charsets.h index 841d3da2..65cfc999 100644 --- a/src/intl/charsets.h +++ b/src/intl/charsets.h @@ -35,6 +35,17 @@ enum convert_string_mode { CSM_NONE, /* Convert nothing. */ }; +/* How to translate non-breaking spaces. */ +enum nbsp_mode { + /* Convert to NBSP_CHAR. This lets the HTML renderer + * recognize nbsp even if the codepage doesn't support + * nbsp. (VISCII doesn't.) */ + NBSP_MODE_HACK = 0, + + /* Convert to normal ASCII space. */ + NBSP_MODE_ASCII = 1 +}; + struct conv_table *get_translation_table(int, int); unsigned char *get_entity_string(const unsigned char *str, const int strlen, int encoding); @@ -101,9 +112,9 @@ unicode_val_T cp_to_unicode(int, unsigned char **, unsigned char *); unicode_val_T cp2u(int, unsigned char); unsigned char *cp2utf8(int, int); -unsigned char *u2cp_(unicode_val_T, int, int no_nbsp_hack); -#define u2cp(u, to) u2cp_(u, to, 0) -#define u2cp_no_nbsp(u, to) u2cp_(u, to, 1) +unsigned char *u2cp_(unicode_val_T, int, enum nbsp_mode); +#define u2cp(u, to) u2cp_(u, to, NBSP_MODE_HACK) +#define u2cp_no_nbsp(u, to) u2cp_(u, to, NBSP_MODE_ASCII) void init_charsets_lookup(void); void free_charsets_lookup(void);