Path: blob/main/system/lib/llvm-libc/src/wchar/wcsstr.cpp
6171 views
//===-- Implementation of wcsstr ------------------------------------------===//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/wcsstr.h"910#include "hdr/types/size_t.h"11#include "hdr/types/wchar_t.h"12#include "src/__support/common.h"13#include "src/__support/macros/config.h"14#include "src/string/string_utils.h"1516namespace LIBC_NAMESPACE_DECL {1718LLVM_LIBC_FUNCTION(const wchar_t *, wcsstr,19(const wchar_t *s1, const wchar_t *s2)) {20size_t s1_len = internal::string_length(s1);21size_t s2_len = internal::string_length(s2);22if (s2_len == 0)23return s1;24if (s2_len > s1_len)25return nullptr;26for (size_t i = 0; i <= (s1_len - s2_len); ++i) {27size_t j = 0;28// j will increment until the characters don't match or end of string.29for (; j < s2_len && s1[i + j] == s2[j]; ++j)30;31if (j == s2_len)32return (s1 + i);33}34return nullptr;35}3637} // namespace LIBC_NAMESPACE_DECL383940