mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
util: make sanitize string available in string util for reuse
No functional changes.
This commit is contained in:
parent
998a8a95c3
commit
029790d3ff
3 changed files with 29 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,13 @@
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue