1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Bug 821: kbd_field: CONFIG_UTF8 does not mean widget_data->cdata is UTF-8.

The current rules are:

             term.utf8
CONFIG_UTF8  UTF-8 I/O  widget_data.cdata
-----------  ---------  ------------------
undefined    disabled   charset of the terminal
undefined    enabled    charset of the terminal
defined      disabled   charset of the terminal (*)
defined      enabled    always UTF-8

(*) kbd_field was incorrectly assuming UTF-8 in this case.
This commit is contained in:
Kalle Olavi Niemitalo 2006-10-22 17:18:26 +03:00 committed by Kalle Olavi Niemitalo
parent d050cb67aa
commit 2fd8538a72

View File

@ -680,12 +680,32 @@ kbd_field(struct dialog_data *dlg_data, struct widget_data *widget_data)
if (check_kbd_textinput_key(ev)) {
unsigned char *text = widget_data->cdata;
int textlen = strlen(text);
#ifdef CONFIG_UTF8
const unsigned char *ins = encode_utf8(get_kbd_key(ev));
int inslen = utf8charlen(ins);
#else /* !CONFIG_UTF8 */
#ifndef CONFIG_UTF8
/* Both get_kbd_key(ev) and @text
* are in the terminal's charset. */
const int inslen = 1;
#endif /* !CONFIG_UTF8 */
#else /* CONFIG_UTF8 */
const unsigned char *ins;
int inslen;
if (term->utf8) {
/* get_kbd_key(ev) is in UCS-4,
* and @text is in UTF-8. */
ins = encode_utf8(get_kbd_key(ev));
/* get_kbd_key(ev) cannot be L'\0'
* because @check_kbd_textinput_key
* would have rejected it. So it
* is OK to use @strlen below. */
} else {
/* get_kbd_key(ev) is UCS-4, and @text
* is in the terminal's charset. */
int cp = get_opt_codepage_tree(term->spec,
"charset");
ins = u2cp_no_nbsp(get_kbd_key(ev), cp);
}
inslen = strlen(ins);
#endif /* CONFIG_UTF8 */
if (textlen >= widget_data->widget->datalen - inslen)
goto display_field;