xref: /llvm-project/libc/src/string/strstr.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
1d080635bScgyurgyik //===-- Implementation of strstr ------------------------------------------===//
2d080635bScgyurgyik //
3d080635bScgyurgyik // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4d080635bScgyurgyik // See https://llvm.org/LICENSE.txt for license information.
5d080635bScgyurgyik // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d080635bScgyurgyik //
7d080635bScgyurgyik //===----------------------------------------------------------------------===//
8d080635bScgyurgyik 
9d080635bScgyurgyik #include "src/string/strstr.h"
10d080635bScgyurgyik 
11d080635bScgyurgyik #include "src/__support/common.h"
12*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
131f578347SGuillaume Chatelet #include "src/string/memory_utils/inline_strstr.h"
14d080635bScgyurgyik 
15*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
16d080635bScgyurgyik 
17d080635bScgyurgyik // TODO: This is a simple brute force implementation. This can be
18d080635bScgyurgyik // improved upon using well known string matching algorithms.
19a0b65a7bSMichael Jones LLVM_LIBC_FUNCTION(char *, strstr, (const char *haystack, const char *needle)) {
20eebb2e31SAlex Brachet   auto comp = [](char l, char r) -> int { return l - r; };
211f578347SGuillaume Chatelet   return inline_strstr(haystack, needle, comp);
22d080635bScgyurgyik }
23d080635bScgyurgyik 
24*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
25