[Commit] nickle ChangeLog,1.92,1.93 string.5c,1.9,1.10

Bart Massey commit at keithp.com
Sun Nov 7 22:06:47 PST 2004


Committed by: bart

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv4325

Modified Files:
	ChangeLog string.5c 
Log Message:
* string.5c:
Add wordsplit() function.



Index: ChangeLog
===================================================================
RCS file: /local/src/CVS/nickle/ChangeLog,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -d -r1.92 -r1.93
--- ChangeLog	8 Nov 2004 06:01:51 -0000	1.92
+++ ChangeLog	8 Nov 2004 06:06:44 -0000	1.93
@@ -1,3 +1,8 @@
+2004-11-7  Bart Massey <bart at cs.pdx.edu>
+
+	* string.5c:
+	Add wordsplit() function.
+	
 2004-10-19  Keith Packard  <keithp at keithp.com>
 
 	* lex.l:

Index: string.5c
===================================================================
RCS file: /local/src/CVS/nickle/string.5c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- string.5c	8 Jun 2004 09:30:54 -0000	1.9
+++ string.5c	8 Nov 2004 06:06:44 -0000	1.10
@@ -51,6 +51,9 @@
 	return ss;
     }
 
+
+
+
     public string chomp(string s) 
 	/*
 	 * Trim whitespace from begining and end of 's'
@@ -74,6 +77,29 @@
 	return index(String::new(c), s) >= 0;
     }
 
+    public string[*] wordsplit(string s, string sep) 
+    /*
+     * Split 's' at boundaries consisting of sequences of
+     * 'sep' characters, returning an array of the resulting
+     * pieces
+     */
+    {
+	string[...] ss = {};
+	int i = 0; 
+	while(i < length(s)) {
+	    while (i < length(s) && inchars(s[i], sep))
+		i++;
+	    int j = i;
+	    while (j < length(s) && !inchars(s[j], sep))
+		j++;
+	    if (i == j)
+		break;
+	    ss[dim(ss)] = substr(s, i, j - i);
+	    i = j;
+	}
+	return ss;
+    }
+
     public typedef struct { 
 	string oq, cq, qq;
     } quote_context;




More information about the Commit mailing list