Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ${(s::)VAR} vs "${(s::)VAR}"



Aha, I have however worked out what's wrong with what I did:

% foo=":bar:"
% print -l "${(s.:.)foo}"

foo
%

There should be an extra empty element, as there used to be.  So I think
I need the following instead...  Possibly this explains why mul was
relegated to the end in that why.

Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.268
diff -p -u -r1.268 utils.c
--- Src/utils.c	16 Apr 2012 11:26:10 -0000	1.268
+++ Src/utils.c	29 Apr 2012 18:39:39 -0000
@@ -3114,7 +3114,7 @@ wordcount(char *s, char *sep, int mul)
 	r = 1;
 	sl = strlen(sep);
 	for (; (c = findsep(&s, sep, 0)) >= 0; s += sl)
-	    if ((c && *(s + sl)) || mul)
+	    if ((c || mul) && (sl || *(s + sl)))
 		r++;
     } else {
 	char *t = s;
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.67
diff -p -u -r1.67 D04parameter.ztst
--- Test/D04parameter.ztst	22 Apr 2012 18:39:53 -0000	1.67
+++ Test/D04parameter.ztst	29 Apr 2012 18:39:39 -0000
@@ -1292,7 +1292,7 @@
 >in
 >it
 
-  foo="line:with::missing::fields:in:it"
+  foo="line:with::missing::fields:in:it:"
   print -l "${(@s.:.)foo}"
 0:Retention of empty fields in quoted splitting with "@"
 >line
@@ -1303,6 +1303,20 @@
 >fields
 >in
 >it
+>
+
+  str=abcd
+  print -l ${(s..)str}
+  print -l "${(s..)str}"
+0:splitting of strings into characters
+>a
+>b
+>c
+>d
+>a
+>b
+>c
+>d
 
   array=('%' '$' 'j' '*' '$foo')
   print ${array[(i)*]} "${array[(i)*]}"

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author