libc/wchar: Add wcsspn() - scc - simple c99 compiler
 (HTM) git clone git://git.simple-cc.org/scc
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d21aa5a5a185cacd7a63439788287ef6564ad5e2
 (DIR) parent aef615310c0729e97e4ad5a2e4206266660679a2
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Wed, 26 Mar 2025 14:26:21 +0100
       
       libc/wchar: Add wcsspn()
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         A src/libc/wchar/wcsspn.c             |      14 ++++++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0061-wcsspn.c    |      25 +++++++++++++++++++++++++
         M tests/libc/execute/libc-tests.lst   |       1 +
       
       5 files changed, 42 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
       @@ -137,6 +137,7 @@ COMMON_OBJS =\
                wchar/wcsrchr.$O\
                wchar/wcsstr.$O\
                wchar/wcsxfrm.$O\
       +        wchar/wcsspn.$O\
                wchar/wcsrtombs.$O\
                wchar/wcwidth.$O\
                wchar/wmemchr.$O\
 (DIR) diff --git a/src/libc/wchar/wcsspn.c b/src/libc/wchar/wcsspn.c
       @@ -0,0 +1,14 @@
       +#include <wchar.h>
       +
       +#undef wcsspn
       +
       +size_t
       +wcsspn(const wchar_t *s, const wchar_t *accept)
       +{
       +        wchar_t wc;
       +        const wchar_t *p;
       +
       +        for (p = s; (wc = *p) && wcschr(accept, wc); p++)
       +                ;
       +        return p - s;
       +}
 (DIR) diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -57,4 +57,5 @@
        0058-wcsrchr
        0059-wcsstr
        0060-wcsxfrm
       +0061-wcsspn
        test.log
 (DIR) diff --git a/tests/libc/execute/0061-wcsspn.c b/tests/libc/execute/0061-wcsspn.c
       @@ -0,0 +1,25 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +done
       +end:
       +*/
       +
       +int
       +main()
       +{
       +        puts("testing");
       +        assert(wcsspn(L"abccdef", L"cba") == 4);
       +        assert(wcsspn(L"abcg", L"cba0") == 3);
       +        assert(wcsspn(L"", L"abc") == 0);
       +        assert(wcsspn(L"abc", L"") == 0);
       +        assert(wcsspn(L"", L"") == 0);
       +        assert(wcsspn(L"abc", L"def") == 0);
       +        puts("done");
       +
       +        return 0;
       +}
 (DIR) diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -56,3 +56,4 @@
        0058-wcsrchr
        0059-wcsstr
        0060-wcsxfrm
       +0061-wcsspn