diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-04-19 19:15:01 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-04-19 19:15:01 +0200 |
commit | 146f4482b2f6dccb2a53543dca81cec40e7f6fa4 (patch) | |
tree | 6f6c9cb39c32068bcb321d70a3b4b6700c20d9cd /src/basic/string-util.c | |
parent | string-util: introduce string_replace_char() (diff) | |
download | systemd-146f4482b2f6dccb2a53543dca81cec40e7f6fa4.tar.xz systemd-146f4482b2f6dccb2a53543dca81cec40e7f6fa4.zip |
string-util: introduce strspn_from_end()
Diffstat (limited to 'src/basic/string-util.c')
-rw-r--r-- | src/basic/string-util.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 71ce921288..128aea99c0 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -1174,3 +1174,18 @@ char *string_replace_char(char *str, char old_char, char new_char) { return str; } + +size_t strspn_from_end(const char *str, const char *accept) { + size_t n = 0; + + if (isempty(str)) + return 0; + + if (isempty(accept)) + return 0; + + for (const char *p = str + strlen(str); p > str && strchr(accept, p[-1]); p--) + n++; + + return n; +} |