fix: edit in 8-bit locale UTF-8 source

This commit is contained in:
Ilia Maslakov 2009-04-20 09:01:47 +00:00
parent 7494db39ed
commit 4725fe329c
3 changed files with 59 additions and 3 deletions

View File

@ -2385,7 +2385,24 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
if (edit_get_byte (edit, edit->curs1) != '\n') if (edit_get_byte (edit, edit->curs1) != '\n')
edit_delete (edit); edit_delete (edit);
} }
edit_insert (edit, char_for_insertion); if ( char_for_insertion > 255 && utf8_display == 0 ) {
unsigned char str[6 + 1];
int res = g_unichar_to_utf8 (char_for_insertion, str);
if ( res == 0 ) {
str[0] = '.';
str[1] = '\0';
} else {
str[res] = '\0';
}
int i = 0;
while ( str[i] != 0 && i<=6) {
char_for_insertion = str[i];
edit_insert (edit, char_for_insertion);
i++;
}
} else {
edit_insert (edit, char_for_insertion);
}
if (option_auto_para_formatting) { if (option_auto_para_formatting) {
format_paragraph (edit, 0); format_paragraph (edit, 0);
edit->force |= REDRAW_PAGE; edit->force |= REDRAW_PAGE;

View File

@ -269,8 +269,11 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
} }
#ifdef HAVE_CHARSET #ifdef HAVE_CHARSET
} else { } else {
//FIXME: need more think about c = convert_from_input_c (x_key);
//must be return multibyte char but this func return 8bit char if (is_printable (c)) {
char_for_insertion = convert_from_8bit_to_utf_c2((unsigned char) x_key);
goto fin;
}
} }
/* UTF-8 locale */ /* UTF-8 locale */
} else { } else {

View File

@ -393,5 +393,41 @@ convert_from_8bit_to_utf_c (const char input_char)
} }
return ch; return ch;
}
int
convert_from_8bit_to_utf_c2 (const char input_char)
{
unsigned char str[2];
unsigned char buf_ch[6 + 1];
int ch = '.';
int res = 0;
GIConv conv;
str[0] = (unsigned char) input_char;
str[1] = '\0';
const char *cp_from = get_codepage_id ( source_codepage );
conv = str_crt_conv_to (cp_from);
if (conv != INVALID_CONV) {
switch (str_translate_char (conv, str, -1, buf_ch, sizeof(buf_ch))) {
case 0:
res = g_utf8_get_char_validated (buf_ch, -1);
if ( res < 0 ) {
ch = buf_ch[0];
} else {
ch = res;
}
break;
case 1:
case 2:
ch = '.';
break;
}
str_close_conv (conv);
}
return ch;
} }
#endif /* HAVE_CHARSET */ #endif /* HAVE_CHARSET */