Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-- str{,case}cmp implementation ----------------------------*- C++ -*-===//
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//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_STRCMP_H
10#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_STRCMP_H
11
12#include "src/__support/macros/attributes.h" // LIBC_INLINE
13#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
14#include <stddef.h>
15
16namespace LIBC_NAMESPACE_DECL {
17
18template <typename Comp>
19LIBC_INLINE constexpr int inline_strcmp(const char *left, const char *right,
20 Comp &&comp) {
21 // TODO: Look at benefits for comparing words at a time.
22 for (; *left && !comp(*left, *right); ++left, ++right)
23 ;
24 return comp(*reinterpret_cast<const unsigned char *>(left),
25 *reinterpret_cast<const unsigned char *>(right));
26}
27
28template <typename Comp>
29LIBC_INLINE constexpr int inline_strncmp(const char *left, const char *right,
30 size_t n, Comp &&comp) {
31 if (n == 0)
32 return 0;
33
34 // TODO: Look at benefits for comparing words at a time.
35 for (; n > 1; --n, ++left, ++right) {
36 char lc = *left;
37 if (!comp(lc, '\0') || comp(lc, *right))
38 break;
39 }
40 return comp(*reinterpret_cast<const unsigned char *>(left),
41 *reinterpret_cast<const unsigned char *>(right));
42}
43
44} // namespace LIBC_NAMESPACE_DECL
45
46#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_STRCMP_H
47

Warning: This file is not a C or C++ file. It does not have highlighting.

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of libc/src/string/memory_utils/inline_strcmp.h