From c1a9d70936756887c7cdf55b5b32826df72b9d52 Mon Sep 17 00:00:00 2001 From: Norihiro Tanaka Date: Sun, 18 Sep 2016 17:46:57 +0900 Subject: [PATCH] sed: use cache provided by localeinfo for mbrtowc and mbrlen * sed/sed.h (MBRTOWC, MBRLEN): Use cache provided by localeinfo. (MBRTOWC, MBRLEN): Use the cache. --- sed/sed.h | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sed/sed.h b/sed/sed.h index 083baae..9ebc815 100644 --- a/sed/sed.h +++ b/sed/sed.h @@ -247,8 +247,8 @@ extern bool is_utf8; extern bool sandbox; #define MBRTOWC(pwc, s, n, ps) \ - (mb_cur_max == 1 ? \ - (*(pwc) = btowc (*(unsigned char *) (s)), 1) : \ + (localeinfo.sbclen[*(unsigned char *) (s)] == 1 ? \ + (*(pwc) = localeinfo.sbctowc[*(unsigned char *) (s)], 1) : \ mbrtowc ((pwc), (s), (n), (ps))) #define WCRTOMB(s, wc, ps) \ @@ -260,7 +260,8 @@ extern bool sandbox; (mb_cur_max == 1 ? 1 : mbsinit ((s))) #define MBRLEN(s, n, ps) \ - (mb_cur_max == 1 ? 1 : mbrtowc (NULL, s, n, ps)) + (localeinfo.sbclen[*(unsigned char *) (s)] == 1 ? \ + 1 : mbrtowc (NULL, s, n, ps)) #define IS_MB_CHAR(ch, ps) \ (mb_cur_max == 1 ? 0 : is_mb_char (ch, ps)) -- 1.7.1