libc/wchar: Add wcscspn() - 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 5a4639f2e13052cfd4ff099cf1fcee020af58a55
 (DIR) parent d21aa5a5a185cacd7a63439788287ef6564ad5e2
 (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Wed, 26 Mar 2025 14:34:58 +0100
       
       libc/wchar: Add wcscspn()
       
       Diffstat:
         M src/libc/objs/common-objs.mk        |       1 +
         A src/libc/wchar/wcscspn.c            |      14 ++++++++++++++
         M tests/libc/execute/.gitignore       |       1 +
         A tests/libc/execute/0062-wcscspn.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
       @@ -138,6 +138,7 @@ COMMON_OBJS =\
                wchar/wcsstr.$O\
                wchar/wcsxfrm.$O\
                wchar/wcsspn.$O\
       +        wchar/wcscspn.$O\
                wchar/wcsrtombs.$O\
                wchar/wcwidth.$O\
                wchar/wmemchr.$O\
 (DIR) diff --git a/src/libc/wchar/wcscspn.c b/src/libc/wchar/wcscspn.c
       @@ -0,0 +1,14 @@
       +#include <wchar.h>
       +
       +#undef wcscspn
       +
       +size_t
       +wcscspn(const wchar_t *s, const wchar_t *reject)
       +{
       +        wchar_t wc;
       +        const wchar_t *p;
       +
       +        for (p = s; (wc = *p) && !wcschr(reject, wc); p++)
       +                ;
       +        return p - s;
       +}
 (DIR) diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
       @@ -58,4 +58,5 @@
        0059-wcsstr
        0060-wcsxfrm
        0061-wcsspn
       +0062-wcscspn
        test.log
 (DIR) diff --git a/tests/libc/execute/0062-wcscspn.c b/tests/libc/execute/0062-wcscspn.c
       @@ -0,0 +1,25 @@
       +#include <assert.h>
       +#include <stdio.h>
       +#include <wchar.h>
       +
       +/*
       +output:
       +testing
       +done
       +end:
       +*/
       +
       +int
       +main()
       +{
       +        puts("testing");
       +
       +        assert(wcscspn(L"0125", L"56789") == 3);
       +        assert(wcscspn(L"", L"56789") == 0);
       +        assert(wcscspn(L"01234", L"") == 5);
       +        assert(wcscspn(L"", L"") == 0);
       +
       +        puts("done");
       +
       +        return 0;
       +}
 (DIR) diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
       @@ -57,3 +57,4 @@
        0059-wcsstr
        0060-wcsxfrm
        0061-wcsspn
       +0062-wcscspn