[AA] Pass query info.
[llvm-project.git] / libc / src / string / strstr.cpp
bloba598f6610621f59ffb9d0554df01da0ae2eadaf7
1 //===-- Implementation of strstr ------------------------------------------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/string/strstr.h"
11 #include "src/__support/common.h"
12 #include <stddef.h>
14 namespace __llvm_libc {
16 // TODO: This is a simple brute force implementation. This can be
17 // improved upon using well known string matching algorithms.
18 char *LLVM_LIBC_ENTRYPOINT(strstr)(const char *haystack, const char *needle) {
19 for (size_t i = 0; haystack[i]; ++i) {
20 size_t j;
21 for (j = 0; haystack[i + j] && haystack[i + j] == needle[j]; ++j)
23 if (!needle[j])
24 return const_cast<char *>(haystack + i);
26 return nullptr;
29 } // namespace __llvm_libc