Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions libc/src/wchar/wcspbrk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@

namespace LIBC_NAMESPACE_DECL {

bool contains_char(const wchar_t *str, wchar_t target) {
for (; *str != 0; str++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a wide char null byte this should be L'\0' instead of 0.

if (*str == target)
return true;

return false;
}

LLVM_LIBC_FUNCTION(const wchar_t *, wcspbrk,
(const wchar_t *src, const wchar_t *breakset)) {
// currently O(n * m), can be further optimized to O(n + m) with a hash set
for (int src_idx = 0; src[src_idx] != 0; src_idx++)
for (int breakset_idx = 0; breakset[breakset_idx] != 0; breakset_idx++)
if (src[src_idx] == breakset[breakset_idx])
return src + src_idx;
if (contains_char(breakset, src[src_idx]))
return src + src_idx;

return nullptr;
}
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/wchar/wcspbrk_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//===-- Unittests for wcspbrk
//----------------------------------------------===//
//===-- Unittests for wcspbrk ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Loading