mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add wcsspn(3).
This commit is contained in:
parent
1902f2d797
commit
1938db2c25
3 changed files with 46 additions and 1 deletions
|
@ -139,6 +139,7 @@ wcslen.o \
|
||||||
wcsncat.o \
|
wcsncat.o \
|
||||||
wcsncpy.o \
|
wcsncpy.o \
|
||||||
wcsrchr.o \
|
wcsrchr.o \
|
||||||
|
wcsspn.o \
|
||||||
wctomb.o \
|
wctomb.o \
|
||||||
wctype.o \
|
wctype.o \
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ size_t wcslen(const wchar_t*);
|
||||||
wchar_t* wcsncat(wchar_t* restrict, const wchar_t* restrict, size_t);
|
wchar_t* wcsncat(wchar_t* restrict, const wchar_t* restrict, size_t);
|
||||||
wchar_t* wcsncpy(wchar_t* restrict, const wchar_t* restrict, size_t);
|
wchar_t* wcsncpy(wchar_t* restrict, const wchar_t* restrict, size_t);
|
||||||
wchar_t* wcsrchr(const wchar_t*, wchar_t);
|
wchar_t* wcsrchr(const wchar_t*, wchar_t);
|
||||||
|
size_t wcsspn(const wchar_t*, const wchar_t*);
|
||||||
|
|
||||||
/* TODO: These are not implemented in sortix libc yet. */
|
/* TODO: These are not implemented in sortix libc yet. */
|
||||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
||||||
|
@ -107,7 +108,6 @@ size_t mbsrtowcs(wchar_t* restrict, const char** restrict, size_t, mbstate_t* re
|
||||||
size_t wcscspn(const wchar_t*, const wchar_t*);
|
size_t wcscspn(const wchar_t*, const wchar_t*);
|
||||||
size_t wcsftime(wchar_t* restrict, size_t, const wchar_t* restrict, const struct tm* restrict);
|
size_t wcsftime(wchar_t* restrict, size_t, const wchar_t* restrict, const struct tm* restrict);
|
||||||
size_t wcsrtombs(char* restrict, const wchar_t** restrict, size_t, mbstate_t* restrict);
|
size_t wcsrtombs(char* restrict, const wchar_t** restrict, size_t, mbstate_t* restrict);
|
||||||
size_t wcsspn(const wchar_t*, const wchar_t*);
|
|
||||||
size_t wcsxfrm(wchar_t* restrict, const wchar_t* restrict, size_t);
|
size_t wcsxfrm(wchar_t* restrict, const wchar_t* restrict, size_t);
|
||||||
unsigned long long wcstoull(const wchar_t* restrict, wchar_t** restrict, int);
|
unsigned long long wcstoull(const wchar_t* restrict, wchar_t** restrict, int);
|
||||||
unsigned long wcstoul(const wchar_t* restrict, wchar_t** restrict, int);
|
unsigned long wcstoul(const wchar_t* restrict, wchar_t** restrict, int);
|
||||||
|
|
44
libc/wcsspn.cpp
Normal file
44
libc/wcsspn.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
|
||||||
|
|
||||||
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
wcsspn.cpp
|
||||||
|
Search a string for a set of characters.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
extern "C" size_t wcsspn(const wchar_t* str, const wchar_t* accept)
|
||||||
|
{
|
||||||
|
size_t acceptlen = 0;
|
||||||
|
while ( accept[acceptlen] ) { acceptlen++; }
|
||||||
|
for ( size_t result = 0; true; result++ )
|
||||||
|
{
|
||||||
|
wchar_t c = str[result];
|
||||||
|
if ( !c ) { return result; }
|
||||||
|
bool matches = false;
|
||||||
|
for ( size_t i = 0; i < acceptlen; i++ )
|
||||||
|
{
|
||||||
|
if ( str[result] != accept[i] ) { continue; }
|
||||||
|
matches = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( !matches ) { return result; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue