mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 02:13:56 +09:00
LibC: Implement wcs{,c}spn()
This commit is contained in:
parent
4f8d095f5a
commit
3b281baf75
Notes:
sideshowbarker
2024-07-18 03:20:18 +09:00
Author: https://github.com/alimpfard
Commit: 3b281baf75
Pull-request: https://github.com/SerenityOS/serenity/pull/11324
Reviewed-by: https://github.com/BertalanD
2 changed files with 28 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue