[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

split ''



OK, here's another grotesque modification to es.  This one makes it
possible to split a string into a list of its single characters, making
%split symmetric with %flatten with respect to separator ''.

	;; a = <>{%split '' 'xyz'}
	;; echo $a
	x y z

The %fsplit operator isn't affected, so it would yield "xyz" in the above
example - I don't know if that's good or bad, it just came out that way.
I'm not dying to use this for some particular problem, it just seems
like a useful way to approach some kinds of string manipulations.  Also
I haven't thought very hard about what circumstances could produce this
situation, other than to verify that `{} still works.

The patch below is against version 0.67, which is what's available on
white.utcs.toronto.edu.  I gather there are more recent versions -
the discussion yesterday about formatting "if" blocks apparently involved
more recent versions, since 0.67 still requires the } { to be on the same
line, parenthesized or not.

	Donn Cave, University Computing Services, University of Washington
	donn@cac.washington.edu

-------------------------------
*** split.c.dist	Thu Oct  1 00:25:38 1992
--- split.c	Thu Oct 15 11:01:13 1992
***************
*** 95,100 ****
--- 95,108 ----
  			bufend = bufp + buffer.len;
  			*bufp++ = c;
  			assert(bufp + 1 < bufend);
+ 			if (!ifs[0]) {
+ 				Term *term;
+ 				*bufp++ = '\0';
+ 				term = mkterm(sealbuffer(bufp), NULL);
+ 				value = mklist(term, value);
+ 				bufend = bufp = NULL;
+ 				inword = FALSE;
+ 			}
  		}
  	}