]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
break out the string manipulation routines
authorRoger Dingledine <arma@torproject.org>
Wed, 12 Nov 2003 19:34:19 +0000 (19:34 +0000)
committerRoger Dingledine <arma@torproject.org>
Wed, 12 Nov 2003 19:34:19 +0000 (19:34 +0000)
svn:r804

src/common/util.c
src/common/util.h

index c81d0fe87635b6379ae0d8117241f19d0f8d1cbf..af0f32231a59c1fe85d9a179ee9d8e35757e301e 100644 (file)
@@ -48,6 +48,43 @@ char *tor_strdup(const char *s) {
   return dup;
 }
 
+/*
+ *    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 @@ int switch_id(char *user, char *group) {
 
   return -1;
 }
+
index 15893f1608f3e3a37a892835a76f30954344e0a1..f1c744b01bdf6cdcedbdd1eb6c6d442a0cede08c 100644 (file)
@@ -37,6 +37,10 @@ void *tor_realloc(void *ptr, size_t size);
 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);