1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:34:59 +00:00

LibC: Implement wcspbrk

This commit is contained in:
Tim Schumacher 2021-09-22 08:52:27 +00:00 committed by Brian Gianforcaro
parent c80b65b827
commit 1b078f87b7
3 changed files with 39 additions and 0 deletions

View file

@ -8,6 +8,33 @@
#include <wchar.h>
TEST_CASE(wcspbrk)
{
const wchar_t* input;
wchar_t* ret;
// Test empty haystack.
ret = wcspbrk(L"", L"ab");
EXPECT_EQ(ret, nullptr);
// Test empty needle.
ret = wcspbrk(L"ab", L"");
EXPECT_EQ(ret, nullptr);
// Test search for a single character.
input = L"abcd";
ret = wcspbrk(input, L"a");
EXPECT_EQ(ret, input);
// Test search for multiple characters, none matches.
ret = wcspbrk(input, L"zxy");
EXPECT_EQ(ret, nullptr);
// Test search for multiple characters, last matches.
ret = wcspbrk(input, L"zxyc");
EXPECT_EQ(ret, input + 2);
}
TEST_CASE(wcscoll)
{
// Check if wcscoll is sorting correctly. At the moment we are doing raw char comparisons,

View file

@ -344,4 +344,15 @@ int mbsinit(const mbstate_t* state)
return 1;
}
wchar_t* wcspbrk(const wchar_t* wcs, const wchar_t* accept)
{
for (const wchar_t* cur = accept; *cur; cur++) {
wchar_t* res = wcschr(wcs, *cur);
if (res)
return res;
}
return nullptr;
}
}

View file

@ -41,5 +41,6 @@ size_t wcrtomb(char*, wchar_t, mbstate_t*);
int wcscoll(const wchar_t*, const wchar_t*);
int wctob(wint_t);
int mbsinit(const mbstate_t*);
wchar_t* wcspbrk(const wchar_t*, const wchar_t*);
__END_DECLS