diff options
author | Rob Barnes <robbarnes@google.com> | 2021-07-27 15:29:51 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-09 16:43:13 +0000 |
commit | b82517a459d8e9394a1ea4a2a0148232c61f45e5 (patch) | |
tree | 9d37d20245dae1e41e074c80ae064c5823d12003 /common | |
parent | 48f83b8b045e4105c4811bf8982cc109e7408b9e (diff) | |
download | chrome-ec-b82517a459d8e9394a1ea4a2a0148232c61f45e5.tar.gz |
util: Add strcspn
Add the standard string function strcspn. strcspn calculates the length
of the initial segment of s which consists entirely of bytes not in
reject.
BUG=None
TEST=make run-utils_str
BRANCH=None
Signed-off-by: Rob Barnes <robbarnes@google.com>
Change-Id: I3eb9a4fff42cb0fdcdb288d00f8070e0f22b2179
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3057730
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/util.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/common/util.c b/common/util.c index 152c8370d0..7ed4c45c53 100644 --- a/common/util.c +++ b/common/util.c @@ -19,6 +19,17 @@ __stdlib_compat size_t strlen(const char *s) return len; } +__stdlib_compat size_t strcspn(const char *s, const char *reject) +{ + size_t i; + size_t reject_len = strlen(reject); + + for (i = 0; s[i] != 0; i++) + for (size_t j = 0; j < reject_len; j++) + if (s[i] == reject[j]) + return i; + return i; +} __stdlib_compat size_t strnlen(const char *s, size_t maxlen) { @@ -207,7 +218,7 @@ __stdlib_compat unsigned long long int strtoull(const char *nptr, char **endptr, *endptr = (char *)nptr - 1; return result; } - + base = find_base(base, &c, &nptr); while (c) { |