fix: with status_string on utf-8 char

This commit is contained in:
Ilia Maslakov 2009-04-15 18:14:17 +00:00 committed by Slava Zanko
parent dd6e11fa9c
commit 2fdb3689e2
2 changed files with 17 additions and 7 deletions

View File

@ -164,12 +164,11 @@ int edit_get_utf (WEdit * edit, long byte_index, int *char_width)
int width = 0; int width = 0;
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) { if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) {
*char_width = 1; *char_width = 0;
return '\n'; return '\n';
} }
str = edit_get_byte_ptr (edit, byte_index); str = edit_get_byte_ptr (edit, byte_index);
res = g_utf8_get_char_validated (str, -1); res = g_utf8_get_char_validated (str, -1);
if ( res < 0 ) { if ( res < 0 ) {

View File

@ -73,11 +73,22 @@ static void status_string (WEdit * edit, char *s, int w)
* as decimal and as hex. * as decimal and as hex.
*/ */
if (edit->curs1 < edit->last_byte) { if (edit->curs1 < edit->last_byte) {
unsigned char cur_byte = edit_get_byte (edit, edit->curs1); if ( !edit->utf8 ) {
g_snprintf (byte_str, sizeof (byte_str), "%c %3d 0x%02X", unsigned char cur_byte = edit_get_byte (edit, edit->curs1);
is_printable (cur_byte) ? cur_byte : '.', g_snprintf (byte_str, sizeof (byte_str), "%c %3d 0x%02X",
(int) cur_byte, is_printable (cur_byte) ? cur_byte : '.',
(unsigned) cur_byte); (int) cur_byte,
(unsigned) cur_byte);
} else {
int cw = 1;
unsigned int cur_utf = edit_get_utf (edit, edit->curs1, &cw);
if ( cw > 0 ) {
g_snprintf (byte_str, sizeof (byte_str), "%04d 0x%03X",
(unsigned) cur_utf,
(unsigned) cur_utf);
}
}
} else { } else {
strcpy (byte_str, "<EOF>"); strcpy (byte_str, "<EOF>");
} }