mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-22 17:34:54 +01:00
util: Const version of strtok_len
Because of limitations in the C type system, we can't a strtok_len that can work on both const string and non-const strings. The C library solves this by taking a const char* and returning a char* in functions like this (e.g., strchr), but that's not const-safe. Solve it by introducing strtok_len_c, a version of strtok_len for const strings.
This commit is contained in:
parent
c95a398deb
commit
9f0f30f7de
2 changed files with 11 additions and 0 deletions
|
@ -37,6 +37,14 @@ strtok_len (char *s, const char *delim, size_t *len)
|
|||
return *len ? s : NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
strtok_len_c (const char *s, const char *delim, size_t *len)
|
||||
{
|
||||
/* strtok_len is already const-safe, but we can't express both
|
||||
* versions in the C type system. */
|
||||
return strtok_len ((char*)s, delim, len);
|
||||
}
|
||||
|
||||
char *
|
||||
sanitize_string (const void *ctx, const char *str)
|
||||
{
|
||||
|
|
|
@ -23,6 +23,9 @@ extern "C" {
|
|||
|
||||
char *strtok_len (char *s, const char *delim, size_t *len);
|
||||
|
||||
/* Const version of strtok_len. */
|
||||
const char *strtok_len_c (const char *s, const char *delim, size_t *len);
|
||||
|
||||
/* Return a talloced string with str sanitized.
|
||||
*
|
||||
* Whitespace characters (tabs and newlines) are replaced with spaces,
|
||||
|
|
Loading…
Reference in a new issue