Path: blob/main/system/lib/llvm-libc/src/string/strcasestr.cpp
6175 views
//===-- Implementation of strcasestr --------------------------------------===//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/string/strcasestr.h"910#include "src/__support/common.h"11#include "src/__support/ctype_utils.h"12#include "src/__support/macros/config.h"13#include "src/__support/macros/null_check.h"14#include "src/string/memory_utils/inline_strstr.h"1516namespace LIBC_NAMESPACE_DECL {1718// TODO: This is a simple brute force implementation. This can be19// improved upon using well known string matching algorithms.20LLVM_LIBC_FUNCTION(char *, strcasestr,21(const char *haystack, const char *needle)) {22auto case_cmp = [](char a, char b) {23return LIBC_NAMESPACE::internal::tolower(a) -24LIBC_NAMESPACE::internal::tolower(b);25};2627LIBC_CRASH_ON_NULLPTR(haystack);28LIBC_CRASH_ON_NULLPTR(needle);29return inline_strstr(haystack, needle, case_cmp);30}3132} // namespace LIBC_NAMESPACE_DECL333435