mirror of
https://github.com/systemd/systemd.git
synced 2026-07-13 10:59:49 +00:00
string-util: introduce string_replace_char()
This commit is contained in:
@@ -1162,3 +1162,15 @@ bool streq_skip_trailing_chars(const char *s1, const char *s2, const char *ok) {
|
||||
|
||||
return in_charset(s1, ok) && in_charset(s2, ok);
|
||||
}
|
||||
|
||||
char *string_replace_char(char *str, char old_char, char new_char) {
|
||||
assert(str);
|
||||
assert(old_char != '\0');
|
||||
assert(new_char != '\0');
|
||||
assert(old_char != new_char);
|
||||
|
||||
for (char *p = strchr(str, old_char); p; p = strchr(p + 1, old_char))
|
||||
*p = new_char;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user