LibC: Implement wcs{,c}spn()

This commit is contained in:
Ali Mohammad Pur 2021-12-19 20:51:30 +03:30 committed by Ali Mohammad Pur
parent 4f8d095f5a
commit 3b281baf75
Notes: sideshowbarker 2024-07-18 03:20:18 +09:00
2 changed files with 28 additions and 0 deletions

View File

@ -626,4 +626,30 @@ size_t mbsrtowcs(wchar_t* dst, char const** src, size_t len, mbstate_t* ps)
// SIZE_MAX is as close as we are going to get to "unlimited".
return mbsnrtowcs(dst, src, SIZE_MAX, len, ps);
}
size_t wcscspn(wchar_t const* wcs, wchar_t const* reject)
{
for (auto const* wc_pointer = wcs;;) {
auto c = *wc_pointer++;
wchar_t rc;
auto const* reject_copy = reject;
do {
if ((rc = *reject_copy++) == c)
return wc_pointer - 1 - wcs;
} while (rc != 0);
}
}
size_t wcsspn(wchar_t const* wcs, wchar_t const* accept)
{
for (auto const* wc_pointer = wcs;;) {
auto c = *wc_pointer++;
wchar_t rc;
auto const* accept_copy = accept;
do {
if ((rc = *accept_copy++) != c)
return wc_pointer - 1 - wcs;
} while (rc != 0);
}
}
}

View File

@ -66,5 +66,7 @@ size_t mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*);
int wmemcmp(const wchar_t*, const wchar_t*, size_t);
size_t wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*);
size_t mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*);
size_t wcscspn(const wchar_t* wcs, const wchar_t* reject);
size_t wcsspn(const wchar_t* wcs, const wchar_t* accept);
__END_DECLS