From 11bcf4b22449d08b61617183c1951db98457653a Mon Sep 17 00:00:00 2001 From: Tomas Heinrich Date: Tue, 1 Jun 2010 08:33:18 +0200 Subject: lineedit: fix column display for wide and combining chars in TAB completion function old new delta unicode_strwidth - 20 +20 read_line_input 4945 4953 +8 unicode_strlen 31 - -31 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/0 up/down: 28/-31) Total: -3 bytes Signed-off-by: Tomas Heinrich Signed-off-by: Denys Vlasenko --- libbb/unicode.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'libbb/unicode.c') diff --git a/libbb/unicode.c b/libbb/unicode.c index b2c28239b..d6fcf7a43 100644 --- a/libbb/unicode.c +++ b/libbb/unicode.c @@ -25,13 +25,15 @@ uint8_t unicode_status; void FAST_FUNC init_unicode(void) { - /* In unicode, this is a one character string */ static const char unicode_0x394[] = { 0xce, 0x94, 0 }; + size_t width; if (unicode_status != UNICODE_UNKNOWN) return; - - unicode_status = unicode_strlen(unicode_0x394) == 1 ? UNICODE_ON : UNICODE_OFF; + /* In unicode, this is a one character string */ +// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused + width = mbstowcs(NULL, unicode_0x394, INT_MAX); + unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF); } #else @@ -954,6 +956,7 @@ int FAST_FUNC unicode_bidi_is_neutral_wchar(wint_t wc) /* The rest is mostly same for libc and for "homegrown" support */ +#if 0 // UNUSED size_t FAST_FUNC unicode_strlen(const char *string) { size_t width = mbstowcs(NULL, string, INT_MAX); @@ -961,6 +964,14 @@ size_t FAST_FUNC unicode_strlen(const char *string) return strlen(string); return width; } +#endif + +size_t FAST_FUNC unicode_strwidth(const char *string) +{ + uni_stat_t uni_stat; + printable_string(&uni_stat, string); + return uni_stat.unicode_width; +} static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags) { -- cgit v1.2.3-55-g6feb