* PATCH: extended ${(#)...}
@ 2006-06-28 14:25 Peter Stephenson
2006-06-28 15:07 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2006-06-28 14:25 UTC (permalink / raw)
To: Zsh hackers list
Another way of getting Unicode characters, this time directly from
numbers in parameters. For example, ${(#):-0xa5} is a Yen sign.
Note this is strictly Unicode, not the current character set.
I was lazy and hijacked \Uxxxxxxxx. Really that junk of getkeystring()
needs separating out.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.66
diff -u -r1.66 expn.yo
--- Doc/Zsh/expn.yo 22 May 2006 09:52:34 -0000 1.66
+++ Doc/Zsh/expn.yo 28 Jun 2006 14:23:10 -0000
@@ -649,6 +649,9 @@
Evaluate the resulting words as numeric expressions and output the
characters corresponding to the resulting integer. Note that this form is
entirely distinct from use of the tt(#) without parentheses.
+
+If the tt(MULTIBYTE) option is set and the number is greater than 127
+(i.e. not an ASCII character) it is treated as a Unicode character.
)
item(tt(%))(
Expand all tt(%) escapes in the resulting words in the same way as in in
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.52
diff -u -r1.52 subst.c
--- Src/subst.c 28 Jun 2006 13:12:55 -0000 1.52
+++ Src/subst.c 28 Jun 2006 14:23:12 -0000
@@ -889,6 +889,29 @@
return 1;
}
+/* Evaluation for (#) flag */
+
+static char *
+substevalchar(char *ptr)
+{
+ zlong ires = mathevali(ptr);
+
+ if (errflag)
+ return NULL;
+ if (isset(MULTIBYTE) && ires > 127) {
+ char buf[10];
+ int dummy;
+
+ /* inefficient: should separate out \U handling from getkeystring */
+ sprintf(buf, "\\U%.8x", (unsigned int)ires);
+ return getkeystring(buf, &dummy, 2, NULL);
+ } else {
+ ptr = zhalloc(2);
+ sprintf(ptr, "%c", (int)ires);
+ return ptr;
+ }
+}
+
/* parameter substitution */
#define isstring(c) ((c) == '$' || (char)(c) == String || (char)(c) == Qstring)
@@ -2269,13 +2292,7 @@
/*
* Evaluate the value numerically and output the result as
* a character.
- *
- * Note this doesn't yet handle Unicode or multibyte characters:
- * that will need handling more generally probably by
- * an additional flag of some sort.
*/
- zlong ires;
-
if (isarr) {
char **aval2, **avptr, **av2ptr;
@@ -2283,20 +2300,14 @@
for (avptr = aval, av2ptr = aval2; *avptr; avptr++, av2ptr++)
{
- ires = mathevali(*avptr);
- if (errflag)
+ if (!(*av2ptr = substevalchar(*avptr)))
return NULL;
- *av2ptr = zhalloc(2);
- sprintf(*av2ptr, "%c", (int)ires);
}
*av2ptr = NULL;
aval = aval2;
} else {
- ires = mathevali(val);
- if (errflag)
+ if (!(val = substevalchar(val)))
return NULL;
- val = zhalloc(2);
- sprintf(val, "%c", (int)ires);
}
}
/*
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: extended ${(#)...}
2006-06-28 14:25 PATCH: extended ${(#)...} Peter Stephenson
@ 2006-06-28 15:07 ` Peter Stephenson
2006-06-28 18:25 ` Nikolai Weibull
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2006-06-28 15:07 UTC (permalink / raw)
To: zsh-workers
Peter Stephenson <pws@csr.com> wrote:
> I was lazy and hijacked \Uxxxxxxxx. Really that junk of getkeystring()
> needs separating out.
Sorry, I was trying to say "chunk". I wasn't commenting on the quality of
the code.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: PATCH: extended ${(#)...}
2006-06-28 15:07 ` Peter Stephenson
@ 2006-06-28 18:25 ` Nikolai Weibull
0 siblings, 0 replies; 3+ messages in thread
From: Nikolai Weibull @ 2006-06-28 18:25 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-workers
On 6/28/06, Peter Stephenson <pws@csr.com> wrote:
> Peter Stephenson <pws@csr.com> wrote:
> > I was lazy and hijacked \Uxxxxxxxx. Really that junk of getkeystring()
> > needs separating out.
> Sorry, I was trying to say "chunk". I wasn't commenting on the quality of
> the code.
Classic example of Freudian mis-typing ;-).
nikolai
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-06-28 18:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-28 14:25 PATCH: extended ${(#)...} Peter Stephenson
2006-06-28 15:07 ` Peter Stephenson
2006-06-28 18:25 ` Nikolai Weibull
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).