Path: blob/main/system/lib/llvm-libc/src/wchar/wcspbrk.cpp
6174 views
//===-- Implementation of wcspbrk -----------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "src/wchar/wcspbrk.h"910#include "hdr/types/wchar_t.h"11#include "src/__support/common.h"12#include "src/__support/macros/null_check.h"1314namespace LIBC_NAMESPACE_DECL {1516bool contains_char(const wchar_t *str, wchar_t target) {17for (; *str != L'\0'; str++)18if (*str == target)19return true;2021return false;22}2324LLVM_LIBC_FUNCTION(const wchar_t *, wcspbrk,25(const wchar_t *src, const wchar_t *breakset)) {26LIBC_CRASH_ON_NULLPTR(src);27LIBC_CRASH_ON_NULLPTR(breakset);2829// currently O(n * m), can be further optimized to O(n + m) with a hash set30for (int src_idx = 0; src[src_idx] != 0; src_idx++)31if (contains_char(breakset, src[src_idx]))32return src + src_idx;3334return nullptr;35}3637} // namespace LIBC_NAMESPACE_DECL383940