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

[or-cvs] break out the string manipulation routines



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/common

Modified Files:
	util.c util.h 
Log Message:
break out the string manipulation routines


Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- util.c	10 Nov 2003 06:28:52 -0000	1.38
+++ util.c	12 Nov 2003 19:34:19 -0000	1.39
@@ -49,6 +49,43 @@
 }
 
 /*
+ *    String manipulation
+ */
+
+/* return the first char of s that is not whitespace and not a comment */
+char *eat_whitespace(char *s) {
+  assert(s);
+
+  while(isspace(*s) || *s == '#') {
+    while(isspace(*s))
+      s++;
+    if(*s == '#') { /* read to a \n or \0 */
+      while(*s && *s != '\n')
+        s++;
+      if(!*s)
+        return s;
+    }
+  }
+  return s;
+}
+
+char *eat_whitespace_no_nl(char *s) {
+  while(*s == ' ' || *s == '\t') 
+    ++s;
+  return s;
+}
+
+/* return the first char of s that is whitespace or '#' or '\0 */
+char *find_whitespace(char *s) {
+  assert(s);
+
+  while(*s && !isspace(*s) && *s != '#')
+    s++;
+
+  return s;
+}
+
+/*
  *    Time
  */
 
@@ -653,3 +690,4 @@
 
   return -1;
 }
+

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- util.h	22 Oct 2003 11:21:29 -0000	1.21
+++ util.h	12 Nov 2003 19:34:19 -0000	1.22
@@ -37,6 +37,10 @@
 char *tor_strdup(const char *s);
 #define tor_free(p) do {if(p) {free(p); (p)=NULL;}} while(0)
 
+char *eat_whitespace(char *s);
+char *eat_whitespace_no_nl(char *s);
+char *find_whitespace(char *s);
+
 void tor_gettimeofday(struct timeval *timeval);
 long tv_udiff(struct timeval *start, struct timeval *end);
 void tv_addms(struct timeval *a, long ms);