mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
fix: edit in 8-bit locale UTF-8 source
This commit is contained in:
parent
7494db39ed
commit
4725fe329c
17
edit/edit.c
17
edit/edit.c
@ -2385,7 +2385,24 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion)
|
||||
if (edit_get_byte (edit, edit->curs1) != '\n')
|
||||
edit_delete (edit);
|
||||
}
|
||||
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) {
|
||||
format_paragraph (edit, 0);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
|
@ -269,8 +269,11 @@ edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch)
|
||||
}
|
||||
#ifdef HAVE_CHARSET
|
||||
} else {
|
||||
//FIXME: need more think about
|
||||
//must be return multibyte char but this func return 8bit char
|
||||
c = convert_from_input_c (x_key);
|
||||
if (is_printable (c)) {
|
||||
char_for_insertion = convert_from_8bit_to_utf_c2((unsigned char) x_key);
|
||||
goto fin;
|
||||
}
|
||||
}
|
||||
/* UTF-8 locale */
|
||||
} else {
|
||||
|
@ -393,5 +393,41 @@ convert_from_8bit_to_utf_c (const char input_char)
|
||||
}
|
||||
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 */
|
||||
|
Loading…
Reference in New Issue
Block a user