[libc-commits] [libc] [libc] Implemented wcspbrk (PR #142040)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Fri May 30 10:47:22 PDT 2025
================
@@ -0,0 +1,27 @@
+//===-- Implementation of wcspbrk -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/wchar/wcspbrk.h"
+
+#include "hdr/types/wchar_t.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+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;
----------------
michaelrj-google wrote:
if you break the check if `src[src_idx]` is in `breakset` out into a helper function this will be easier to read
https://github.com/llvm/llvm-project/pull/142040
More information about the libc-commits
mailing list