[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Make split(..., NULL) split on horizontal space; fix bug wi...



Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv342/src/common

Modified Files:
	container.c 
Log Message:
Make split(..., NULL) split on horizontal space; fix bug with tabs in config file.

Index: container.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/container.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- container.c	8 Dec 2004 00:40:01 -0000	1.14
+++ container.c	16 Dec 2004 21:10:50 -0000	1.15
@@ -247,7 +247,7 @@
  * trailing space from each entry.  If
  * <b>flags</b>&amp;SPLIT_IGNORE_BLANK is true, remove any entries of
  * length 0.  If max>0, divide the string into no more than <b>max</b>
- * pieces.
+ * pieces.  If <b>sep</b> is NULL, split on any sequence of horizontal space.
  */
 int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep,
                            int flags, int max)
@@ -257,7 +257,6 @@
 
   tor_assert(sl);
   tor_assert(str);
-  tor_assert(sep);
 
   cp = str;
   while (1) {
@@ -267,15 +266,23 @@
 
     if (max>0 && n == max-1) {
       end = strchr(cp,'\0');
-    } else {
+    } else if (sep) {
       end = strstr(cp,sep);
       if (!end)
         end = strchr(cp,'\0');
+    } else {
+      for (end = cp; *end && *end != '\t' && *end != ' '; ++end)
+        ;
     }
+
     if (!*end) {
       next = NULL;
-    } else {
+    } else if (sep) {
       next = end+strlen(sep);
+    } else {
+      next = end+1;
+      while (*next == '\t' || *next == ' ')
+        ++next;
     }
 
     if (flags&SPLIT_SKIP_SPACE) {