improve the handling of whitespace display mode in multibyte locales:
use new function make_mbstring() instead of display_string() to make sure the multibyte string is valid and interpreted properly git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2348 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
родитель
55dfc3d3e9
Коммит
e0fb4d5641
@ -173,8 +173,9 @@ CVS code -
|
||||
color_to_int(), and add a few miscellaneous tweaks.
|
||||
- Still more steps toward full wide/multibyte character support.
|
||||
Make whitespace display mode work with multibyte characters,
|
||||
and add a few related documentation updates. Changes to
|
||||
do_help(), main(), parse_rcfile(), and display_string(). (DLR)
|
||||
and add a few related documentation updates. New function
|
||||
make_mbstring(); changes to do_help(), main(), parse_rcfile(),
|
||||
and display_string(). (DLR)
|
||||
- cut.c:
|
||||
do_cut_text()
|
||||
- If keep_cutbuffer is FALSE, only blow away the text in the
|
||||
|
53
src/chars.c
53
src/chars.c
@ -297,6 +297,58 @@ char *make_mbchar(int chr, char *chr_mb, int *chr_mb_len)
|
||||
return chr_mb;
|
||||
}
|
||||
|
||||
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
|
||||
/* Convert the string str to a valid multibyte string with the same wide
|
||||
* character values as str. Return the multibyte string. */
|
||||
char *make_mbstring(char *str, char *str_mb)
|
||||
{
|
||||
assert(str != NULL && str_mb != NULL);
|
||||
|
||||
#ifdef NANO_WIDE
|
||||
if (!ISSET(NO_UTF8)) {
|
||||
char *chr_mb = charalloc(MB_CUR_MAX);
|
||||
int chr_mb_len;
|
||||
size_t str_mb_len = 0;
|
||||
|
||||
str_mb = charalloc((MB_CUR_MAX * strlen(str)) + 1);
|
||||
|
||||
while (*str != '\0') {
|
||||
bool bad_char;
|
||||
int i;
|
||||
|
||||
chr_mb_len = parse_mbchar(str, chr_mb, &bad_char, NULL);
|
||||
|
||||
if (bad_char) {
|
||||
char *bad_chr_mb = charalloc(MB_CUR_MAX);
|
||||
int bad_chr_mb_len;
|
||||
|
||||
bad_chr_mb = make_mbchar((unsigned char)chr_mb[0],
|
||||
bad_chr_mb, &bad_chr_mb_len);
|
||||
|
||||
for (i = 0; i < bad_chr_mb_len; i++)
|
||||
str_mb[str_mb_len + i] = bad_chr_mb[i];
|
||||
str_mb_len += bad_chr_mb_len;
|
||||
|
||||
free(bad_chr_mb);
|
||||
} else {
|
||||
for (i = 0; i < chr_mb_len; i++)
|
||||
str_mb[str_mb_len + i] = chr_mb[i];
|
||||
str_mb_len += chr_mb_len;
|
||||
}
|
||||
|
||||
str += chr_mb_len;
|
||||
}
|
||||
|
||||
free(chr_mb);
|
||||
null_at(&str_mb, str_mb_len);
|
||||
|
||||
return str_mb;
|
||||
} else
|
||||
#endif
|
||||
return mallocstrcpy(str_mb, str);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Parse a multibyte character from buf. Return the number of bytes
|
||||
* used. If chr isn't NULL, store the multibyte character in it. If
|
||||
* bad_chr isn't NULL, set it to TRUE if we have a bad multibyte
|
||||
@ -330,6 +382,7 @@ int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t
|
||||
/* Save the multibyte character in chr. */
|
||||
if (chr != NULL) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < buf_mb_len; i++)
|
||||
chr[i] = buf[i];
|
||||
}
|
||||
|
@ -175,6 +175,9 @@ wchar_t control_wrep(wchar_t c);
|
||||
int mbwidth(const char *c);
|
||||
int mb_cur_max(void);
|
||||
char *make_mbchar(int chr, char *chr_mb, int *chr_mb_len);
|
||||
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
|
||||
char *make_mbstring(char *str, char *str_mb);
|
||||
#endif
|
||||
int parse_mbchar(const char *buf, char *chr, bool *bad_chr, size_t
|
||||
*col);
|
||||
size_t move_mbleft(const char *buf, size_t pos);
|
||||
|
@ -570,12 +570,7 @@ void parse_rcfile(FILE *rcstream)
|
||||
#endif
|
||||
#ifndef NANO_SMALL
|
||||
if (strcasecmp(rcopts[i].name, "whitespace") == 0) {
|
||||
/* We use display_string() here so that any
|
||||
* invalid multibyte characters in option
|
||||
* will be converted to valid multibyte
|
||||
* characters in whitespace. */
|
||||
whitespace = display_string(option, 0, 3, FALSE);
|
||||
|
||||
whitespace = make_mbstring(option, whitespace);
|
||||
if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) {
|
||||
rcfile_error(N_("Two single-column characters required"));
|
||||
free(whitespace);
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user