]> git.cworth.org Git - notmuch/commitdiff
util: make sanitize string available in string util for reuse
authorJani Nikula <jani@nikula.org>
Mon, 3 Feb 2014 19:51:43 +0000 (21:51 +0200)
committerDavid Bremner <david@tethera.net>
Sun, 9 Mar 2014 13:13:30 +0000 (10:13 -0300)
No functional changes.

notmuch-search.c
util/string-util.c
util/string-util.h

index 0262eb30a1f96829141b4fd6cc7b20ecf141ff2e..bc9be4593ecc0a06b34e82bab62b9a034ffb9f40 100644 (file)
@@ -30,25 +30,6 @@ typedef enum {
     OUTPUT_TAGS
 } output_t;
 
-static char *
-sanitize_string (const void *ctx, const char *str)
-{
-    char *out, *loop;
-
-    if (NULL == str)
-       return NULL;
-
-    loop = out = talloc_strdup (ctx, str);
-
-    for (; *loop; loop++) {
-       if (*loop == '\t' || *loop == '\n')
-           *loop = ' ';
-       else if ((unsigned char)(*loop) < 32)
-           *loop = '?';
-    }
-    return out;
-}
-
 /* Return two stable query strings that identify exactly the matched
  * and unmatched messages currently in thread.  If there are no
  * matched or unmatched messages, the returned buffers will be
index a5622d7a209dfee96b90e5e3dbd698cc455ad6df..9e2f728fc6750c586f3effed3ecac5673ea980e0 100644 (file)
@@ -37,6 +37,28 @@ strtok_len (char *s, const char *delim, size_t *len)
     return *len ? s : NULL;
 }
 
+char *
+sanitize_string (const void *ctx, const char *str)
+{
+    char *out, *loop;
+
+    if (! str)
+       return NULL;
+
+    out = talloc_strdup (ctx, str);
+    if (! out)
+       return NULL;
+
+    for (loop = out; *loop; loop++) {
+       if (*loop == '\t' || *loop == '\n')
+           *loop = ' ';
+       else if ((unsigned char)(*loop) < 32)
+           *loop = '?';
+    }
+
+    return out;
+}
+
 static int
 is_unquoted_terminator (unsigned char c)
 {
index 0194607ee52877b9c1adcfc96933d84aab9658f1..8a3ad19eae6e9808a319aec043e78089b792d41e 100644 (file)
 
 char *strtok_len (char *s, const char *delim, size_t *len);
 
+/* Return a talloced string with str sanitized.
+ *
+ * Whitespace characters (tabs and newlines) are replaced with spaces,
+ * non-printable characters with question marks.
+ */
+char *sanitize_string (const void *ctx, const char *str);
+
 /* Construct a boolean term query with the specified prefix (e.g.,
  * "id") and search term, quoting term as necessary.  Specifically, if
  * term contains any non-printable ASCII characters, non-ASCII