From aa167556cd2954bb9a9fb0a005178462087a4600 Mon Sep 17 00:00:00 2001 From: Tomas Heinrich Date: Fri, 26 Mar 2010 13:13:24 +0100 Subject: unicode: optional table for better handling of neutral bidi chars Off: function old new delta unicode_bidi_isrtl - 55 +55 isrtl_str 51 65 +14 unicode_isrtl 55 - -55 read_line_input 5003 4937 -66 ------------------------------------------------------------------------------ (add/remove: 1/4 grow/shrink: 1/1 up/down: 69/-121) Total: -52 bytes On: function old new delta static.neutral_b - 320 +320 static.neutral_p - 142 +142 unicode_bidi_isrtl - 55 +55 unicode_bidi_is_neutral_wchar - 55 +55 isrtl_str 51 59 +8 unicode_isrtl 55 - -55 read_line_input 5003 4937 -66 ------------------------------------------------------------------------------ (add/remove: 4/4 grow/shrink: 1/1 up/down: 580/-121) Total: 459 bytes Signed-off-by: Tomas Heinrich Signed-off-by: Denys Vlasenko --- libbb/lineedit.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'libbb/lineedit.c') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index be022e8..38a09cb 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1742,9 +1742,10 @@ static int lineedit_read_key(char *read_key_buffer) static int isrtl_str(void) { int idx = cursor; - while (command_ps[idx] >= ' ' && command_ps[idx] < 127 && !isalpha(command_ps[idx])) + + while (idx < command_len && unicode_bidi_is_neutral_wchar(command_ps[idx])) idx++; - return unicode_isrtl(command_ps[idx]); + return unicode_bidi_isrtl(command_ps[idx]); } #else # define isrtl_str() 0 @@ -2220,19 +2221,18 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li command_ps[cursor] = ic; command_ps[cursor + 1] = BB_NUL; cmdedit_set_out_char(' '); - if (unicode_isrtl(ic)) + if (unicode_bidi_isrtl(ic)) input_backward(1); } else { /* In the middle, insert */ - /* is char right-to-left, or "neutral" one (e.g. comma) added to rtl text? */ - int rtl = ENABLE_UNICODE_BIDI_SUPPORT ? (unicode_isrtl(ic) || (ic < 127 && !isalpha(ic) && isrtl_str())) : 0; int sc = cursor; memmove(command_ps + sc + 1, command_ps + sc, (command_len - sc) * sizeof(command_ps[0])); command_ps[sc] = ic; - if (!rtl) - sc++; + /* is right-to-left char, or neutral one (e.g. comma) was just added to rtl text? */ + if (!isrtl_str()) + sc++; /* no */ /* rewrite from cursor */ input_end(); /* to prev x pos + 1 */ -- cgit v1.1