]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/strutils: add functions to replace and remove chars from string
authorKarel Zak <kzak@redhat.com>
Thu, 11 Apr 2019 11:13:06 +0000 (13:13 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 11 Apr 2019 11:13:06 +0000 (13:13 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/strutils.h

index 65d5259db0820d04617f82ee9ec72936508d8495..5584ac5ece0631216f5618fc037f5564e819ed44 100644 (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, ...)