]> mj.ucw.cz Git - libucw.git/blobdiff - lib/wordsplit.c
Use `char *' instead of `byte *' for strings
[libucw.git] / lib / wordsplit.c
index e79812d18a7bd352ed3bb6a045fdf98745abbd29..70984ab58fbe68e02bc7d90ead4828fb53745cf9 100644 (file)
@@ -1,14 +1,34 @@
 /*
- *     Sherlock Library -- Word Splitting
+ *     UCW Library -- Word Splitting
  *
- *     (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
+ *     (c) 1997 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
-#include <stdio.h>
-
 #include "lib/lib.h"
 #include "lib/chartype.h"
 
+#include <string.h>
+
+int
+sepsplit(byte *str, uns sep, byte **rec, uns max)
+{
+  uns cnt = 0;
+  while (1)
+  {
+    rec[cnt++] = str;
+    str = strchr(str, sep);
+    if (!str)
+      return cnt;
+    if (cnt >= max)
+      return -1;
+    *str++ = 0;
+  }
+}
+
 int
 wordsplit(byte *src, byte **dst, uns max)
 {