tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
find.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2024 Tobias Hienzsch
3
4#ifndef TETL_STRINGS_FIND_HPP
5#define TETL_STRINGS_FIND_HPP
6
7#include <etl/_string_view/basic_string_view.hpp>
8
9namespace etl::strings {
10
11template <typename Char, typename Traits>
12[[nodiscard]] constexpr auto find(
13 basic_string_view<Char, Traits> haystack,
14 basic_string_view<Char, Traits> needle,
15 typename basic_string_view<Char, Traits>::size_type pos = 0
16) noexcept -> typename basic_string_view<Char, Traits>::size_type
17{
18 if (needle.size() == 0 and pos <= haystack.size()) {
19 return pos;
20 }
21
22 if (pos <= haystack.size() - needle.size()) {
23 return haystack.find(needle, pos);
24 }
25
26 return basic_string_view<Char, Traits>::npos;
27}
28
29} // namespace etl::strings
30
31#endif // TETL_STRINGS_FIND_HPP
Definition find.hpp:9
constexpr auto find(basic_string_view< Char, Traits > haystack, basic_string_view< Char, Traits > needle, typename basic_string_view< Char, Traits >::size_type pos=0) noexcept -> typename basic_string_view< Char, Traits >::size_type
Definition find.hpp:12
Definition adjacent_find.hpp:9
The class template basic_string_view describes an object that can refer to a constant contiguous sequ...
Definition basic_string_view.hpp:35