32 lines · cpp
1//===-- Implementation of wcspbrk -----------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/wchar/wcspbrk.h"10 11#include "hdr/types/wchar_t.h"12#include "src/__support/common.h"13#include "src/__support/macros/null_check.h"14#include "src/wchar/wchar_utils.h"15 16namespace LIBC_NAMESPACE_DECL {17 18LLVM_LIBC_FUNCTION(const wchar_t *, wcspbrk,19 (const wchar_t *src, const wchar_t *breakset)) {20 LIBC_CRASH_ON_NULLPTR(src);21 LIBC_CRASH_ON_NULLPTR(breakset);22 23 // currently O(n * m), can be further optimized to O(n + m) with a hash set24 for (int src_idx = 0; src[src_idx] != 0; src_idx++)25 if (internal::wcschr(breakset, src[src_idx]))26 return src + src_idx;27 28 return nullptr;29}30 31} // namespace LIBC_NAMESPACE_DECL32