[PATCH v2 3/7] util: make sanitize string available in string util for reuse

Mark Walters markwalters1009 at gmail.com
Sun Feb 2 10:24:09 PST 2014


On Sat, 30 Nov 2013, Jani Nikula <jani at nikula.org> wrote:
> No functional changes.
> ---
>  notmuch-search.c   | 19 -------------------
>  util/string-util.c | 22 ++++++++++++++++++++++
>  util/string-util.h |  7 +++++++
>  3 files changed, 29 insertions(+), 19 deletions(-)
>
> diff --git a/notmuch-search.c b/notmuch-search.c
> index 11cd6ee..8b6940a 100644
> --- a/notmuch-search.c
> +++ b/notmuch-search.c
> @@ -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
> diff --git a/util/string-util.c b/util/string-util.c
> index a5622d7..9e2f728 100644
> --- a/util/string-util.c
> +++ b/util/string-util.c
> @@ -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)
>  {
> diff --git a/util/string-util.h b/util/string-util.h
> index 0194607..228420d 100644
> --- a/util/string-util.h
> +++ b/util/string-util.h
> @@ -19,6 +19,13 @@
>  
>  char *strtok_len (char *s, const char *delim, size_t *len);
>  
> +/* Return a talloced string with str sanitized.
> + *
> + * Whitespace (tabs and newlines) is replaced with spaces,
> + * non-printable characters with question marks.
> + */

A complete triviality but I would prefer "Whitespace characters (tabs
and newlines) are replaced with spaces..." just to emphasise that e.g.
multiple tabs are replaced by multiple spaces.

Best wishes

Mark






> +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
> -- 
> 1.8.4.2
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


More information about the notmuch mailing list