summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorKarel Zak2019-04-11 13:13:06 +0200
committerKarel Zak2019-04-11 13:13:06 +0200
commit3c4ff2dc9d3fa334623b02b492b30a31dadb81e4 (patch)
tree8fec476bfc6cb9d51a86b7642cce1898a0d77164 /include
parentlib/fileutils: add xreaddir() (diff)
downloadkernel-qcow2-util-linux-3c4ff2dc9d3fa334623b02b492b30a31dadb81e4.tar.gz
kernel-qcow2-util-linux-3c4ff2dc9d3fa334623b02b492b30a31dadb81e4.tar.xz
kernel-qcow2-util-linux-3c4ff2dc9d3fa334623b02b492b30a31dadb81e4.zip
include/strutils: add functions to replace and remove chars from string
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/strutils.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/strutils.h b/include/strutils.h
index 65d5259db..5584ac5ec 100644
--- a/include/strutils.h
+++ b/include/strutils.h
@@ -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, ...)