tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
strchr.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_CSTRING_STRCHR_HPP
5#define TETL_CSTRING_STRCHR_HPP
6
7#include <etl/_contracts/check.hpp>
8#include <etl/_cstddef/size_t.hpp>
9#include <etl/_strings/cstr.hpp>
10
11namespace etl {
12
13/// \ingroup cstring
14/// @{
15
16/// Finds the first occurrence of the character static_cast<char>(ch) in
17/// the byte string pointed to by str.
18///
19/// The terminating null character is considered to be a part of the
20/// string and can be found if searching for '\0'.
21///
22/// https://en.cppreference.com/w/cpp/string/byte/strchr
23///
24/// \ingroup cstring
25[[nodiscard]] constexpr auto strchr(char const* str, int ch) -> char const*
26{
27 TETL_PRECONDITION(str != nullptr);
28#if defined(__clang__)
29 return __builtin_strchr(str, ch);
30#else
31 return etl::detail::strchr<char const>(str, ch);
32#endif
33}
34
35[[nodiscard]] constexpr auto strchr(char* str, int ch) -> char*
36{
37 TETL_PRECONDITION(str != nullptr);
38#if defined(__clang__)
39 return __builtin_strchr(str, ch);
40#else
41 return etl::detail::strchr<char>(str, ch);
42#endif
43}
44
45/// @}
46
47} // namespace etl
48
49#endif // TETL_CSTRING_STRCHR_HPP
constexpr auto strchr(char *str, int ch) -> char *
Definition strchr.hpp:35
constexpr auto strchr(char const *str, int ch) -> char const *
Definition strchr.hpp:25
Definition adjacent_find.hpp:9