libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
+ libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
libc.src.string.strcmp
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
+ libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
libc.src.string.strcmp
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
+ libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
libc.src.string.strcmp
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
+ libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
libc.src.string.strcmp
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
+ libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
libc.src.string.strcmp
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
+ libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
libc.src.string.strcmp
libc.src.string.stpcpy
libc.src.string.stpncpy
libc.src.string.strcasecmp
+ libc.src.string.strcasestr
libc.src.string.strcat
libc.src.string.strchr
libc.src.string.strcmp
RetValSpec<CharPtr>,
[ArgSpec<IntType>, ArgSpec<CharPtr>, ArgSpec<SizeTType>]
>,
+ FunctionSpec<
+ "strcasestr",
+ RetValSpec<CharPtr>,
+ [ArgSpec<ConstCharPtr>, ArgSpec<ConstCharPtr>]
+ >,
]
>;
)
add_entrypoint_object(
+ strcasestr
+ SRCS
+ strcasestr.cpp
+ HDRS
+ strcasestr.h
+ DEPENDS
+ .memory_utils.strstr_implementation
+ libc.src.__support.ctype_utils
+)
+
+add_entrypoint_object(
strcoll
SRCS
strcoll.cpp
--- /dev/null
+//===-- Implementation of strcasestr --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/string/strcasestr.h"
+
+#include "src/__support/common.h"
+#include "src/__support/ctype_utils.h"
+#include "src/string/memory_utils/strstr_implementations.h"
+
+namespace __llvm_libc {
+
+// TODO: This is a simple brute force implementation. This can be
+// improved upon using well known string matching algorithms.
+LLVM_LIBC_FUNCTION(char *, strcasestr,
+ (const char *haystack, const char *needle)) {
+ auto case_cmp = [](char a, char b) {
+ return __llvm_libc::internal::tolower(a) -
+ __llvm_libc::internal::tolower(b);
+ };
+ return strstr_implementation(haystack, needle, case_cmp);
+}
+
+} // namespace __llvm_libc
--- /dev/null
+//===-- Implementation header for strcasestr --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STRING_STRCASECMP_H
+#define LLVM_LIBC_SRC_STRING_STRCASECMP_H
+
+namespace __llvm_libc {
+
+char *strcasestr(const char *needle, const char *haystack);
+
+} // namespace __llvm_libc
+
+#endif // LLVM_LIBC_SRC_STRING_STRCASECMP_H
)
add_libc_unittest(
+ strcasestr_test
+ SUITE
+ libc_string_unittests
+ SRCS
+ strcasestr_test.cpp
+ DEPENDS
+ libc.src.string.strcasestr
+)
+
+add_libc_unittest(
strcoll_test
SUITE
libc_string_unittests
--- /dev/null
+//===-- Unittests for strcasestr ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/string/strcasestr.h"
+#include "utils/UnitTest/Test.h"
+
+TEST(LlvmLibcStrCaseStrTest, NeedleNotInHaystack) {
+ EXPECT_STREQ(__llvm_libc::strcasestr("abcd", "e"), nullptr);
+ EXPECT_STREQ(__llvm_libc::strcasestr("ABCD", "e"), nullptr);
+ EXPECT_STREQ(__llvm_libc::strcasestr("abcd", "E"), nullptr);
+ EXPECT_STREQ(__llvm_libc::strcasestr("ABCD", "E"), nullptr);
+}
+
+TEST(LlvmLibcStrCaseStrTest, NeedleInMiddle) {
+ EXPECT_STREQ(__llvm_libc::strcasestr("abcdefghi", "def"), "defghi");
+ EXPECT_STREQ(__llvm_libc::strcasestr("ABCDEFGHI", "def"), "DEFGHI");
+ EXPECT_STREQ(__llvm_libc::strcasestr("abcdefghi", "DEF"), "defghi");
+ EXPECT_STREQ(__llvm_libc::strcasestr("ABCDEFGHI", "DEF"), "DEFGHI");
+}