include/strutils: add functions to replace and remove chars from string

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-04-11 13:13:06 +02:00
parent 7761bd3bb6
commit 3c4ff2dc9d
1 changed files with 16 additions and 0 deletions

View File

@ -248,6 +248,22 @@ static inline size_t ltrim_whitespace(unsigned char *str)
return len;
}
static inline void strrep(char *s, int find, int replace)
{
while (s && *s && (s = strchr(s, find)) != NULL)
*s++ = replace;
}
static inline void strrem(char *s, int rem)
{
char *p;
for (p = s; s && *s; s++) {
if (*s != rem)
*p++ = *s;
}
}
extern char *strnappend(const char *s, const char *suffix, size_t b);
extern char *strappend(const char *s, const char *suffix);
extern char *strfappend(const char *s, const char *format, ...)