zephyr/lib/libc/minimal/source/string/strspn.c
Peter A. Bigot 8420f43b86 libc: minimal: add strspn and strcspn support
These functions are useful for determining prefixes, as with file system
paths.  They are required by littlefs.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-07-31 09:22:49 -07:00

32 lines
478 B
C

/*
* Copyright (c) 2019 Peter Bigot Consulting, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <string.h>
size_t strspn(const char *s,
const char *accept)
{
const char *ins = s;
while ((*s != '\0') && (strchr(accept, *s) != NULL)) {
++s;
}
return s - ins;
}
size_t strcspn(const char *s,
const char *reject)
{
const char *ins = s;
while ((*s != '\0') && (strchr(reject, *s) == NULL)) {
++s;
}
return s - ins;
}