]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a function to remove a set of characters from a string
authorNick Mathewson <nickm@torproject.org>
Wed, 6 Oct 2004 13:26:37 +0000 (13:26 +0000)
committerNick Mathewson <nickm@torproject.org>
Wed, 6 Oct 2004 13:26:37 +0000 (13:26 +0000)
svn:r2420

src/common/util.c

index 6dd06c7ce65fbaa07119a22dbdd4c50ec67885ad..dde5c7c9147f7e0f400f7fc3b0ff1c95db25c923 100644 (file)
@@ -200,6 +200,21 @@ char *tor_strndup(const char *s, size_t n) {
   return dup;
 }
 
+/** Remove from the string <b>s</b> every character which appears in
+ * <b>strip</b>.  Return the number of characters removed. */
+int tor_strstrip(char *s, const char *strip)
+{
+  char *read = s;
+  while (*read) {
+    if (strchr(strip, *read)) {
+      ++read;
+    } else {
+      *s++ = *read++;
+    }
+  }
+  *s = '\0';
+  return read-s;
+}
 
 #ifndef UNALIGNED_INT_ACCESS_OK
 /**