From 7f53c1c16e7654427dc884e528f5e2d201c15fc5 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 15 Nov 2004 08:32:38 +0000 Subject: [PATCH] fix \l and \u in a multi-byte configuration 2004-11-15 Paolo Bonzini * sed/execute.c (str_append_modified): Copy the first character when using \l or \u in a multi-byte configuration. Use WCRTOMB instead of wcrtomb. * sed/sed.h (WCRTOMB): New. git-archimport-id: bonzini@gnu.org--2004b/sed--stable--4.1--patch-19 --- ChangeLog | 11 +++++++++-- sed/execute.c | 4 +++- sed/sed.h | 8 ++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 979e9cf..13c8660 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,11 @@ -2004-11-11 Paolo Bonzini + + * sed/execute.c (str_append_modified): Copy the first character + when using \l or \u in a multi-byte configuration. Use + WCRTOMB instead of wcrtomb. + * sed/sed.h (WCRTOMB): New. + +2004-11-11 Paolo Bonzini * tst-rxspecer.c: Do not mix instructions and declarations. @@ -6,7 +13,7 @@ gettext, to avoid breakage under Solaris. * sed/sed.c: do not include locale.h. -2004-11-03 Paolo Bonzini * bug-regex11.c: Improve portability. * bug-regex12.c: Improve portability. diff --git a/sed/execute.c b/sed/execute.c index 005a063..2249a24 100644 --- a/sed/execute.c +++ b/sed/execute.c @@ -313,6 +313,8 @@ str_append_modified(to, string, length, type) type &= ~(REPL_LOWERCASE_FIRST | REPL_UPPERCASE_FIRST); if (type == REPL_ASIS) { + n = WCRTOMB (to->active + to->length, wc, &to->mbstate); + to->length += n; str_append(to, string, length); return; } @@ -324,7 +326,7 @@ str_append_modified(to, string, length, type) wc = towlower(wc); /* Copy the new wide character to the end of the string. */ - n = wcrtomb (to->active + to->length, wc, &to->mbstate); + n = WCRTOMB (to->active + to->length, wc, &to->mbstate); to->length += n; if (n == -1) { diff --git a/sed/sed.h b/sed/sed.h index 01969d9..91587a9 100644 --- a/sed/sed.h +++ b/sed/sed.h @@ -233,9 +233,17 @@ extern int mb_cur_max; (mb_cur_max == 1 ? \ (*(pwc) = btowc (*(unsigned char *) (s)), 1) : \ mbrtowc ((pwc), (s), (n), (ps))) + +#define WCRTOMB(s, wc, ps) \ + (mb_cur_max == 1 ? \ + (*(s) = wctob ((wint_t) (wc)), 1) : \ + wcrtomb ((s), (wc), (ps))) #else #define MBRTOWC(pwc, s, n, ps) \ mbrtowc ((pwc), (s), (n), (ps)) + +#define WCRTOMB(s, wc, ps) \ + wcrtomb ((s), (wc), (ps)) #endif #define MBRLEN(s, n, ps) \