string: add and test strspn and strcspn (DONE)

This commit is contained in:
Lephenixnoir 2021-05-23 18:02:38 +02:00
parent 8368ba70fd
commit cda27ac2db
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 23 additions and 5 deletions

View File

@ -140,6 +140,7 @@ set(SOURCES
src/libc/string/strchrnul.c
src/libc/string/strcmp.c
src/libc/string/strcpy.c
src/libc/string/strcspn.c
src/libc/string/strdup.c
src/libc/string/strerror.c
src/libc/string/strlen.c
@ -148,7 +149,8 @@ set(SOURCES
src/libc/string/strncpy.c
src/libc/string/strndup.c
src/libc/string/strnlen.c
src/libc/string/strrchr.c)
src/libc/string/strrchr.c
src/libc/string/strspn.c)
if(vhex-generic IN_LIST TARGET_FOLDERS)
# TODO

4
STATUS
View File

@ -122,10 +122,10 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested
! 7.21.4.5 strxfrm: TODO
7.21.5.1 memchr: DONE
7.21.5.2 strchr: DONE
! 7.21.5.3 strcspn: TODO
7.21.5.3 strcspn: DONE
! 7.21.5.4 strpbrk: TODO
7.21.5.5 strrchr: DONE
! 7.21.5.6 strspn: TODO
7.21.5.6 strspn: DONE
! 7.21.5.7 strstr: TODO
! 7.21.5.8 strtok: TODO
7.21.6.1 memset: DONE

View File

@ -54,7 +54,7 @@ extern void *memchr(void const *__s, int __c, size_t __n);
extern char *strchr(char const *__s, int __c);
/* Count initial characters of __s that are not in __exclude. */
extern char *strcspn(char const *__s, char const *__exclude);
extern size_t strcspn(char const *__s, char const *__exclude);
/* Find the first character of __s that is also in __include. */
extern char *strpbrk(char const *__s, char const *__include);
@ -63,7 +63,7 @@ extern char *strpbrk(char const *__s, char const *__include);
extern char *strrchr(char const *__s, int __c);
/* Count initial characters of __s that are in __include. */
extern char *strspn(char const *__s, char const *__include);
extern size_t strspn(char const *__s, char const *__include);
/* Find the first occurrence of __s2 as a substring of __s1. */
extern char *strstr(char const *__s1, char const *__s2);

View File

@ -0,0 +1,8 @@
#include <string.h>
size_t strcspn(char const *s, char const *reject)
{
size_t i = 0;
while(s[i] && !strchr(reject, s[i])) i++;
return i;
}

8
src/libc/string/strspn.c Normal file
View File

@ -0,0 +1,8 @@
#include <string.h>
size_t strspn(char const *s, char const *accept)
{
size_t i = 0;
while(s[i] && strchr(accept, s[i])) i++;
return i;
}