diff options
author | Tomas Heinrich <heinrich.tomas@gmail.com> | 2010-06-01 08:33:18 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-01 08:33:18 +0200 |
commit | 11bcf4b22449d08b61617183c1951db98457653a (patch) | |
tree | 34d1983e1f1b5eb38d8c764ab9f2b406404b862e /libbb/unicode.c | |
parent | 39a04f71ca8ccf81de2cdbd538df519cf34ef2e6 (diff) | |
download | busybox-w32-11bcf4b22449d08b61617183c1951db98457653a.tar.gz busybox-w32-11bcf4b22449d08b61617183c1951db98457653a.tar.bz2 busybox-w32-11bcf4b22449d08b61617183c1951db98457653a.zip |
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 <heinrich.tomas@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/unicode.c')
-rw-r--r-- | libbb/unicode.c | 17 |
1 files changed, 14 insertions, 3 deletions
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; | |||
25 | 25 | ||
26 | void FAST_FUNC init_unicode(void) | 26 | void FAST_FUNC init_unicode(void) |
27 | { | 27 | { |
28 | /* In unicode, this is a one character string */ | ||
29 | static const char unicode_0x394[] = { 0xce, 0x94, 0 }; | 28 | static const char unicode_0x394[] = { 0xce, 0x94, 0 }; |
29 | size_t width; | ||
30 | 30 | ||
31 | if (unicode_status != UNICODE_UNKNOWN) | 31 | if (unicode_status != UNICODE_UNKNOWN) |
32 | return; | 32 | return; |
33 | 33 | /* In unicode, this is a one character string */ | |
34 | unicode_status = unicode_strlen(unicode_0x394) == 1 ? UNICODE_ON : UNICODE_OFF; | 34 | // can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused |
35 | width = mbstowcs(NULL, unicode_0x394, INT_MAX); | ||
36 | unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF); | ||
35 | } | 37 | } |
36 | 38 | ||
37 | #else | 39 | #else |
@@ -954,6 +956,7 @@ int FAST_FUNC unicode_bidi_is_neutral_wchar(wint_t wc) | |||
954 | 956 | ||
955 | /* The rest is mostly same for libc and for "homegrown" support */ | 957 | /* The rest is mostly same for libc and for "homegrown" support */ |
956 | 958 | ||
959 | #if 0 // UNUSED | ||
957 | size_t FAST_FUNC unicode_strlen(const char *string) | 960 | size_t FAST_FUNC unicode_strlen(const char *string) |
958 | { | 961 | { |
959 | size_t width = mbstowcs(NULL, string, INT_MAX); | 962 | size_t width = mbstowcs(NULL, string, INT_MAX); |
@@ -961,6 +964,14 @@ size_t FAST_FUNC unicode_strlen(const char *string) | |||
961 | return strlen(string); | 964 | return strlen(string); |
962 | return width; | 965 | return width; |
963 | } | 966 | } |
967 | #endif | ||
968 | |||
969 | size_t FAST_FUNC unicode_strwidth(const char *string) | ||
970 | { | ||
971 | uni_stat_t uni_stat; | ||
972 | printable_string(&uni_stat, string); | ||
973 | return uni_stat.unicode_width; | ||
974 | } | ||
964 | 975 | ||
965 | static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags) | 976 | static char* FAST_FUNC unicode_conv_to_printable2(uni_stat_t *stats, const char *src, unsigned width, int flags) |
966 | { | 977 | { |