about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/arith.yo15
-rw-r--r--Src/math.c16
-rw-r--r--Src/utils.c11
-rw-r--r--Test/D07multibyte.ztst10
5 files changed, 48 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 7f8a29e2f..cbf74852c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-06-30  Peter Stephenson  <pws@csr.com>
+
+	* 22529: Doc/Zsh/arith.yo, Src/math.c, Src/utils.c,
+	Test/D07multibyte.ztst: multibyte conversion in math expressions.
+
 2006-06-28  Peter Stephenson  <pws@csr.com>
 
 	* 22526: Doc/Zsh/expn.yo, Src/subst.c: enhance${(#)...} to output
diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo
index 33ca09c20..f13cad987 100644
--- a/Doc/Zsh/arith.yo
+++ b/Doc/Zsh/arith.yo
@@ -129,13 +129,14 @@ the tt(zmodload) builtin to provide standard floating point mathematical
 functions.
 
 An expression of the form `tt(##)var(x)' where var(x) is any character
-sequence such as `tt(a)', `tt(^A)', or `tt(\M-\C-x)' gives the ASCII
-value of this character and an expression of the form `tt(#)var(foo)'
-gives the ASCII value of the first character of the value of the
-parameter var(foo).  Note that this is different from the expression
-`tt($#)var(foo)', a standard parameter substitution which gives the
-length of the parameter var(foo).  `tt(#\)' is accepted instead of
-`tt(##)', but its use is deprecated.
+sequence such as `tt(a)', `tt(^A)', or `tt(\M-\C-x)' gives the value of
+this character and an expression of the form `tt(#)var(foo)' gives the
+value of the first character of the contents of the parameter var(foo).
+Character values are according to the character set used in the current
+locale; for multibyte character handling the option tt(MULTIBYTE) must be
+set.  Note that this form is different from `tt($#)var(foo)', a standard
+parameter substitution which gives the length of the parameter var(foo).
+`tt(#\)' is accepted instead of `tt(##)', but its use is deprecated.
 
 Named parameters and subscripted arrays can be referenced by name within an
 arithmetic expression without using the parameter expansion syntax.  For
diff --git a/Src/math.c b/Src/math.c
index 336416597..bd48288ec 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -549,8 +549,20 @@ getcvar(char *s)
     queue_signals();
     if (!(t = getsparam(s)))
 	mn.u.l = 0;
-    else
-        mn.u.l = STOUC(*t == Meta ? t[1] ^ 32 : *t);
+    else {
+#ifdef MULTIBYTE_SUPPORT
+	if (isset(MULTIBYTE)) {
+	    wint_t wc;
+	    (void)mb_metacharlenconv(t, &wc);
+	    if (wc != WEOF) {
+		mn.u.l = (zlong)wc;
+		unqueue_signals();
+		return mn;
+	    }
+	}
+#endif
+	mn.u.l = STOUC(*t == Meta ? t[1] ^ 32 : *t);
+    }
     unqueue_signals();
     return mn;
 }
diff --git a/Src/utils.c b/Src/utils.c
index 32f6ae336..75a736596 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -4410,6 +4410,17 @@ getkeystring(char *s, int *len, int fromwhere, int *misc)
 		   (fromwhere == 2 || fromwhere == 5 || fromwhere == 6)) {
 	    control = 1;
 	    continue;
+#ifdef MULTIBYTE_SUPPORT
+	} else if (fromwhere == 6 && isset(MULTIBYTE) && STOUC(*s) > 127) {
+	    wint_t wc;
+	    int len;
+	    len = mb_metacharlenconv(s, &wc);
+	    if (wc != WEOF) {
+		*misc = (int)wc;
+		return s + len;
+	    }
+#endif
+
 	} else if (*s == Meta)
 	    *t++ = *++s ^ 32;
 	else
diff --git a/Test/D07multibyte.ztst b/Test/D07multibyte.ztst
index 4d364d879..c30bf1172 100644
--- a/Test/D07multibyte.ztst
+++ b/Test/D07multibyte.ztst
@@ -155,3 +155,13 @@
 >ølaf ødd øpened án encyclopædia
 >Ølaf Ødd Øpened Án Encyclopædia
 >Ølaf Ødd Øpened Án Encyclopædia
+
+  print $(( ##¥ ))
+  pound=£
+  print $(( #pound ))
+  alpha=α
+  print $(( ##α )) $(( #alpha ))
+0:Conversion to Unicode in mathematical expressions
+>165
+>163
+>945 945