tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
basic_string_view.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3#ifndef TETL_BASIC_STRING_VIEW_STRING_VIEW_HPP
4#define TETL_BASIC_STRING_VIEW_STRING_VIEW_HPP
5
6#include <etl/_algorithm/clamp.hpp>
7#include <etl/_algorithm/find_end.hpp>
8#include <etl/_algorithm/lexicographical_compare.hpp>
9#include <etl/_algorithm/min.hpp>
10#include <etl/_algorithm/none_of.hpp>
11#include <etl/_concepts/emulation.hpp>
12#include <etl/_contracts/check.hpp>
13#include <etl/_iterator/begin.hpp>
14#include <etl/_iterator/data.hpp>
15#include <etl/_iterator/end.hpp>
16#include <etl/_iterator/next.hpp>
17#include <etl/_iterator/rbegin.hpp>
18#include <etl/_iterator/rend.hpp>
19#include <etl/_iterator/reverse_iterator.hpp>
20#include <etl/_iterator/size.hpp>
21#include <etl/_ranges/enable_borrowed_range.hpp>
22#include <etl/_string/char_traits.hpp>
23#include <etl/_type_traits/type_identity.hpp>
24#include <etl/_utility/swap.hpp>
25
26namespace etl {
27
28/// \brief The class template basic_string_view describes an object that can
29/// refer to a constant contiguous sequence of char-like objects with the first
30/// element of the sequence at position zero. A typical implementation holds
31/// only two members: a pointer to constant Char and a size.
32/// \headerfile etl/string_view.hpp
33/// \ingroup string_view
34template <typename Char, typename Traits = etl::char_traits<Char>>
36 using traits_type = Traits;
37 using value_type = Char;
38 using pointer = Char*;
39 using const_pointer = Char const*;
40 using reference = Char&;
41 using const_reference = Char const&;
42 using const_iterator = Char const*;
43 using iterator = const_iterator;
44 using size_type = etl::size_t;
45 using difference_type = etl::ptrdiff_t;
46 using const_reverse_iterator = etl::reverse_iterator<const_iterator>;
47 using reverse_iterator = const_reverse_iterator;
48
49 /// \brief Default constructor. Constructs an empty basic_string_view. After
50 /// construction, data() is equal to nullptr, and size() is equal to 0.
51 constexpr basic_string_view() noexcept = default;
52
53 /// \brief Copy constructor. Constructs a view of the same content as other.
54 /// After construction, data() is equal to other.data(), and size() is equal
55 /// to other.size().
56 constexpr basic_string_view(basic_string_view const& other) noexcept = default;
57
58 /// \brief Constructs a view of the first count characters of the character
59 /// array starting with the element pointed by s. s can contain null
60 /// characters. The behavior is undefined if [s, s+count) is not a valid
61 /// range (even though the constructor may not access any of the elements of
62 /// this range). After construction, data() is equal to s, and size() is
63 /// equal to count.
64 constexpr basic_string_view(Char const* str, size_type size)
65 : _begin{str}
66 , _size{size}
67 {
68 }
69
70 /// \brief Constructs a view of the null-terminated character string pointed
71 /// to by s, not including the terminating null character. The length of the
72 /// view is determined as if by Traits::length(s). The behavior is undefined
73 /// if [s, s+Traits::length(s)) is not a valid range. After construction,
74 /// data() is equal to s, and size() is equal to Traits::length(s).
75 constexpr basic_string_view(Char const* str)
76 : _begin{str}
77 , _size{traits_type::length(str)}
78 {
79 }
80
81 constexpr basic_string_view(nullptr_t /*null*/) = delete;
82
83 /// \brief Constructs a basic_string_view over the range [first, last). The
84 /// behavior is undefined if [first, last) is not a valid range.
85 ///
86 /// \bug Improve SFINAE protection. See C++20 standard.
87 template <typename Iter>
88 requires(detail::RandomAccessIterator<Iter>)
89 constexpr basic_string_view(Iter first, Iter last)
90 : basic_string_view{first, static_cast<size_type>(last - first)}
91 {
92 }
93
94 ~basic_string_view() noexcept = default;
95
96 /// \brief Replaces the view with that of view.
97 constexpr auto operator=(basic_string_view const& view) noexcept -> basic_string_view& = default;
98
99 /// \brief Returns an iterator to the first character of the view.
100 [[nodiscard]] constexpr auto begin() const noexcept -> const_iterator
101 {
102 return cbegin();
103 }
104
105 /// \brief Returns an iterator to the first character of the view.
106 [[nodiscard]] constexpr auto cbegin() const noexcept -> const_iterator
107 {
108 return _begin;
109 }
110
111 /// \brief Returns an iterator to the character following the last character
112 /// of the view. This character acts as a placeholder, attempting to access
113 /// it results in undefined behavior.
114 [[nodiscard]] constexpr auto end() const noexcept -> const_iterator
115 {
116 return cend();
117 }
118
119 /// \brief Returns an iterator to the character following the last character
120 /// of the view. This character acts as a placeholder, attempting to access
121 /// it results in undefined behavior.
122 [[nodiscard]] constexpr auto cend() const noexcept -> const_iterator
123 {
124 return _begin + _size;
125 }
126
127 /// \brief Returns a reverse iterator to the first character of the reversed
128 /// view. It corresponds to the last character of the non-reversed view.
129 [[nodiscard]] constexpr auto rbegin() const noexcept -> const_reverse_iterator
130 {
131 return crbegin();
132 }
133
134 /// \brief Returns a reverse iterator to the first character of the reversed
135 /// view. It corresponds to the last character of the non-reversed view.
136 [[nodiscard]] constexpr auto crbegin() const noexcept -> const_reverse_iterator
137 {
138 return const_reverse_iterator(end());
139 }
140
141 /// \brief Returns a reverse iterator to the character following the last
142 /// character of the reversed view.
143 ///
144 /// It corresponds to the character preceding the first character of the
145 /// non-reversed view. This character acts as a placeholder, attempting to
146 /// access it results in undefined behavior.
147 [[nodiscard]] constexpr auto rend() const noexcept -> const_reverse_iterator
148 {
149 return crend();
150 }
151
152 /// \brief Returns a reverse iterator to the character following the last
153 /// character of the reversed view.
154 ///
155 /// It corresponds to the character preceding the first character of the
156 /// non-reversed view. This character acts as a placeholder, attempting to
157 /// access it results in undefined behavior.
158 [[nodiscard]] constexpr auto crend() const noexcept -> const_reverse_iterator
159 {
160 return const_reverse_iterator(begin());
161 }
162
163 /// Returns a const reference to the character at specified location \p pos
164 /// \pre `pos < size()`
165 [[nodiscard]] constexpr auto operator[](size_type pos) const -> const_reference
166 {
167 TETL_PRECONDITION(pos < size());
168 return unsafe_at(pos);
169 }
170
171 /// Returns reference to the first character in the view.
172 /// \pre `size() > 0`
173 [[nodiscard]] constexpr auto front() const -> const_reference
174 {
175 TETL_PRECONDITION(not empty());
176 return unsafe_at(0);
177 }
178
179 /// Returns reference to the last character in the view.
180 /// \pre `size() > 0`
181 [[nodiscard]] constexpr auto back() const -> const_reference
182 {
183 TETL_PRECONDITION(not empty());
184 return unsafe_at(_size - 1);
185 }
186
187 /// Returns a pointer to the underlying character array. The pointer
188 /// is such that the range [data(); data() + size()) is valid and the values
189 /// in it correspond to the values of the view.
190 [[nodiscard]] constexpr auto data() const noexcept -> const_pointer
191 {
192 return _begin;
193 }
194
195 /// Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()).
196 [[nodiscard]] constexpr auto size() const noexcept -> size_type
197 {
198 return length();
199 }
200
201 /// Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()).
202 [[nodiscard]] constexpr auto length() const noexcept -> size_type
203 {
204 return _size;
205 }
206
207 /// The largest possible number of char-like objects that can be
208 /// referred to by a basic_string_view.
209 [[nodiscard]] constexpr auto max_size() const noexcept -> size_type
210 {
211 return size_type(-1);
212 }
213
214 /// Checks if the view has no characters, i.e. whether size() == 0.
215 [[nodiscard]] constexpr auto empty() const noexcept -> bool
216 {
217 return _size == 0;
218 }
219
220 /// Moves the start of the view forward by n characters.
221 /// \pre `n <= size()`
222 constexpr auto remove_prefix(size_type n) -> void
223 {
224 TETL_PRECONDITION(n <= size());
225 _begin += n;
226 _size -= n;
227 }
228
229 /// Moves the end of the view back by n characters.
230 /// \pre `n <= size()`
231 constexpr auto remove_suffix(size_type n) -> void
232 {
233 TETL_PRECONDITION(n <= size());
234 _size = _size - n;
235 }
236
237 /// Exchanges the view with that of v.
238 constexpr auto swap(basic_string_view& v) noexcept -> void
239 {
240 etl::swap(_begin, v._begin);
241 etl::swap(_size, v._size);
242 }
243
244 /// Copies the substring [pos, pos + rcount) to the character array
245 /// pointed to by dest, where rcount is the smaller of count and size() -
246 /// pos. Equivalent to Traits::copy(dest, data() + pos, rcount).
247 [[nodiscard]] constexpr auto copy(Char* dest, size_type count, size_type pos = 0) const -> size_type
248 {
249 TETL_PRECONDITION(pos <= size());
250 auto const rcount = etl::min(count, size() - pos);
251 traits_type::copy(dest, data() + pos, rcount);
252 return rcount;
253 }
254
255 /// Returns a view of the substring [pos, pos + rcount), where rcount
256 /// is the smaller of count and size() - pos.
257 [[nodiscard]] constexpr auto substr(size_type pos = 0, size_type count = npos) const -> basic_string_view
258 {
259 TETL_PRECONDITION(pos <= size());
260 auto const rcount = etl::min(count, size() - pos);
261 return basic_string_view{_begin + pos, rcount};
262 }
263
264 /// Compares two character sequences.
265 ///
266 /// https://en.cppreference.com/w/cpp/string/basic_string_view/compare
267 [[nodiscard]] constexpr auto compare(basic_string_view v) const noexcept -> int
268 {
269 auto const rlen = etl::min(size(), v.size());
270 auto const res = traits_type::compare(data(), v.data(), rlen);
271
272 if (res == 0) {
273 if (size() < v.size()) {
274 return -1;
275 }
276 if (size() > v.size()) {
277 return 1;
278 }
279 }
280
281 return res;
282 }
283
284 /// Compares two character sequences. Equivalent to substr(pos1, count1).compare(v).
285 [[nodiscard]] constexpr auto compare(size_type pos1, size_type count1, basic_string_view v) const -> int
286 {
287 return substr(pos1, count1).compare(v);
288 }
289
290 /// Compares two character sequences. Equivalent to substr(pos1, count1).compare(v.substr(pos2, count2))
291 [[nodiscard]] constexpr auto
292 compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const -> int
293 {
294 return substr(pos1, count1).compare(v.substr(pos2, count2));
295 }
296
297 /// Compares two character sequences. Equivalent to compare(basic_string_view(s)).
298 [[nodiscard]] constexpr auto compare(Char const* s) const -> int
299 {
300 return compare(basic_string_view(s));
301 }
302
303 /// Compares two character sequences. Equivalent to substr(pos1, count1).compare(basic_string_view(s)).
304 [[nodiscard]] constexpr auto compare(size_type pos1, size_type count1, Char const* s) const -> int
305 {
306 return substr(pos1, count1).compare(basic_string_view(s));
307 }
308
309 /// Compares two character sequences. Equivalent to substr(pos1, count1).compare(basic_string_view(s, count2)).
310 [[nodiscard]] constexpr auto compare(size_type pos1, size_type count1, Char const* s, size_type count2) const -> int
311 {
312 return substr(pos1, count1).compare(basic_string_view(s, count2));
313 }
314
315 /// Checks if the string view begins with the given prefix, where the prefix is a string view.
316 ///
317 /// \details Effectively returns substr(0, sv.size()) == sv
318 [[nodiscard]] constexpr auto starts_with(basic_string_view sv) const noexcept -> bool
319 {
320 return substr(0, sv.size()) == sv;
321 }
322
323 /// Checks if the string view begins with the given prefix, where the prefix is a single character.
324 ///
325 /// \details Effectively returns !empty() && Traits::eq(front(), c)
326 [[nodiscard]] constexpr auto starts_with(Char c) const noexcept -> bool
327 {
328 return !empty() && traits_type::eq(front(), c);
329 }
330
331 /// \brief Checks if the string view begins with the given prefix, where the
332 /// the prefix is a null-terminated character string.
333 ///
334 /// \details Effectively returns starts_with(basic_string_view(s))
335 [[nodiscard]] constexpr auto starts_with(Char const* str) const -> bool
336 {
337 return starts_with(basic_string_view(str));
338 }
339
340 /// \brief Checks if the string view ends with the given suffix, where the
341 /// prefix is a string view.
342 ///
343 /// \details Effectively returns size() >= sv.size() && compare(size() -
344 /// sv.size(), npos, sv) == 0
345 [[nodiscard]] constexpr auto ends_with(basic_string_view sv) const noexcept -> bool
346 {
347 return size() >= sv.size() && compare(size() - sv.size(), npos, sv) == 0;
348 }
349
350 /// \brief Checks if the string view ends with the given suffix, where the
351 /// prefix is a single character.
352 ///
353 /// \details Effectively returns !empty() && Traits::eq(back(), c)
354 [[nodiscard]] constexpr auto ends_with(Char c) const noexcept -> bool
355 {
356 return !empty() && Traits::eq(back(), c);
357 }
358
359 /// \brief Checks if the string view ends with the given suffix, where the
360 /// the prefix is a null-terminated character string.
361 ///
362 /// \details Effectively returns ends_with(basic_string_view(s))
363 constexpr auto ends_with(Char const* str) const -> bool
364 {
365 return ends_with(basic_string_view(str));
366 }
367
368 /// \brief Finds the first substring equal to the given character sequence.
369 /// Finds the first occurence of v in this view, starting at position pos.
370 ///
371 /// \returns Position of the first character of the found substring, or npos
372 /// if no such substring is found.
373 [[nodiscard]] constexpr auto find(basic_string_view v, size_type pos = 0) const noexcept -> size_type
374 {
375 if (v.empty()) {
376 return 0;
377 }
378
379 if (v.size() > size() - pos) {
380 return npos;
381 }
382
383 for (size_type outerIdx = pos; outerIdx < size(); ++outerIdx) {
384 if (unsafe_at(outerIdx) == v.front()) {
385 auto found = [&] {
386 for (size_type innerIdx = 0; innerIdx < v.size(); ++innerIdx) {
387 auto offset = outerIdx + innerIdx;
388 if (unsafe_at(offset) != v[innerIdx]) {
389 return false;
390 }
391 }
392
393 return true;
394 }();
395
396 if (found) {
397 return outerIdx;
398 }
399 }
400 }
401
402 return npos;
403 }
404
405 /// \brief Finds the first substring equal to the given character sequence.
406 /// Equivalent to find(basic_string_view(etl::addressof(ch), 1), pos)
407 ///
408 /// \returns Position of the first character of the found substring, or npos
409 /// if no such substring is found.
410 [[nodiscard]] constexpr auto find(Char ch, size_type pos = 0) const noexcept -> size_type
411 {
412 return find(basic_string_view(&ch, 1), pos);
413 }
414
415 /// \brief Finds the first substring equal to the given character sequence.
416 /// Equivalent to find(basic_string_view(s, count), pos)
417 ///
418 /// \returns Position of the first character of the found substring, or npos
419 /// if no such substring is found.
420 constexpr auto find(Char const* s, size_type pos, size_type count) const -> size_type
421 {
422 return find(basic_string_view(s, count), pos);
423 }
424
425 /// \brief Finds the first substring equal to the given character sequence.
426 /// Equivalent to find(basic_string_view(s), pos)
427 ///
428 /// \returns Position of the first character of the found substring, or npos
429 /// if no such substring is found.
430 constexpr auto find(Char const* s, size_type pos = 0) const -> size_type
431 {
432 return find(basic_string_view(s), pos);
433 }
434
435 /// \brief Finds the last substring equal to the given character sequence.
436 /// Finds the last occurence of v in this view, starting at position pos.
437 ///
438 /// \returns Position of the first character of the found substring or npos
439 /// if no such substring is found.
440 [[nodiscard]] constexpr auto rfind(basic_string_view sv, size_type pos = npos) const noexcept -> size_type
441 {
442 pos = etl::min(pos, size());
443 if (sv.size() < size() - pos) {
444 pos += sv.size();
445 } else {
446 pos = size();
447 }
448
449 auto const* r = etl::find_end(data(), data() + pos, sv.begin(), sv.end(), Traits::eq);
450 if (sv.size() > 0 && r == data() + pos) {
451 return npos;
452 }
453 return static_cast<size_type>(r - data());
454 }
455
456 /// \brief Finds the last substring equal to the given character sequence.
457 /// Equivalent to rfind(basic_string_view(&c, 1), pos).
458 ///
459 /// \returns Position of the first character of the found substring or npos
460 /// if no such substring is found.
461 [[nodiscard]] constexpr auto rfind(Char c, size_type pos = npos) const noexcept -> size_type
462 {
463 if (size() < 1) {
464 return npos;
465 }
466
467 if (pos < size()) {
468 ++pos;
469 } else {
470 pos = size();
471 }
472 for (auto const* s = data() + pos; s != data();) {
473 if (Traits::eq(*--s, c)) {
474 return static_cast<size_type>(s - data());
475 }
476 }
477 return npos;
478 }
479
480 /// \brief Finds the last substring equal to the given character sequence.
481 /// Equivalent to rfind(basic_string_view(s, count), pos).
482 ///
483 /// \returns Position of the first character of the found substring or npos
484 /// if no such substring is found.
485 constexpr auto rfind(Char const* s, size_type pos, size_type count) const noexcept -> size_type
486 {
487 return rfind({s, count}, pos);
488 }
489
490 /// \brief Finds the last substring equal to the given character sequence.
491 /// Equivalent to rfind(basic_string_view(s), pos).
492 ///
493 /// \returns Position of the first character of the found substring or npos
494 /// if no such substring is found.
495 constexpr auto rfind(Char const* s, size_type pos = npos) const noexcept -> size_type
496 {
497 return rfind({s, traits_type::length(s)}, pos);
498 }
499
500 /// \brief Finds the first character equal to any of the characters in the
501 /// given character sequence. Finds the first occurence of any of the
502 /// characters of v in this view, starting at position pos.
503 ///
504 /// \returns Position of the first occurrence of any character of the
505 /// substring, or npos if no such character is found.
506 [[nodiscard]] constexpr auto find_first_of(basic_string_view v, size_type pos = 0) const noexcept -> size_type
507 {
508 for (size_type idx = pos; idx < size(); ++idx) {
509 for (auto const c : v) {
510 if (c == unsafe_at(idx)) {
511 return idx;
512 }
513 }
514 }
515
516 return npos;
517 }
518
519 /// \brief Finds the first character equal to any of the characters in the
520 /// given character sequence. Equivalent to
521 /// find_first_of(basic_string_view(&c, 1), pos)
522 ///
523 /// \returns Position of the first occurrence of any character of the
524 /// substring, or npos if no such character is found.
525 [[nodiscard]] constexpr auto find_first_of(Char c, size_type pos = 0) const noexcept -> size_type
526 {
527 return find_first_of(basic_string_view(&c, 1), pos);
528 }
529
530 /// \brief Finds the first character equal to any of the characters in the
531 /// given character sequence. Equivalent to
532 /// find_first_of(basic_string_view(s, count), pos)
533 ///
534 /// \returns Position of the first occurrence of any character of the
535 /// substring, or npos if no such character is found.
536 constexpr auto find_first_of(Char const* s, size_type pos, size_type count) const -> size_type
537 {
538 return find_first_of(basic_string_view(s, count), pos);
539 }
540
541 /// \brief Finds the first character equal to any of the characters in the
542 /// given character sequence. Equivalent to
543 /// find_first_of(basic_string_view(s), pos)
544 ///
545 /// \returns Position of the first occurrence of any character of the
546 /// substring, or npos if no such character is found.
547 constexpr auto find_first_of(Char const* s, size_type pos = 0) const -> size_type
548 {
549 return find_first_of(basic_string_view(s), pos);
550 }
551
552 /// \brief Finds the first character not equal to any of the characters in
553 /// the given character sequence.
554 ///
555 /// \return Position of the first character not equal to any of the
556 /// characters in the given string, or npos if no such character is found.
557 [[nodiscard]] constexpr auto find_first_not_of(basic_string_view sv, size_type pos = 0) const noexcept -> size_type
558 {
559 auto const* str = data();
560 if (pos < size()) {
561 auto const* last = str + size();
562 for (auto const* s = str + pos; s != last; ++s) {
563 if (Traits::find(sv.data(), sv.size(), *s) == nullptr) {
564 return static_cast<size_type>(s - str);
565 }
566 }
567 }
568 return npos;
569 }
570
571 /// \brief Finds the first character not equal to any of the characters in
572 /// the given character sequence.
573 ///
574 /// \return Position of the first character not equal to any of the
575 /// characters in the given string, or npos if no such character is found.
576 [[nodiscard]] constexpr auto find_first_not_of(Char c, size_type pos = 0) const noexcept -> size_type
577 {
578 if (pos < size()) {
579 auto const* last = data() + size();
580 for (auto const* s = data() + pos; s != last; ++s) {
581 if (!Traits::eq(*s, c)) {
582 return static_cast<size_type>(s - data());
583 }
584 }
585 }
586 return npos;
587 }
588
589 /// \brief Finds the first character not equal to any of the characters in
590 /// the given character sequence.
591 ///
592 /// \return Position of the first character not equal to any of the
593 /// characters in the given string, or npos if no such character is found.
594 [[nodiscard]] constexpr auto find_first_not_of(Char const* s, size_type pos, size_type count) const -> size_type
595 {
596 return find_first_not_of({s, count}, pos);
597 }
598
599 /// \brief Finds the first character not equal to any of the characters in
600 /// the given character sequence.
601 ///
602 /// \return Position of the first character not equal to any of the
603 /// characters in the given string, or npos if no such character is found.
604 [[nodiscard]] constexpr auto find_first_not_of(Char const* s, size_type pos = 0) const -> size_type
605 {
606 return find_first_not_of({s, traits_type::length(s)}, pos);
607 }
608
609 /// \brief Finds the last character equal to one of characters in the given
610 /// character sequence. Exact search algorithm is not specified. The search
611 /// considers only the interval [0; pos]. If the character is not present in
612 /// the interval, npos will be returned. Finds the last occurence of any of
613 /// the characters of v in this view, ending at position pos.
614 ///
615 /// \returns Position of the last occurrence of any character of the
616 /// substring, or npos if no such character is found.
617 [[nodiscard]] constexpr auto find_last_of(basic_string_view v, size_type pos = npos) const noexcept -> size_type
618 {
619 auto offset = etl::clamp<size_type>(pos, 0, size() - 1);
620 do { // NOLINT(cppcoreguidelines-avoid-do-while)
621 auto const current = unsafe_at(offset);
622 for (auto const ch : v) {
623 if (ch == current) {
624 return offset;
625 }
626 }
627 } while (offset-- != 0);
628
629 return npos;
630 }
631
632 /// \brief Finds the last character equal to one of characters in the given
633 /// character sequence. Exact search algorithm is not specified. The search
634 /// considers only the interval [0; pos]. If the character is not present in
635 /// the interval, npos will be returned. Equivalent to
636 /// find_last_of(basic_string_view(&c, 1), pos).
637 ///
638 /// \returns Position of the last occurrence of any character of the
639 /// substring, or npos if no such character is found.
640 [[nodiscard]] constexpr auto find_last_of(Char c, size_type pos = npos) const noexcept -> size_type
641 {
642 return find_last_of(basic_string_view(&c, 1), pos);
643 }
644
645 /// \brief Finds the last character equal to one of characters in the given
646 /// character sequence. Exact search algorithm is not specified. The search
647 /// considers only the interval [0; pos]. If the character is not present in
648 /// the interval, npos will be returned. Equivalent to
649 /// find_last_of(basic_string_view(s, count), pos).
650 ///
651 /// \returns Position of the last occurrence of any character of the
652 /// substring, or npos if no such character is found.
653 constexpr auto find_last_of(Char const* s, size_type pos, size_type count) const -> size_type
654 {
655 return find_last_of(basic_string_view(s, count), pos);
656 }
657
658 /// \brief Finds the last character equal to one of characters in the given
659 /// character sequence. Exact search algorithm is not specified. The search
660 /// considers only the interval [0; pos]. If the character is not present in
661 /// the interval, npos will be returned. Equivalent to
662 /// find_last_of(basic_string_view(s), pos).
663 ///
664 /// \returns Position of the last occurrence of any character of the
665 /// substring, or npos if no such character is found.
666 constexpr auto find_last_of(Char const* s, size_type pos = npos) const -> size_type
667 {
668 return find_last_of(basic_string_view(s), pos);
669 }
670
671 /// \brief Finds the last character not equal to any of the characters of v
672 /// in this view, starting at position pos.
673 ///
674 /// \returns Position of the last character not equal to any of the
675 /// characters in the given string, or npos if no such character is found.
676 [[nodiscard]] constexpr auto find_last_not_of(basic_string_view v, size_type pos = npos) const noexcept -> size_type
677 {
678 auto offset = etl::clamp<size_type>(pos, 0, size() - 1);
679 do { // NOLINT(cppcoreguidelines-avoid-do-while)
680 auto equals = [&](auto ch) { return ch == unsafe_at(offset); };
681 if (etl::none_of(v.begin(), v.end(), equals)) {
682 return offset;
683 }
684 } while (offset-- != 0);
685
686 return npos;
687 }
688
689 /// \brief Finds the last character not equal to any of the characters in
690 /// the given character sequence. Equivalent to
691 /// find_last_not_of(basic_string_view(&c, 1), pos).
692 ///
693 /// \returns Position of the last character not equal to any of the
694 /// characters in the given string, or npos if no such character is found.
695 [[nodiscard]] constexpr auto find_last_not_of(Char c, size_type pos = npos) const noexcept -> size_type
696 {
697 return find_last_not_of(basic_string_view(&c, 1), pos);
698 }
699
700 /// \brief Finds the last character not equal to any of the characters in
701 /// the given character sequence. Equivalent to
702 /// find_last_not_of(basic_string_view(s, count), pos).
703 ///
704 /// \returns Position of the last character not equal to any of the
705 /// characters in the given string, or npos if no such character is found.
706 [[nodiscard]] constexpr auto find_last_not_of(const_pointer s, size_type pos, size_type count) const -> size_type
707 {
708 return find_last_not_of(basic_string_view(s, count), pos);
709 }
710
711 /// \brief Finds the last character not equal to any of the characters in
712 /// the given character sequence. Equivalent to
713 /// find_last_not_of(basic_string_view(s), pos)
714 ///
715 /// \returns Position of the last character not equal to any of the
716 /// characters in the given string, or npos if no such character is found.
717 [[nodiscard]] constexpr auto find_last_not_of(const_pointer s, size_type pos = npos) const -> size_type
718 {
719 return find_last_not_of(basic_string_view(s), pos);
720 }
721
722 /// \brief Checks if the string contains the given substring.
723 [[nodiscard]] constexpr auto contains(basic_string_view sv) const noexcept -> bool
724 {
725 return find(sv) != npos;
726 }
727
728 /// \brief Checks if the string contains the given substring.
729 [[nodiscard]] constexpr auto contains(Char c) const noexcept -> bool
730 {
731 return find(c) != npos;
732 }
733
734 /// \brief Checks if the string contains the given substring.
735 [[nodiscard]] constexpr auto contains(Char const* s) const -> bool
736 {
737 return find(s) != npos;
738 }
739
740 /// \brief This is a special value equal to the maximum value
741 /// representable by the type size_type.
742 ///
743 /// \details The exact meaning depends on context, but it is generally
744 /// used either as end of view indicator by the functions that expect a
745 /// view index or as the error indicator by the functions that return a
746 /// view index.
747 static constexpr size_type npos = size_type(-1);
748
749private:
750 [[nodiscard]] constexpr auto unsafe_at(size_type pos) const -> const_reference
751 {
752 return _begin[pos];
753 }
754
755 const_pointer _begin = nullptr;
756 size_type _size = 0;
757};
758
759/// Typedef for common character type `char`
760/// \ingroup string_view
761using string_view = basic_string_view<char, etl::char_traits<char>>;
762
763/// Typedef for common character type `wchar_t`
764/// \ingroup string_view
765using wstring_view = basic_string_view<wchar_t, etl::char_traits<wchar_t>>;
766
767/// Typedef for common character type `char8_t`
768/// \ingroup string_view
769using u8string_view = basic_string_view<char8_t, etl::char_traits<char8_t>>;
770
771/// Typedef for common character type `char16_t`
772/// \ingroup string_view
773using u16string_view = basic_string_view<char16_t, etl::char_traits<char16_t>>;
774
775/// Typedef for common character type `char32_t`
776/// \ingroup string_view
777using u32string_view = basic_string_view<char32_t, etl::char_traits<char32_t>>;
778
779inline namespace literals {
780inline namespace string_view_literals {
781
782/// Forms a string view of a character literal. Returns etl::string_view{str, len}
783[[nodiscard]] constexpr auto operator""_sv(char const* str, etl::size_t len) noexcept -> etl::string_view
784{
785 return {str, len};
786}
787
788/// Forms a string view of a character literal. Returns etl::wstring_view{str, len}
789[[nodiscard]] constexpr auto operator""_sv(wchar_t const* str, etl::size_t len) noexcept -> etl::wstring_view
790{
791 return {str, len};
792}
793
794/// Forms a string view of a character literal. Returns etl::u8string_view{str, len}
795[[nodiscard]] constexpr auto operator""_sv(char8_t const* str, etl::size_t len) noexcept -> etl::u8string_view
796{
797 return {str, len};
798}
799
800/// Forms a string view of a character literal. Returns etl::u16string_view{str, len}
801[[nodiscard]] constexpr auto operator""_sv(char16_t const* str, etl::size_t len) noexcept -> etl::u16string_view
802{
803 return {str, len};
804}
805
806/// Forms a string view of a character literal. Returns etl::u32string_view{str, len}
807[[nodiscard]] constexpr auto operator""_sv(char32_t const* str, etl::size_t len) noexcept -> etl::u32string_view
808{
809 return {str, len};
810}
811
812} // namespace string_view_literals
813} // namespace literals
814
815namespace ranges {
816
817template <typename Char, typename Traits>
818inline constexpr bool enable_borrowed_range<etl::basic_string_view<Char, Traits>> = true;
819
820} // namespace ranges
821
822/// \brief Compares two views. All comparisons are done via the compare() member
823/// function (which itself is defined in terms of Traits::compare()):
824///
825/// \details Two views are equal if both the size of lhs and rhs are equal and
826/// each character in lhs has an equivalent character in rhs at the same
827/// position.
828template <typename Char, typename Traits>
829[[nodiscard]] constexpr auto
830operator==(basic_string_view<Char, Traits> lhs, type_identity_t<basic_string_view<Char, Traits>> rhs) noexcept -> bool
831{
832 if (lhs.size() != rhs.size()) {
833 return false;
834 }
835 return lhs.compare(rhs) == 0;
836}
837
838/// \brief Compares two views. All comparisons are done via the compare() member
839/// function (which itself is defined in terms of Traits::compare()):
840///
841/// \details The ordering comparisons are done lexicographically -- the
842/// comparison is performed by a function equivalent to
843/// lexicographical_compare.
844template <typename Char, typename Traits>
845[[nodiscard]] constexpr auto
846operator<(basic_string_view<Char, Traits> lhs, basic_string_view<Char, Traits> rhs) noexcept -> bool
847{
848 return lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
849}
850
851template <typename Char, typename Traits, int = 1>
852[[nodiscard]] constexpr auto
853operator<(type_identity_t<basic_string_view<Char, Traits>> lhs, basic_string_view<Char, Traits> rhs) noexcept -> bool
854{
855 return lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
856}
857
858template <typename Char, typename Traits, int = 2>
859[[nodiscard]] constexpr auto
860operator<(basic_string_view<Char, Traits> lhs, type_identity_t<basic_string_view<Char, Traits>> rhs) noexcept -> bool
861{
862 return lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
863}
864
865/// \brief Compares two views. All comparisons are done via the compare() member
866/// function (which itself is defined in terms of Traits::compare()):
867///
868/// \details The ordering comparisons are done lexicographically -- the
869/// comparison is performed by a function equivalent to
870/// lexicographical_compare.
871template <typename Char, typename Traits>
872[[nodiscard]] constexpr auto
873operator<=(basic_string_view<Char, Traits> lhs, basic_string_view<Char, Traits> rhs) noexcept -> bool
874{
875 return (lhs < rhs) or (lhs == rhs);
876}
877
878template <typename Char, typename Traits, int = 1>
879[[nodiscard]] constexpr auto
880operator<=(type_identity_t<basic_string_view<Char, Traits>> lhs, basic_string_view<Char, Traits> rhs) noexcept -> bool
881{
882 return (lhs < rhs) or (lhs == rhs);
883}
884
885template <typename Char, typename Traits, int = 2>
886[[nodiscard]] constexpr auto
887operator<=(basic_string_view<Char, Traits> lhs, type_identity_t<basic_string_view<Char, Traits>> rhs) noexcept -> bool
888{
889 return (lhs < rhs) or (lhs == rhs);
890}
891
892/// \brief Compares two views. All comparisons are done via the compare() member
893/// function (which itself is defined in terms of Traits::compare()):
894///
895/// \details The ordering comparisons are done lexicographically -- the
896/// comparison is performed by a function equivalent to
897/// lexicographical_compare.
898template <typename Char, typename Traits>
899[[nodiscard]] constexpr auto
900operator>(basic_string_view<Char, Traits> lhs, basic_string_view<Char, Traits> rhs) noexcept -> bool
901{
902 return !(lhs < rhs) and !(lhs == rhs);
903}
904
905template <typename Char, typename Traits, int = 1>
906[[nodiscard]] constexpr auto
907operator>(type_identity_t<basic_string_view<Char, Traits>> lhs, basic_string_view<Char, Traits> rhs) noexcept -> bool
908{
909 return !(lhs < rhs) and !(lhs == rhs);
910}
911
912template <typename Char, typename Traits, int = 2>
913[[nodiscard]] constexpr auto
914operator>(basic_string_view<Char, Traits> lhs, type_identity_t<basic_string_view<Char, Traits>> rhs) noexcept -> bool
915{
916 return !(lhs < rhs) and !(lhs == rhs);
917}
918
919/// \brief Compares two views. All comparisons are done via the compare() member
920/// function (which itself is defined in terms of Traits::compare()):
921///
922/// \details The ordering comparisons are done lexicographically -- the
923/// comparison is performed by a function equivalent to
924/// lexicographical_compare.
925template <typename Char, typename Traits>
926[[nodiscard]] constexpr auto
927operator>=(basic_string_view<Char, Traits> lhs, basic_string_view<Char, Traits> rhs) noexcept -> bool
928{
929 return lhs > rhs or lhs == rhs;
930}
931
932template <typename Char, typename Traits, int = 1>
933[[nodiscard]] constexpr auto
934operator>=(type_identity_t<basic_string_view<Char, Traits>> lhs, basic_string_view<Char, Traits> rhs) noexcept -> bool
935{
936 return lhs > rhs or lhs == rhs;
937}
938
939template <typename Char, typename Traits, int = 2>
940[[nodiscard]] constexpr auto
941operator>=(basic_string_view<Char, Traits> lhs, type_identity_t<basic_string_view<Char, Traits>> rhs) noexcept -> bool
942{
943 return lhs > rhs or lhs == rhs;
944}
945
946} // namespace etl
947
948#endif // TETL_BASIC_STRING_VIEW_STRING_VIEW_HPP
Definition basic_string_view.hpp:780
Definition day.hpp:129
Definition ranges_in_fun_result.hpp:12
Definition adjacent_find.hpp:9
constexpr auto operator<(basic_string_view< Char, Traits > lhs, type_identity_t< basic_string_view< Char, Traits > > rhs) noexcept -> bool
Definition basic_string_view.hpp:860
constexpr auto operator<(basic_string_view< Char, Traits > lhs, basic_string_view< Char, Traits > rhs) noexcept -> bool
Compares two views. All comparisons are done via the compare() member function (which itself is defin...
Definition basic_string_view.hpp:846
constexpr auto operator<=(basic_string_view< Char, Traits > lhs, type_identity_t< basic_string_view< Char, Traits > > rhs) noexcept -> bool
Definition basic_string_view.hpp:887
constexpr auto operator<(type_identity_t< basic_string_view< Char, Traits > > lhs, basic_string_view< Char, Traits > rhs) noexcept -> bool
Definition basic_string_view.hpp:853
constexpr auto operator==(basic_string_view< Char, Traits > lhs, type_identity_t< basic_string_view< Char, Traits > > rhs) noexcept -> bool
Compares two views. All comparisons are done via the compare() member function (which itself is defin...
Definition basic_string_view.hpp:830
constexpr auto operator>(basic_string_view< Char, Traits > lhs, type_identity_t< basic_string_view< Char, Traits > > rhs) noexcept -> bool
Definition basic_string_view.hpp:914
constexpr auto operator<=(type_identity_t< basic_string_view< Char, Traits > > lhs, basic_string_view< Char, Traits > rhs) noexcept -> bool
Definition basic_string_view.hpp:880
constexpr auto operator>(basic_string_view< Char, Traits > lhs, basic_string_view< Char, Traits > rhs) noexcept -> bool
Compares two views. All comparisons are done via the compare() member function (which itself is defin...
Definition basic_string_view.hpp:900
constexpr auto operator>=(basic_string_view< Char, Traits > lhs, basic_string_view< Char, Traits > rhs) noexcept -> bool
Compares two views. All comparisons are done via the compare() member function (which itself is defin...
Definition basic_string_view.hpp:927
constexpr auto operator>=(type_identity_t< basic_string_view< Char, Traits > > lhs, basic_string_view< Char, Traits > rhs) noexcept -> bool
Definition basic_string_view.hpp:934
constexpr auto operator<=(basic_string_view< Char, Traits > lhs, basic_string_view< Char, Traits > rhs) noexcept -> bool
Compares two views. All comparisons are done via the compare() member function (which itself is defin...
Definition basic_string_view.hpp:873
constexpr auto operator>=(basic_string_view< Char, Traits > lhs, type_identity_t< basic_string_view< Char, Traits > > rhs) noexcept -> bool
Definition basic_string_view.hpp:941
constexpr auto operator>(type_identity_t< basic_string_view< Char, Traits > > lhs, basic_string_view< Char, Traits > rhs) noexcept -> bool
Definition basic_string_view.hpp:907
The class template basic_string_view describes an object that can refer to a constant contiguous sequ...
Definition basic_string_view.hpp:35
constexpr auto compare(size_type pos1, size_type count1, Char const *s) const -> int
Compares two character sequences. Equivalent to substr(pos1, count1).compare(basic_string_view(s)).
Definition basic_string_view.hpp:304
constexpr auto compare(size_type pos1, size_type count1, Char const *s, size_type count2) const -> int
Compares two character sequences. Equivalent to substr(pos1, count1).compare(basic_string_view(s,...
Definition basic_string_view.hpp:310
constexpr auto ends_with(Char const *str) const -> bool
Checks if the string view ends with the given suffix, where the the prefix is a null-terminated chara...
Definition basic_string_view.hpp:363
constexpr auto rfind(Char const *s, size_type pos=npos) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view...
Definition basic_string_view.hpp:495
constexpr auto back() const -> const_reference
Returns reference to the last character in the view.
Definition basic_string_view.hpp:181
constexpr auto compare(Char const *s) const -> int
Compares two character sequences. Equivalent to compare(basic_string_view(s)).
Definition basic_string_view.hpp:298
constexpr auto find_first_of(Char const *s, size_type pos=0) const -> size_type
Finds the first character equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:547
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type size_type.
Definition basic_string_view.hpp:747
constexpr auto find_first_not_of(basic_string_view sv, size_type pos=0) const noexcept -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_string_view.hpp:557
constexpr auto rfind(basic_string_view sv, size_type pos=npos) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Finds the last occurence of v in this...
Definition basic_string_view.hpp:440
~basic_string_view() noexcept=default
constexpr basic_string_view(Char const *str, size_type size)
Constructs a view of the first count characters of the character array starting with the element poin...
Definition basic_string_view.hpp:64
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first character of the reversed view. It corresponds to the last ch...
Definition basic_string_view.hpp:136
constexpr auto rfind(Char const *s, size_type pos, size_type count) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view...
Definition basic_string_view.hpp:485
constexpr auto starts_with(Char const *str) const -> bool
Checks if the string view begins with the given prefix, where the the prefix is a null-terminated cha...
Definition basic_string_view.hpp:335
constexpr auto find(Char const *s, size_type pos=0) const -> size_type
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view...
Definition basic_string_view.hpp:430
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first character of the reversed view. It corresponds to the last ch...
Definition basic_string_view.hpp:129
constexpr auto copy(Char *dest, size_type count, size_type pos=0) const -> size_type
Copies the substring [pos, pos + rcount) to the character array pointed to by dest,...
Definition basic_string_view.hpp:247
constexpr auto find_last_of(Char const *s, size_type pos, size_type count) const -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_string_view.hpp:653
constexpr auto find(Char ch, size_type pos=0) const noexcept -> size_type
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view...
Definition basic_string_view.hpp:410
constexpr auto compare(size_type pos1, size_type count1, basic_string_view v) const -> int
Compares two character sequences. Equivalent to substr(pos1, count1).compare(v).
Definition basic_string_view.hpp:285
constexpr auto operator=(basic_string_view const &view) noexcept -> basic_string_view &=default
Replaces the view with that of view.
constexpr auto find(basic_string_view v, size_type pos=0) const noexcept -> size_type
Finds the first substring equal to the given character sequence. Finds the first occurence of v in th...
Definition basic_string_view.hpp:373
constexpr auto find_last_of(Char const *s, size_type pos=npos) const -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_string_view.hpp:666
constexpr auto find_first_not_of(Char const *s, size_type pos, size_type count) const -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_string_view.hpp:594
constexpr auto find_last_not_of(const_pointer s, size_type pos=npos) const -> size_type
Finds the last character not equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:717
constexpr auto find_last_not_of(Char c, size_type pos=npos) const noexcept -> size_type
Finds the last character not equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:695
constexpr auto contains(basic_string_view sv) const noexcept -> bool
Checks if the string contains the given substring.
Definition basic_string_view.hpp:723
constexpr auto rfind(Char c, size_type pos=npos) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Equivalent to rfind(basic_string_view...
Definition basic_string_view.hpp:461
constexpr auto find_last_not_of(const_pointer s, size_type pos, size_type count) const -> size_type
Finds the last character not equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:706
constexpr auto ends_with(Char c) const noexcept -> bool
Checks if the string view ends with the given suffix, where the prefix is a single character.
Definition basic_string_view.hpp:354
constexpr basic_string_view(nullptr_t)=delete
constexpr basic_string_view() noexcept=default
Default constructor. Constructs an empty basic_string_view. After construction, data() is equal to nu...
constexpr auto compare(basic_string_view v) const noexcept -> int
Compares two character sequences.
Definition basic_string_view.hpp:267
constexpr auto begin() const noexcept -> const_iterator
Returns an iterator to the first character of the view.
Definition basic_string_view.hpp:100
constexpr auto cbegin() const noexcept -> const_iterator
Returns an iterator to the first character of the view.
Definition basic_string_view.hpp:106
constexpr auto contains(Char c) const noexcept -> bool
Checks if the string contains the given substring.
Definition basic_string_view.hpp:729
constexpr basic_string_view(Iter first, Iter last)
Constructs a basic_string_view over the range [first, last). The behavior is undefined if [first,...
Definition basic_string_view.hpp:89
constexpr auto contains(Char const *s) const -> bool
Checks if the string contains the given substring.
Definition basic_string_view.hpp:735
constexpr auto front() const -> const_reference
Returns reference to the first character in the view.
Definition basic_string_view.hpp:173
constexpr auto empty() const noexcept -> bool
Checks if the view has no characters, i.e. whether size() == 0.
Definition basic_string_view.hpp:215
constexpr auto compare(size_type pos1, size_type count1, basic_string_view v, size_type pos2, size_type count2) const -> int
Compares two character sequences. Equivalent to substr(pos1, count1).compare(v.substr(pos2,...
Definition basic_string_view.hpp:292
constexpr auto starts_with(basic_string_view sv) const noexcept -> bool
Checks if the string view begins with the given prefix, where the prefix is a string view.
Definition basic_string_view.hpp:318
constexpr auto substr(size_type pos=0, size_type count=npos) const -> basic_string_view
Returns a view of the substring [pos, pos + rcount), where rcount is the smaller of count and size() ...
Definition basic_string_view.hpp:257
constexpr auto remove_suffix(size_type n) -> void
Moves the end of the view back by n characters.
Definition basic_string_view.hpp:231
constexpr auto find_last_of(Char c, size_type pos=npos) const noexcept -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_string_view.hpp:640
constexpr auto find(Char const *s, size_type pos, size_type count) const -> size_type
Finds the first substring equal to the given character sequence. Equivalent to find(basic_string_view...
Definition basic_string_view.hpp:420
constexpr basic_string_view(basic_string_view const &other) noexcept=default
Copy constructor. Constructs a view of the same content as other. After construction,...
constexpr auto find_last_of(basic_string_view v, size_type pos=npos) const noexcept -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_string_view.hpp:617
constexpr auto length() const noexcept -> size_type
Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()).
Definition basic_string_view.hpp:202
constexpr auto find_first_of(Char const *s, size_type pos, size_type count) const -> size_type
Finds the first character equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:536
constexpr auto swap(basic_string_view &v) noexcept -> void
Exchanges the view with that of v.
Definition basic_string_view.hpp:238
constexpr auto max_size() const noexcept -> size_type
The largest possible number of char-like objects that can be referred to by a basic_string_view.
Definition basic_string_view.hpp:209
constexpr basic_string_view(Char const *str)
Constructs a view of the null-terminated character string pointed to by s, not including the terminat...
Definition basic_string_view.hpp:75
constexpr auto end() const noexcept -> const_iterator
Returns an iterator to the character following the last character of the view. This character acts as...
Definition basic_string_view.hpp:114
constexpr auto remove_prefix(size_type n) -> void
Moves the start of the view forward by n characters.
Definition basic_string_view.hpp:222
constexpr auto starts_with(Char c) const noexcept -> bool
Checks if the string view begins with the given prefix, where the prefix is a single character.
Definition basic_string_view.hpp:326
constexpr auto operator[](size_type pos) const -> const_reference
Returns a const reference to the character at specified location pos.
Definition basic_string_view.hpp:165
constexpr auto find_first_not_of(Char const *s, size_type pos=0) const -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_string_view.hpp:604
constexpr auto find_last_not_of(basic_string_view v, size_type pos=npos) const noexcept -> size_type
Finds the last character not equal to any of the characters of v in this view, starting at position p...
Definition basic_string_view.hpp:676
constexpr auto find_first_of(Char c, size_type pos=0) const noexcept -> size_type
Finds the first character equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:525
constexpr auto crend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the character following the last character of the reversed view.
Definition basic_string_view.hpp:158
constexpr auto ends_with(basic_string_view sv) const noexcept -> bool
Checks if the string view ends with the given suffix, where the prefix is a string view.
Definition basic_string_view.hpp:345
constexpr auto find_first_of(basic_string_view v, size_type pos=0) const noexcept -> size_type
Finds the first character equal to any of the characters in the given character sequence....
Definition basic_string_view.hpp:506
constexpr auto data() const noexcept -> const_pointer
Returns a pointer to the underlying character array. The pointer is such that the range [data(); data...
Definition basic_string_view.hpp:190
constexpr auto rend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the character following the last character of the reversed view.
Definition basic_string_view.hpp:147
constexpr auto size() const noexcept -> size_type
Returns the number of Char elements in the view, i.e. etl::distance(begin(), end()).
Definition basic_string_view.hpp:196
constexpr auto cend() const noexcept -> const_iterator
Returns an iterator to the character following the last character of the view. This character acts as...
Definition basic_string_view.hpp:122
constexpr auto find_first_not_of(Char c, size_type pos=0) const noexcept -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_string_view.hpp:576