diff options
author | Tim Schumacher <timschumi@gmx.de> | 2021-09-22 08:54:23 +0000 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-10-03 05:28:51 +0000 |
commit | 5ac2e84264a669dc207be63d0fc746887a1d241f (patch) | |
tree | 2e9b4a55182b09b59a791420b6b99772976480c5 /Userland/Libraries/LibC | |
parent | 1b078f87b77e65afac3a998af8223bbebe729df0 (diff) | |
download | serenity-5ac2e84264a669dc207be63d0fc746887a1d241f.zip |
LibC: Implement wcsstr
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r-- | Userland/Libraries/LibC/wchar.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibC/wchar.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/wchar.cpp b/Userland/Libraries/LibC/wchar.cpp index 39eb3e8579..db255185af 100644 --- a/Userland/Libraries/LibC/wchar.cpp +++ b/Userland/Libraries/LibC/wchar.cpp @@ -355,4 +355,24 @@ wchar_t* wcspbrk(const wchar_t* wcs, const wchar_t* accept) return nullptr; } + +wchar_t* wcsstr(const wchar_t* haystack, const wchar_t* needle) +{ + size_t nlen = wcslen(needle); + + if (nlen == 0) + return const_cast<wchar_t*>(haystack); + + size_t hlen = wcslen(haystack); + + while (hlen >= nlen) { + if (wcsncmp(haystack, needle, nlen) == 0) + return const_cast<wchar_t*>(haystack); + + haystack++; + hlen--; + } + + return nullptr; +} } diff --git a/Userland/Libraries/LibC/wchar.h b/Userland/Libraries/LibC/wchar.h index 98c6824945..70ea7006a8 100644 --- a/Userland/Libraries/LibC/wchar.h +++ b/Userland/Libraries/LibC/wchar.h @@ -42,5 +42,6 @@ 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*); +wchar_t* wcsstr(const wchar_t*, const wchar_t*); __END_DECLS |