aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-08-13 09:57:44 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-08-13 09:57:44 +0200
commitc538d5bcc304d1ac99783de2337937c70a7013c7 (patch)
treeaf410434f444a73c37b4df6da68c356f02047106 /shell
parent45b4ecc8689d1291b01793efab3ac25125e14e48 (diff)
downloadbusybox-w32-c538d5bcc304d1ac99783de2337937c70a7013c7.tar.gz
busybox-w32-c538d5bcc304d1ac99783de2337937c70a7013c7.tar.bz2
busybox-w32-c538d5bcc304d1ac99783de2337937c70a7013c7.zip
hush: make ${#var} unicode-aware
This mimics bash Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c29
-rw-r--r--shell/hush_test/hush-misc/unicode1.right3
-rwxr-xr-xshell/hush_test/hush-misc/unicode1.tests13
3 files changed, 35 insertions, 10 deletions
diff --git a/shell/hush.c b/shell/hush.c
index e1d0ece29..7d3547110 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1977,6 +1977,22 @@ static struct variable *set_vars_and_save_old(char **strings)
1977 1977
1978 1978
1979/* 1979/*
1980 * Unicode helper
1981 */
1982static void reinit_unicode_for_hush(void)
1983{
1984 /* Unicode support should be activated even if LANG is set
1985 * _during_ shell execution, not only if it was set when
1986 * shell was started. Therefore, re-check LANG every time:
1987 */
1988 const char *s = get_local_var_value("LC_ALL");
1989 if (!s) s = get_local_var_value("LC_CTYPE");
1990 if (!s) s = get_local_var_value("LANG");
1991 reinit_unicode(s);
1992}
1993
1994
1995/*
1980 * in_str support 1996 * in_str support
1981 */ 1997 */
1982static int FAST_FUNC static_get(struct in_str *i) 1998static int FAST_FUNC static_get(struct in_str *i)
@@ -2042,15 +2058,7 @@ static void get_user_input(struct in_str *i)
2042 /* Enable command line editing only while a command line 2058 /* Enable command line editing only while a command line
2043 * is actually being read */ 2059 * is actually being read */
2044 do { 2060 do {
2045 /* Unicode support should be activated even if LANG is set 2061 reinit_unicode_for_hush();
2046 * _during_ shell execution, not only if it was set when
2047 * shell was started. Therefore, re-check LANG every time:
2048 */
2049 const char *s = get_local_var_value("LC_ALL");
2050 if (!s) s = get_local_var_value("LC_CTYPE");
2051 if (!s) s = get_local_var_value("LANG");
2052 reinit_unicode(s);
2053
2054 G.flag_SIGINT = 0; 2062 G.flag_SIGINT = 0;
2055 /* buglet: SIGINT will not make new prompt to appear _at once_, 2063 /* buglet: SIGINT will not make new prompt to appear _at once_,
2056 * only after <Enter>. (^C will work) */ 2064 * only after <Enter>. (^C will work) */
@@ -5028,8 +5036,9 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha
5028 5036
5029 /* Handle any expansions */ 5037 /* Handle any expansions */
5030 if (exp_op == 'L') { 5038 if (exp_op == 'L') {
5039 reinit_unicode_for_hush();
5031 debug_printf_expand("expand: length(%s)=", val); 5040 debug_printf_expand("expand: length(%s)=", val);
5032 val = utoa(val ? strlen(val) : 0); 5041 val = utoa(val ? unicode_strlen(val) : 0);
5033 debug_printf_expand("%s\n", val); 5042 debug_printf_expand("%s\n", val);
5034 } else if (exp_op) { 5043 } else if (exp_op) {
5035 if (exp_op == '%' || exp_op == '#') { 5044 if (exp_op == '%' || exp_op == '#') {
diff --git a/shell/hush_test/hush-misc/unicode1.right b/shell/hush_test/hush-misc/unicode1.right
new file mode 100644
index 000000000..d3bbbf697
--- /dev/null
+++ b/shell/hush_test/hush-misc/unicode1.right
@@ -0,0 +1,3 @@
11
21
3Ok
diff --git a/shell/hush_test/hush-misc/unicode1.tests b/shell/hush_test/hush-misc/unicode1.tests
new file mode 100755
index 000000000..8788ba910
--- /dev/null
+++ b/shell/hush_test/hush-misc/unicode1.tests
@@ -0,0 +1,13 @@
1LANG=en_US.UTF-8
2
3# A combining character U+300
4a=`printf "\xcc\x80"`
5# Should print 1
6echo ${#a}
7
8# A Japanese katakana charachter U+30a3
9a=`printf "\xe3\x82\xa3"`
10# Should print 1
11echo ${#a}
12
13echo Ok