tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
basic_inplace_string.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3#ifndef TETL_STRING_BASIC_INPLACE_STRING_HPP
4#define TETL_STRING_BASIC_INPLACE_STRING_HPP
5
6#include <etl/_algorithm/copy.hpp>
7#include <etl/_algorithm/fill.hpp>
8#include <etl/_algorithm/max.hpp>
9#include <etl/_algorithm/remove.hpp>
10#include <etl/_algorithm/rotate.hpp>
11#include <etl/_algorithm/swap_ranges.hpp>
12#include <etl/_array/array.hpp>
13#include <etl/_contracts/check.hpp>
14#include <etl/_cstring/memset.hpp>
15#include <etl/_iterator/begin.hpp>
16#include <etl/_iterator/data.hpp>
17#include <etl/_iterator/distance.hpp>
18#include <etl/_iterator/end.hpp>
19#include <etl/_iterator/next.hpp>
20#include <etl/_iterator/prev.hpp>
21#include <etl/_iterator/rbegin.hpp>
22#include <etl/_iterator/rend.hpp>
23#include <etl/_iterator/size.hpp>
24#include <etl/_limits/numeric_limits.hpp>
25#include <etl/_string/char_traits.hpp>
26#include <etl/_string/str_replace.hpp>
27#include <etl/_string_view/basic_string_view.hpp>
28#include <etl/_strings/find.hpp>
29#include <etl/_strings/rfind.hpp>
30#include <etl/_type_traits/is_convertible.hpp>
31#include <etl/_type_traits/smallest_size_t.hpp>
32#include <etl/_utility/ignore_unused.hpp>
33
34namespace etl {
35
36/// \brief basic_inplace_string class with fixed size capacity.
37/// \tparam Char Build in type for character size (mostly 'char')
38/// \tparam Capacity Usable capacity for basic_inplace_string (excluding null terminator)
39/// \headerfile etl/string.hpp
40/// \include string.cpp
41template <typename Char, etl::size_t Capacity, typename Traits = etl::char_traits<Char>>
43 template <typename T>
44 static constexpr bool string_view_like = //
46 and not is_convertible_v<T const&, Char const*>;
47
48 using internal_size_t = etl::smallest_size_t<Capacity>;
49
50public:
51 using value_type = Char;
52 using size_type = etl::size_t;
53 using difference_type = etl::ptrdiff_t;
54 using traits_type = Traits;
55 using pointer = Char*;
56 using const_pointer = Char const*;
57 using reference = Char&;
58 using const_reference = Char const&;
59 using iterator = Char*;
60 using const_iterator = Char const*;
61 using reverse_iterator = etl::reverse_iterator<iterator>;
62 using const_reverse_iterator = etl::reverse_iterator<const_iterator>;
63
64 /// Default constructor.
65 constexpr basic_inplace_string() = default;
66
67 /// Character pointer constructor.
68 /// \pre len <= Capacity
69 constexpr basic_inplace_string(const_pointer str, size_type const len) noexcept
70 {
71 TETL_PRECONDITION(len <= Capacity);
72 unsafe_set_size(len);
73 traits_type::copy(_storage.data(), str, len);
74 }
75
76 /// Character pointer constructor. Calls traits_type::length.
77 /// \pre Length of \p str must be <= Capacity
78 constexpr basic_inplace_string(const_pointer str) noexcept
79 : basic_inplace_string(str, traits_type::length(str))
80 {
81 }
82
83 constexpr basic_inplace_string(nullptr_t /*null*/) = delete;
84
85 /// Constructs the string with count copies of character ch.
86 /// \pre count <= Capacity
87 constexpr basic_inplace_string(size_type count, Char ch) noexcept
88 {
89 TETL_PRECONDITION(count <= Capacity);
90 fill(begin(), begin() + count, ch);
91 unsafe_set_size(count);
92 }
93
94 /// Constructs the string with the contents of the range [ first,
95 /// last). Fails silently if input length is greater then capacity.
96 template <typename InputIt>
97 requires(detail::InputIterator<InputIt>)
98 constexpr basic_inplace_string(InputIt first, InputIt last) noexcept
99 : basic_inplace_string(first, static_cast<size_type>(distance(first, last)))
100 {
101 }
102
103 /// Constructs the string with a substring [pos, pos+count) of other.
104 constexpr basic_inplace_string(basic_inplace_string const& other, size_type pos, size_type count)
105 : basic_inplace_string{other.substr(pos, count)}
106 {
107 }
108
109 /// Constructs the string with a substring [pos, other.size()).
110 constexpr basic_inplace_string(basic_inplace_string const& other, size_type pos)
111 : basic_inplace_string{other.substr(pos, other.size())}
112 {
113 }
114
115 /// Implicitly converts view to a string view sv, then initializes the
116 /// string with the contents of sv.
117 template <typename StringView>
118 requires string_view_like<StringView>
119 explicit constexpr basic_inplace_string(StringView const& view) noexcept
120
121 {
122 basic_string_view<Char, traits_type> const sv = view;
123 assign(sv.begin(), sv.end());
124 }
125
126 /// Implicitly converts view to a string view sv, then initializes the
127 /// string with the subrange [ pos, pos + n ) of sv.
128 template <typename StringView>
129 requires string_view_like<StringView>
130 explicit constexpr basic_inplace_string(StringView const& view, size_type pos, size_type n)
131 : basic_inplace_string{basic_string_view<Char, traits_type>{view}.substr(pos, n)}
132 {
133 }
134
135 /// Defaulted copy constructor.
136 constexpr basic_inplace_string(basic_inplace_string const& /*str*/) noexcept = default;
137
138 /// Defaulted move constructor.
139 constexpr basic_inplace_string(basic_inplace_string&& /*str*/) noexcept = default;
140
141 /// Defaulted copy assignment.
142 constexpr auto operator=(basic_inplace_string const& /*str*/) noexcept -> basic_inplace_string& = default;
143
144 /// Defaulted move assignment.
145 constexpr auto operator=(basic_inplace_string&& /*str*/) noexcept -> basic_inplace_string& = default;
146
147 /// Replaces the contents with those of null-terminated character
148 /// string pointed to by s.
149 constexpr auto operator=(const_pointer s) noexcept -> basic_inplace_string&
150 {
151 auto const len = traits_type::length(s);
152 TETL_PRECONDITION(len <= capacity());
153 assign(s, len);
154 return *this;
155 }
156
157 constexpr auto operator=(nullptr_t /*0*/) -> basic_inplace_string& = delete;
158
159 /// Replaces the contents with character ch.
160 constexpr auto operator=(Char ch) noexcept -> basic_inplace_string&
161 {
162 assign(&ch, 1);
163 return *this;
164 }
165
166 /// Implicitly converts view to a string view sv, then replaces the
167 /// contents with those of the sv.
168 template <typename StringView>
169 requires string_view_like<StringView>
170 constexpr auto operator=(StringView const& view) noexcept -> basic_inplace_string&
171 {
172 assign(view);
173 return *this;
174 }
175
176 /// Replaces the contents with count copies of character ch.
177 constexpr auto assign(size_type count, Char ch) noexcept -> basic_inplace_string&
178 {
179 TETL_PRECONDITION(count <= capacity());
180 (*this) = basic_inplace_string{count, ch};
181 return *this;
182 }
183
184 /// Replaces the contents with a copy of str.
185 constexpr auto assign(basic_inplace_string const& str) noexcept -> basic_inplace_string&
186 {
187 *this = str;
188 return *this;
189 }
190
191 /// Replaces the contents with a substring [ pos, pos + count )
192 /// of str.
193 constexpr auto assign(basic_inplace_string const& str, size_type pos, size_type count = npos) noexcept
195 {
196 *this = str.substr(pos, count);
197 return *this;
198 }
199
200 /// Replaces the contents with copies of the characters in the range
201 /// [ s, s + count ). This range can contain null characters.
202 constexpr auto assign(const_pointer s, size_type count) noexcept -> basic_inplace_string&
203 {
204 TETL_PRECONDITION(count <= capacity());
205 *this = basic_inplace_string{s, count};
206 return *this;
207 }
208
209 /// \brief Replaces the contents with those of null-terminated character
210 /// string pointed to by s.
211 constexpr auto assign(const_pointer s) noexcept -> basic_inplace_string&
212 {
213 *this = basic_inplace_string{s, traits_type::length(s)};
214 return *this;
215 }
216
217 /// \brief Replaces the contents with copies of the characters in the
218 /// range [ first , last ).
219 template <typename InputIt>
220 requires(detail::InputIterator<InputIt>)
221 constexpr auto assign(InputIt first, InputIt last) noexcept -> basic_inplace_string&
222 {
223 *this = basic_inplace_string{first, last};
224 return *this;
225 }
226
227 /// \brief Implicitly converts view to a string view sv, then replaces the
228 /// contents with the characters from sv.
229 template <typename StringView>
230 requires string_view_like<StringView>
231 constexpr auto assign(StringView const& view) noexcept -> basic_inplace_string&
232 {
233 auto tmp = basic_inplace_string{view};
234 *this = tmp;
235 return *this;
236 }
237
238 /// \brief Implicitly converts view to a string view sv, then replaces the
239 /// contents with the characters from the subview [ pos, pos + count ) of
240 /// sv.
241 template <typename StringView>
242 requires string_view_like<StringView>
243 constexpr auto assign(StringView const& view, size_type pos, size_type count = npos) noexcept
245 {
246 auto tmp = basic_inplace_string{view, pos, count};
247 *this = tmp;
248 return *this;
249 }
250
251 /// \brief Accesses the specified character without bounds checking.
252 constexpr auto operator[](size_type index) noexcept -> reference
253 {
254 return unsafe_at(index);
255 }
256
257 /// \brief Accesses the specified character without bounds checking.
258 constexpr auto operator[](size_type index) const noexcept -> const_reference
259 {
260 return unsafe_at(index);
261 }
262
263 /// \brief Returns an iterator to the beginning.
264 constexpr auto begin() noexcept -> iterator
265 {
266 return data();
267 }
268
269 /// \brief Returns an const iterator to the beginning.
270 [[nodiscard]] constexpr auto begin() const noexcept -> const_iterator
271 {
272 return data();
273 }
274
275 /// \brief Returns an const iterator to the beginning.
276 [[nodiscard]] constexpr auto cbegin() const noexcept -> const_iterator
277 {
278 return begin();
279 }
280
281 /// \brief Returns an iterator to the end.
282 constexpr auto end() noexcept -> iterator
283 {
284 return etl::next(begin(), static_cast<ptrdiff_t>(size()));
285 }
286
287 /// \brief Returns an const iterator to the end.
288 [[nodiscard]] constexpr auto end() const noexcept -> const_iterator
289 {
290 return etl::next(begin(), static_cast<ptrdiff_t>(size()));
291 }
292
293 /// \brief Returns an const iterator to the end.
294 [[nodiscard]] constexpr auto cend() const noexcept -> const_iterator
295 {
296 return end();
297 }
298
299 /// \brief Returns a reverse iterator to the first character of the reversed
300 /// string. It corresponds to the last character of the non-reversed string.
301 [[nodiscard]] constexpr auto rbegin() noexcept -> reverse_iterator
302 {
303 return reverse_iterator(end());
304 }
305
306 /// \brief Returns a reverse iterator to the first character of the reversed
307 /// string. It corresponds to the last character of the non-reversed string.
308 [[nodiscard]] constexpr auto rbegin() const noexcept -> const_reverse_iterator
309 {
310 return const_reverse_iterator(end());
311 }
312
313 /// \brief Returns a reverse iterator to the first character of the reversed
314 /// string. It corresponds to the last character of the non-reversed string.
315 [[nodiscard]] constexpr auto crbegin() const noexcept -> const_reverse_iterator
316 {
317 return rbegin();
318 }
319
320 /// \brief Returns a reverse iterator to the first character of the reversed
321 /// string. It corresponds to the last character of the non-reversed string.
322 [[nodiscard]] constexpr auto rend() noexcept -> reverse_iterator
323 {
324 return reverse_iterator(begin());
325 }
326
327 /// \brief Returns a reverse iterator to the first character of the reversed
328 /// string. It corresponds to the last character of the non-reversed string.
329 [[nodiscard]] constexpr auto rend() const noexcept -> const_reverse_iterator
330 {
331 return const_reverse_iterator(begin());
332 }
333
334 /// \brief Returns a reverse iterator to the first character of the reversed
335 /// string. It corresponds to the last character of the non-reversed string.
336 [[nodiscard]] constexpr auto crend() const noexcept -> const_reverse_iterator
337 {
338 return rend();
339 }
340
341 /// \brief Accesses the first character.
342 [[nodiscard]] constexpr auto front() noexcept -> reference
343 {
344 TETL_PRECONDITION(not empty());
345 return *begin();
346 }
347
348 /// \brief Accesses the first character.
349 [[nodiscard]] constexpr auto front() const noexcept -> const_reference
350 {
351 TETL_PRECONDITION(not empty());
352 return *begin();
353 }
354
355 /// \brief Accesses the last character.
356 [[nodiscard]] constexpr auto back() noexcept -> reference
357 {
358 TETL_PRECONDITION(not empty());
359 return *etl::prev(end());
360 }
361
362 /// \brief Accesses the last character.
363 [[nodiscard]] constexpr auto back() const noexcept -> const_reference
364 {
365 TETL_PRECONDITION(not empty());
366 return *etl::prev(end());
367 }
368
369 /// \brief Checks whether the string is empty.
370 [[nodiscard]] constexpr auto empty() const noexcept -> bool
371 {
372 return size() == 0;
373 }
374
375 /// \brief Checks whether the string is full. i.e. size() == capacity()
376 [[nodiscard]] constexpr auto full() const noexcept -> bool
377 {
378 return size() == capacity();
379 }
380
381 /// \brief Returns the number of characters.
382 [[nodiscard]] constexpr auto size() const noexcept -> size_type
383 {
384 return _storage.get_size();
385 }
386
387 /// \brief Returns the number of characters.
388 [[nodiscard]] constexpr auto length() const noexcept -> size_type
389 {
390 return size();
391 }
392
393 /// \brief Returns the number of characters that can be held in allocated
394 /// storage, NOT including the null terminator.
395 [[nodiscard]] constexpr auto capacity() const noexcept -> size_type
396 {
397 return Capacity;
398 }
399
400 /// \brief Returns the number of characters that can be held in allocated
401 /// storage, NOT including the null terminator.
402 [[nodiscard]] constexpr auto max_size() const noexcept -> size_type
403 {
404 return Capacity;
405 }
406
407 /// \brief Reserve is a nop, since the capacity is fixed.
408 static constexpr auto reserve(size_type /*newCap*/) -> void { }
409
410 /// \brief Shrink to fit is a nop, since the capacity is fixed.
411 static constexpr auto shrink_to_fit() -> void { }
412
413 /// \brief Returns a pointer to the underlying array serving as character
414 /// storage. The pointer is such that the range [data(); data() + size()) is
415 /// valid and the values in it correspond to the values stored in the
416 /// string.
417 ///
418 /// \details Always null-terminated.
419 [[nodiscard]] constexpr auto data() noexcept -> pointer
420 {
421 return _storage.data();
422 }
423
424 /// \brief Returns a pointer to the underlying array serving as character
425 /// storage. The pointer is such that the range [data(); data() + size()) is
426 /// valid and the values in it correspond to the values stored in the
427 /// string.
428 ///
429 /// \details Always null-terminated.
430 [[nodiscard]] constexpr auto data() const noexcept -> const_pointer
431 {
432 return _storage.data();
433 }
434
435 /// \brief Returns a pointer to a null-terminated character array.
436 ///
437 /// The data is equivalent to those stored in the string. The pointer is
438 /// such that the range [c_str(); c_str() + size()] is valid and the values
439 /// in it correspond to the values stored in the string with an additional
440 /// null character after the last position.
441 [[nodiscard]] constexpr auto c_str() const noexcept -> const_pointer
442 {
443 return data();
444 }
445
446 /// \brief Returns a etl::basic_string_view.
447 [[nodiscard]] constexpr operator basic_string_view<Char, traits_type>() const noexcept
448 {
449 return basic_string_view<Char, traits_type>(data(), size());
450 }
451
452 /// \brief Removes all characters from the string. Sets size to 0 and
453 /// overrides the buffer with zeros.
454 constexpr auto clear() noexcept -> void
455 {
456 *begin() = Char(0);
457 unsafe_set_size(0);
458 }
459
460 /// \brief Removes min(count, size() - index) characters starting at index.
461 ///
462 /// \returns *this
463 constexpr auto erase(size_type index = 0, size_type count = npos) noexcept -> basic_inplace_string&
464 {
465 auto safeCount = etl::min(count, size() - index);
466 erase(begin() + index, begin() + index + safeCount);
467 return *this;
468 }
469
470 /// \brief Removes the character at position.
471 ///
472 /// \returns iterator pointing to the character immediately following the
473 /// character erased, or end() if no such character exists.
474 constexpr auto erase(const_iterator position) noexcept -> iterator
475 {
476 return erase(position, position + 1);
477 }
478
479 /// \brief Removes the characters in the range [first, last).
480 ///
481 /// \returns iterator pointing to the character last pointed to before the
482 /// erase, or end() if no such character exists.
483 constexpr auto erase(const_iterator first, const_iterator last) noexcept -> iterator
484 {
485 auto const start = static_cast<size_type>(etl::distance(cbegin(), first));
486 auto const distance = static_cast<size_type>(etl::distance(first, last));
487 TETL_PRECONDITION(size() > distance);
488 etl::rotate(begin() + start, begin() + start + distance, end());
489 unsafe_set_size(size() - distance);
490 return begin() + start;
491 }
492
493 /// \brief Appends the given character ch to the end of the string.
494 /// \pre size() < capacity()
495 constexpr auto push_back(Char ch) noexcept -> void
496 {
497 TETL_PRECONDITION(size() < capacity());
498 append(1, ch);
499 }
500
501 /// \brief Removes the last character from the string.
502 /// \pre size() != 0
503 constexpr auto pop_back() noexcept -> void
504 {
505 TETL_PRECONDITION(not empty());
506 unsafe_set_size(size() - 1);
507 }
508
509 /// \brief Appends count copies of character s.
510 constexpr auto append(size_type const count, Char const s) noexcept -> basic_inplace_string&
511 {
512 auto const safeCount = etl::min(count, capacity() - size());
513 auto const newSize = size() + safeCount;
514 etl::fill(end(), etl::next(begin(), static_cast<ptrdiff_t>(newSize)), s);
515 unsafe_set_size(newSize);
516 return *this;
517 }
518
519 /// \brief Appends the null-terminated character string pointed to by s. The
520 /// length of the string is determined by the first null character using
521 constexpr auto append(const_pointer s) noexcept -> basic_inplace_string&
522 {
523 auto const len = traits_type::length(s);
524 return append(s, len);
525 }
526
527 /// \brief Appends characters in the range [ str, str + count ). This range can
528 /// contain null characters.
529 constexpr auto append(const_pointer str, size_type count) noexcept -> basic_inplace_string&
530 {
531 auto const safeCount = etl::min(count, capacity() - size());
532 etl::copy(str, etl::next(str, static_cast<ptrdiff_t>(safeCount)), end());
533 unsafe_set_size(size() + safeCount);
534 return *this;
535 }
536
537 /// \brief Appends characters in the range [ first , last ).
538 template <typename InputIt>
539 requires(detail::InputIterator<InputIt>)
540 constexpr auto append(InputIt first, InputIt last) noexcept -> basic_inplace_string&
541 {
542 for (; first != last; ++first) {
543 push_back(*first);
544 }
545 return *this;
546 }
547
548 /// \brief Appends string str.
549 constexpr auto append(basic_inplace_string const& str) noexcept -> basic_inplace_string&
550 {
551 return append(str.begin(), str.end());
552 }
553
554 /// \brief Appends a substring [ pos, pos + count ) of str.
555 constexpr auto append(basic_inplace_string const& str, size_type pos, size_type count = npos) noexcept
557 {
558 return append(str.substr(pos, count));
559 }
560
561 /// \brief Implicitly converts view to a string_view sv, then appends all
562 /// characters from sv.
563 template <typename StringView>
564 requires string_view_like<StringView>
565 constexpr auto append(StringView const& view) -> basic_inplace_string&
566 {
567 etl::basic_string_view<Char, traits_type> sv = view;
568 return append(sv.data(), sv.size());
569 }
570
571 /// \brief Implicitly converts view to a string_view sv then appends the
572 /// characters from the subview [ pos, pos + count ) of sv.
573 template <typename StringView>
574 requires string_view_like<StringView>
575 constexpr auto append(StringView const& view, size_type pos, size_type count = npos) -> basic_inplace_string&
576 {
577 etl::basic_string_view<Char, traits_type> sv = view;
578 return append(sv.substr(pos, count));
579 }
580
581 /// \brief Appends string str.
582 constexpr auto operator+=(basic_inplace_string const& str) noexcept -> basic_inplace_string&
583 {
584 return append(str);
585 }
586
587 /// \brief Appends character ch.
588 constexpr auto operator+=(Char ch) noexcept -> basic_inplace_string&
589 {
590 return append(1, ch);
591 }
592
593 /// \brief Appends the null-terminated character string pointed to by s.
594 constexpr auto operator+=(const_pointer s) noexcept -> basic_inplace_string&
595 {
596 return append(s);
597 }
598
599 /// \brief Implicitly converts view to a string view sv, then appends
600 /// characters in the string view sv.
601 template <typename StringView>
602 requires string_view_like<StringView>
603 constexpr auto operator+=(StringView const& view) noexcept -> basic_inplace_string&
604 {
605 return append(view);
606 }
607
608 /// \brief Inserts count copies of character ch at the position index.
609 constexpr auto insert(size_type const index, size_type const count, Char const ch) noexcept -> basic_inplace_string&
610 {
611 for (size_type i = 0; i < count; ++i) {
612 insert_impl(begin() + index, &ch, 1);
613 }
614 return *this;
615 }
616
617 /// \brief Inserts null-terminated character string pointed to by s at the
618 /// position index.
619 constexpr auto insert(size_type const index, const_pointer s) noexcept -> basic_inplace_string&
620 {
621 insert_impl(begin() + index, s, traits_type::length(s));
622 return *this;
623 }
624
625 /// \brief Inserts the characters in the range [s, s+count) at the position
626 /// index. The range can contain null characters.
627 constexpr auto insert(size_type const index, const_pointer s, size_type const count) noexcept
629 {
630 insert_impl(begin() + index, s, count);
631 return *this;
632 }
633
634 /// \brief Inserts string str at the position index.
635 constexpr auto insert(size_type const index, basic_inplace_string const& str) noexcept -> basic_inplace_string&
636 {
637 insert_impl(begin() + index, str.data(), str.size());
638 return *this;
639 }
640
641 /// \brief Inserts a string, obtained by str.substr(index_str, count) at the
642 /// position index.
643 constexpr auto insert(
644 size_type const index,
645 basic_inplace_string const& str,
646 size_type const indexStr,
647 size_type const count = npos
648 ) noexcept -> basic_inplace_string&
649 {
650 using view_type = basic_string_view<Char, traits_type>;
651 auto sv = view_type(str).substr(indexStr, count);
652 insert_impl(begin() + index, sv.data(), sv.size());
653 return *this;
654 }
655
656 //
657 // * \brief Inserts character ch before the character pointed by pos.
658 // constexpr auto insert(const_iterator pos, Char const ch) noexcept
659 // -> iterator
660 // {
661 // }
662
663 //
664 // * \brief Inserts count copies of character ch before the element (if
665 // any) pointed by
666 // * pos.
667 // constexpr auto insert(const_iterator pos, size_type count,
668 // Char const ch) noexcept -> iterator
669 // {
670 // }
671
672 //
673 // * \brief Inserts characters from the range [first, last) before the
674 // element (if any)
675 // * pointed by pos.
676 // template <typename InputIter>
677 // requires(detail::InputIterator<T>)
678 // constexpr auto insert(const_iterator pos, InputIter first, InputIter
679 // last) noexcept
680 // -> iterator
681 // {
682 // }
683
684 /// \brief Implicitly converts view to a string view sv, then inserts the
685 /// elements from sv before the element (if any) pointed by pos.
686 template <typename StringView>
687 requires string_view_like<StringView>
688 constexpr auto insert(size_type const pos, StringView const& view) noexcept -> basic_inplace_string&
689 {
690 basic_string_view<Char, traits_type> sv = view;
691 insert_impl(begin() + pos, sv.data(), sv.size());
692 return *this;
693 }
694
695 /// \brief Implicitly converts view to a string view sv, then inserts, before
696 /// the element (if any) pointed by pos, the characters from the subview
697 /// [index_str, index_str+count) of sv.
698 template <typename StringView>
699 requires string_view_like<StringView>
700 constexpr auto insert(
701 size_type const index,
702 StringView const& view,
703 size_type const indexStr,
704 size_type const count = npos
705 ) noexcept -> basic_inplace_string&
706 {
707 basic_string_view<Char, traits_type> sv = view;
708
709 auto sub = sv.substr(indexStr, count);
710 insert_impl(begin() + index, sub.data(), sub.size());
711 return *this;
712 }
713
714 /// \brief Compares this string to str.
715 [[nodiscard]] constexpr auto compare(basic_inplace_string const& str) const noexcept -> int
716 {
717 return basic_string_view<Char, Traits>{*this}.compare({str.data(), str.size()});
718 }
719
720 /// \brief Compares this string to str with other capacity.
721 template <size_type OtherCapacity>
722 [[nodiscard]] constexpr auto
723 compare(basic_inplace_string<Char, OtherCapacity, traits_type> const& str) const noexcept -> int
724 {
725 return basic_string_view<Char, Traits>{*this}.compare({str.data(), str.size()});
726 }
727
728 /// \brief Compares a [pos, pos+count) substring of this string to str. If
729 /// count > size() - pos the substring is [pos, size()).
730 [[nodiscard]] constexpr auto
731 compare(size_type const pos, size_type const count, basic_inplace_string const& str) const -> int
732 {
733 auto const sz = count > size() - pos ? size() : count;
734 auto const sub = basic_string_view<Char, Traits>(*this).substr(pos, sz);
735 return sub.compare(str);
736 }
737
738 /// \brief Compares a [pos1, pos1+count1) substring of this string to a
739 /// substring [pos2, pos2+count2) of str. If count1 > size() - pos1 the
740 /// first substring is [pos1, size()). Likewise, count2 > str.size() - pos2
741 /// the second substring is [pos2, str.size()).
742 [[nodiscard]] constexpr auto compare(
743 size_type const pos1,
744 size_type const count1,
745 basic_inplace_string const& str,
746 size_type const pos2,
747 size_type const count2 = npos
748 ) const -> int
749 {
750 auto const sz1 = count1 > size() - pos1 ? size() : count1;
751 auto const sub1 = basic_string_view<Char, Traits>(*this).substr(pos1, sz1);
752
753 auto const sz2 = count2 > str.size() - pos2 ? size() : count2;
754 auto const sub2 = basic_string_view<Char, Traits>(str).substr(pos2, sz2);
755
756 return sub1.compare(sub2);
757 }
758
759 /// \brief Compares this string to the null-terminated character sequence
760 /// beginning at the character pointed to by s with length
761 /// traits_type::length(s).
762 [[nodiscard]] constexpr auto compare(const_pointer s) const -> int
763 {
764 return basic_string_view<Char, Traits>{*this}.compare({s, traits_type::length(s)});
765 }
766
767 /// \brief Compares a [pos1, pos1+count1) substring of this string to the
768 /// null-terminated character sequence beginning at the character pointed to
769 /// by s with length traits_type::length(s). If count1 > size() - pos1 the
770 /// substring is [pos1, size()).
771 [[nodiscard]] constexpr auto compare(size_type const pos, size_type const count, const_pointer s) const -> int
772 {
773 auto const sz = count > size() - pos ? size() : count;
774 auto const sub = basic_string_view<Char, Traits>(*this).substr(pos, sz);
775 return sub.compare({s, traits_type::length(s)});
776 }
777
778 /// \brief Compares a [pos1, pos1+count1) substring of this string to the
779 /// characters in the range [s, s + count2). If count1 > size() - pos1 the
780 /// substring is [pos1, size()). (Note: the characters in the range [s, s +
781 /// count2) may include null characters.)
782 [[nodiscard]] constexpr auto
783 compare(size_type const pos1, size_type const count1, const_pointer s, size_type const count2) const -> int
784 {
785 auto const sz = count1 > size() - pos1 ? size() : count1;
786 auto const sub = basic_string_view<Char, Traits>(*this).substr(pos1, sz);
787 return sub.compare({s, count2});
788 }
789
790 /// \brief Implicitly converts view to a string view sv, then compares the
791 /// content of this string to sv.
792 template <typename StringView>
793 requires string_view_like<StringView>
794 [[nodiscard]] constexpr auto compare(StringView const& view) const noexcept -> int
795 {
796 using view_type = basic_string_view<Char, Traits>;
797 view_type const sv = view;
798 return view_type(*this).compare(sv);
799 }
800
801 /// \brief Implicitly converts view to a string view sv, then compares a [pos1,
802 /// pos1+count1) substring of this string to sv.
803 template <typename StringView>
804 requires string_view_like<StringView>
805 [[nodiscard]] constexpr auto compare(size_type pos1, size_type count1, StringView const& view) const noexcept -> int
806 {
807 using view_type = basic_string_view<Char, Traits>;
808 view_type const sv = view;
809 return view_type(*this).substr(pos1, count1).compare(sv);
810 }
811
812 /// \brief Implicitly converts view to a string view sv, then compares a [pos1,
813 /// pos1+count1) substring of this string to a substring [pos2, pos2+count2)
814 /// of sv.
815 template <typename StringView>
816 requires string_view_like<StringView>
817 [[nodiscard]] constexpr auto compare(
818 size_type pos1,
819 size_type count1,
820 StringView const& view,
821 size_type pos2,
822 size_type count2 = npos
823 ) const noexcept -> int
824 {
825 using view_type = basic_string_view<Char, Traits>;
826 view_type const sv = view;
827 return view_type(*this).substr(pos1, count1).compare(sv.substr(pos2, count2));
828 }
829
830 /// \brief Checks if the string begins with the given prefix.
831 [[nodiscard]] constexpr auto starts_with(basic_string_view<Char, Traits> sv) const noexcept -> bool
832 {
833 return basic_string_view<Char, Traits>(data(), size()).starts_with(sv);
834 }
835
836 /// \brief Checks if the string begins with the given prefix.
837 [[nodiscard]] constexpr auto starts_with(Char c) const noexcept -> bool
838 {
839 return basic_string_view<Char, Traits>(data(), size()).starts_with(c);
840 }
841
842 /// \brief Checks if the string begins with the given prefix.
843 [[nodiscard]] constexpr auto starts_with(const_pointer s) const -> bool
844 {
845 return basic_string_view<Char, Traits>(data(), size()).starts_with(s);
846 }
847
848 /// \brief Checks if the string ends with the given prefix.
849 [[nodiscard]] constexpr auto ends_with(basic_string_view<Char, Traits> sv) const noexcept -> bool
850 {
851 return basic_string_view<Char, Traits>(data(), size()).ends_with(sv);
852 }
853
854 /// \brief Checks if the string ends with the given prefix.
855 [[nodiscard]] constexpr auto ends_with(Char c) const noexcept -> bool
856 {
857 return basic_string_view<Char, Traits>(data(), size()).ends_with(c);
858 }
859
860 /// \brief Checks if the string ends with the given prefix.
861 [[nodiscard]] constexpr auto ends_with(const_pointer str) const -> bool
862 {
863 return basic_string_view<Char, Traits>(data(), size()).ends_with(str);
864 }
865
866 /// \brief Replaces the part of the string indicated [pos, pos + count) with
867 /// a new string.
868 constexpr auto replace(size_type pos, size_type count, basic_inplace_string const& str) -> basic_inplace_string&
869 {
870 TETL_PRECONDITION(pos < size());
871 TETL_PRECONDITION(pos + count < size());
872
873 auto* f = data() + pos;
874 auto* l = data() + pos + count;
875 detail::str_replace(f, l, str.begin(), str.end());
876 return *this;
877 }
878
879 /// \brief Replaces the part of the string indicated [first, last) with a
880 /// new string.
881 constexpr auto replace(const_iterator first, const_iterator last, basic_inplace_string const& str)
883 {
884 auto* f = to_mutable_iterator(first);
885 auto* l = to_mutable_iterator(last);
886 detail::str_replace(f, l, str.begin(), str.end());
887 return *this;
888 }
889
890 constexpr auto
891 replace(size_type pos, size_type count, basic_inplace_string const& str, size_type pos2, size_type count2 = npos)
893 {
894 TETL_PRECONDITION(pos < size());
895 TETL_PRECONDITION(pos2 < str.size());
896
897 auto* f = data() + etl::min(pos, size());
898 auto* l = data() + etl::min(pos + count, size());
899 auto const* sf = etl::next(str.begin(), static_cast<etl::ptrdiff_t>(etl::min(pos2, str.size())));
900 auto const* sl = etl::next(str.begin(), static_cast<etl::ptrdiff_t>(etl::min(pos2 + count2, str.size())));
901 detail::str_replace(f, l, sf, sl);
902 return *this;
903 }
904
905 constexpr auto replace(size_type pos, size_type count, Char const* str, size_type count2) -> basic_inplace_string&
906 {
907 TETL_PRECONDITION(pos < size());
908 TETL_PRECONDITION(pos + count < size());
909
910 auto* f = next(data(), min(pos, size()));
911 auto* l = next(data(), min(pos + count, size()));
912 detail::str_replace(f, l, str, next(str, count2));
913 return *this;
914 }
915
916 constexpr auto replace(const_iterator first, const_iterator last, Char const* str, size_type count2)
918 {
919 auto* f = to_mutable_iterator(first);
920 auto* l = to_mutable_iterator(last);
921 detail::str_replace(f, l, str, next(str, count2));
922 return *this;
923 }
924
925 constexpr auto replace(size_type pos, size_type count, Char const* str) -> basic_inplace_string&
926 {
927 TETL_PRECONDITION(pos < size());
928 TETL_PRECONDITION(pos + count < size());
929
930 auto* f = next(data(), min(pos, size()));
931 auto* l = next(data(), min(pos + count, size()));
932 detail::str_replace(f, l, str, next(str, strlen(str)));
933 return *this;
934 }
935
936 constexpr auto replace(const_iterator first, const_iterator last, Char const* str) -> basic_inplace_string&
937 {
938 auto* f = to_mutable_iterator(first);
939 auto* l = to_mutable_iterator(last);
940 detail::str_replace(f, l, str, next(str, strlen(str)));
941 return *this;
942 }
943
944 // constexpr auto replace(size_type pos, size_type count, size_type count2,
945 // Char ch) -> basic_inplace_string&
946 //{
947 // TETL_ASSERT(pos < size());
948 // TETL_ASSERT(pos + count < size());
949 //
950 // auto* f = next(data(), min(pos, size()));
951 // auto* l = next(data(), min(pos + count, size()));
952 // detail::str_replace(f, l, ch);
953 // return *this;
954 //}
955
956 constexpr auto replace(const_iterator first, const_iterator last, size_type count2, Char ch)
958 {
959 auto* f = to_mutable_iterator(first);
960 auto* l = etl::min(to_mutable_iterator(last), f + count2);
961 detail::str_replace(f, l, ch);
962 return *this;
963 }
964
965 /// \brief Returns a substring [pos, pos+count). If the requested substring
966 /// extends past the end of the string, or if count == npos, the returned
967 /// substring is [pos, size()).
968 ///
969 /// If pos is greater then size(), an empty string will be returned.
970 [[nodiscard]] constexpr auto substr(size_type pos = 0, size_type count = npos) const -> basic_inplace_string
971 {
972 if (pos > size()) {
973 return {};
974 }
975 return basic_inplace_string(data() + pos, etl::min(count, size() - pos));
976 }
977
978 /// \brief Copies a substring [pos, pos+count) to character string pointed
979 /// to by dest. If the requested substring lasts past the end of the string,
980 /// or if count == npos, the copied substring is [pos, size()). The
981 /// resulting character string is not null-terminated.
982 ///
983 /// If pos is greater then size(), nothing will be copied.
984 ///
985 /// \returns Number of characters copied.
986 constexpr auto copy(pointer destination, size_type count, size_type pos = 0) const -> size_type
987 {
988 if (pos > size()) {
989 return 0;
990 }
991 auto const* first = data() + pos;
992 auto const* last = first + etl::min(count, size() - pos);
993 auto const* dest = destination;
994 auto const* res = etl::copy(first, last, destination);
995 return static_cast<size_type>(res - dest);
996 }
997
998 /// \brief Resizes the string to contain count characters.
999 ///
1000 /// \details If the current size is less than count, additional characters
1001 /// are appended, maximum up to it's capacity. If the current size is
1002 /// greater than count, the string is reduced to its first count elements.
1003 constexpr auto resize(size_type count, Char ch) noexcept -> void
1004 {
1005 if (size() > count) {
1006 unsafe_set_size(count);
1007 }
1008 if (size() < count) {
1009 append(count, ch);
1010 }
1011 }
1012
1013 /// \brief Resizes the string to contain count characters.
1014 ///
1015 /// \details If the current size is less than count, additional characters
1016 /// are appended, maximum up to it's capacity. If the current size is
1017 /// greater than count, the string is reduced to its first count elements.
1018 constexpr auto resize(size_type count) noexcept -> void
1019 {
1020 resize(count, Char());
1021 }
1022
1023 /// \brief Exchanges the contents of the string with those of other. All
1024 /// iterators and references may be invalidated.
1025 constexpr auto swap(basic_inplace_string& other) noexcept -> void
1026 {
1027 auto const thisSize = size();
1028 auto const maxSize = static_cast<etl::ptrdiff_t>(etl::max(thisSize, other.size()));
1029
1030 etl::swap_ranges(begin(), etl::next(begin(), maxSize + 1), other.begin()); // includes null-terminator
1031 unsafe_set_size(other.size());
1032 other.unsafe_set_size(thisSize);
1033 }
1034
1035 /// \brief Finds the first substring equal to the given character sequence.
1036 /// Search begins at pos, i.e. the found substring must not begin in a
1037 /// position preceding pos.
1038 ///
1039 /// https://en.cppreference.com/w/cpp/string/basic_string/find
1040 ///
1041 /// \returns Position of the first character of the found substring or npos
1042 /// if no such substring is found.
1043 [[nodiscard]] constexpr auto find(basic_inplace_string const& str, size_type pos = 0) const noexcept -> size_type
1044 {
1045 return etl::strings::find<Char, Traits>(*this, str, pos);
1046 }
1047
1048 /// \brief Finds the first substring equal to the given character sequence.
1049 /// Search begins at pos, i.e. the found substring must not begin in a
1050 /// position preceding pos.
1051 ///
1052 /// https://en.cppreference.com/w/cpp/string/basic_string/find
1053 ///
1054 /// \returns Position of the first character of the found substring or npos
1055 /// if no such substring is found.
1056 [[nodiscard]] constexpr auto find(const_pointer s, size_type pos, size_type count) const noexcept -> size_type
1057 {
1058 return etl::strings::find<Char, Traits>(*this, basic_string_view<Char, Traits>{s, count}, pos);
1059 }
1060
1061 /// \brief Finds the first substring equal to the given character sequence.
1062 /// Search begins at pos, i.e. the found substring must not begin in a
1063 /// position preceding pos.
1064 ///
1065 /// https://en.cppreference.com/w/cpp/string/basic_string/find
1066 ///
1067 /// \returns Position of the first character of the found substring or npos
1068 /// if no such substring is found.
1069 [[nodiscard]] constexpr auto find(const_pointer s, size_type pos = 0) const noexcept -> size_type
1070 {
1071 return etl::strings::find<Char, Traits>(*this, s, pos);
1072 }
1073
1074 /// \brief Finds the first substring equal to the given character sequence.
1075 /// Search begins at pos, i.e. the found substring must not begin in a
1076 /// position preceding pos.
1077 ///
1078 /// https://en.cppreference.com/w/cpp/string/basic_string/find
1079 ///
1080 /// \returns Position of the first character of the found substring or npos
1081 /// if no such substring is found.
1082 [[nodiscard]] constexpr auto find(Char ch, size_type pos = 0) const noexcept -> size_type
1083 {
1084 return etl::strings::find<Char, Traits>(*this, basic_string_view<Char, Traits>{&ch, 1}, pos);
1085 }
1086
1087 /// \brief Finds the last substring equal to the given character sequence.
1088 /// Search begins at pos, i.e. the found substring must not begin in a
1089 /// position following pos. If npos or any value not smaller than size()-1
1090 /// is passed as pos, whole string will be searched.
1091 ///
1092 /// https://en.cppreference.com/w/cpp/string/basic_string/rfind
1093 ///
1094 /// \returns Position of the first character of the found substring or npos
1095 /// if no such substring is found. Note that this is an offset from the
1096 /// start of the string, not the end.
1097 [[nodiscard]] constexpr auto rfind(basic_inplace_string const& str, size_type pos = 0) const noexcept -> size_type
1098 {
1099 return etl::strings::rfind<Char, Traits>(*this, str, pos);
1100 }
1101
1102 /// \brief Finds the last substring equal to the given character sequence.
1103 /// Search begins at pos, i.e. the found substring must not begin in a
1104 /// position following pos. If npos or any value not smaller than size()-1
1105 /// is passed as pos, whole string will be searched.
1106 ///
1107 /// https://en.cppreference.com/w/cpp/string/basic_string/rfind
1108 ///
1109 /// \returns Position of the first character of the found substring or npos
1110 /// if no such substring is found. Note that this is an offset from the
1111 /// start of the string, not the end.
1112 ///
1113 /// \bug See tests.
1114 [[nodiscard]] constexpr auto rfind(const_pointer s, size_type pos, size_type count) const noexcept -> size_type
1115 {
1116 return etl::strings::rfind<Char, Traits>(*this, s, count, pos);
1117 }
1118
1119 /// \brief Finds the last substring equal to the given character sequence.
1120 /// Search begins at pos, i.e. the found substring must not begin in a
1121 /// position following pos. If npos or any value not smaller than size()-1
1122 /// is passed as pos, whole string will be searched.
1123 ///
1124 /// https://en.cppreference.com/w/cpp/string/basic_string/rfind
1125 ///
1126 /// \returns Position of the first character of the found substring or npos
1127 /// if no such substring is found. Note that this is an offset from the
1128 /// start of the string, not the end.
1129 [[nodiscard]] constexpr auto rfind(const_pointer s, size_type pos = 0) const noexcept -> size_type
1130 {
1131 return etl::strings::rfind<Char, Traits>(*this, s, pos);
1132 }
1133
1134 /// \brief Finds the last substring equal to the given character sequence.
1135 /// Search begins at pos, i.e. the found substring must not begin in a
1136 /// position following pos. If npos or any value not smaller than size()-1
1137 /// is passed as pos, whole string will be searched.
1138 ///
1139 /// https://en.cppreference.com/w/cpp/string/basic_string/rfind
1140 ///
1141 /// \returns Position of the first character of the found substring or npos
1142 /// if no such substring is found. Note that this is an offset from the
1143 /// start of the string, not the end.
1144 [[nodiscard]] constexpr auto rfind(Char ch, size_type pos = 0) const noexcept -> size_type
1145 {
1146 return etl::strings::rfind<Char, Traits>(*this, ch, pos);
1147 }
1148
1149 /// \brief Finds the first character equal to one of the characters in the
1150 /// given character sequence. The search considers only the interval [pos,
1151 /// size()). If the character is not present in the interval, npos will be
1152 /// returned.
1153 [[nodiscard]] constexpr auto find_first_of(basic_inplace_string const& str, size_type pos = 0) const noexcept
1154 -> size_type
1155 {
1156 return find_first_of(str.c_str(), pos, str.size());
1157 }
1158
1159 /// \brief Finds the first character equal to one of the characters in the
1160 /// given character sequence. The search considers only the interval [pos,
1161 /// size()). If the character is not present in the interval, npos will be
1162 /// returned.
1163 [[nodiscard]] constexpr auto find_first_of(const_pointer s, size_type pos, size_type count) const -> size_type
1164 {
1165 if (pos < size()) {
1166 return basic_string_view<Char, Traits>{*this}.find_first_of(s, pos, count);
1167 }
1168
1169 return npos;
1170 }
1171
1172 /// \brief Finds the first character equal to one of the characters in the
1173 /// given character sequence. The search considers only the interval [pos,
1174 /// size()). If the character is not present in the interval, npos will be
1175 /// returned.
1176 [[nodiscard]] constexpr auto find_first_of(const_pointer s, size_type pos = 0) const -> size_type
1177 {
1178 return find_first_of(s, pos, traits_type::length(s));
1179 }
1180
1181 /// \brief Finds the first character equal to one of the characters in the
1182 /// given character sequence. The search considers only the interval [pos,
1183 /// size()). If the character is not present in the interval, npos will be
1184 /// returned.
1185 [[nodiscard]] constexpr auto find_first_of(Char ch, size_type pos = 0) const noexcept -> size_type
1186 {
1187 return find_first_of(&ch, pos, 1);
1188 }
1189
1190 /// \brief Finds the first character equal to one of the characters in the
1191 /// given character sequence. The search considers only the interval [pos,
1192 /// size()). If the character is not present in the interval, npos will be
1193 /// returned.
1194 [[nodiscard]] constexpr auto
1195 find_first_of(basic_string_view<Char, traits_type> str, size_type pos = 0) const noexcept -> size_type
1196 {
1197 return find_first_of(str.data(), pos, str.size());
1198 }
1199
1200 /// \brief Finds the first character not equal to any of the characters in
1201 /// the given character sequence.
1202 ///
1203 /// \return Position of the first character not equal to any of the
1204 /// characters in the given string, or npos if no such character is found.
1205 [[nodiscard]] constexpr auto find_first_not_of(basic_inplace_string const& str, size_type pos = 0) const noexcept
1206 -> size_type
1207 {
1208 return basic_string_view<Char, Traits>{*this}.find_first_not_of(str, pos);
1209 }
1210
1211 /// \brief Finds the first character not equal to any of the characters in
1212 /// the given character sequence.
1213 ///
1214 /// \return Position of the first character not equal to any of the
1215 /// characters in the given string, or npos if no such character is found.
1216 [[nodiscard]] constexpr auto find_first_not_of(Char ch, size_type pos = 0) const noexcept -> size_type
1217 {
1218 return basic_string_view<Char, Traits>{*this}.find_first_not_of(ch, pos);
1219 }
1220
1221 /// \brief Finds the first character not equal to any of the characters in
1222 /// the given character sequence.
1223 ///
1224 /// \return Position of the first character not equal to any of the
1225 /// characters in the given string, or npos if no such character is found.
1226 [[nodiscard]] constexpr auto find_first_not_of(Char const* s, size_type pos) const -> size_type
1227 {
1228 return basic_string_view<Char, Traits>{*this}.find_first_not_of(s, pos);
1229 }
1230
1231 /// \brief Finds the first character not equal to any of the characters in
1232 /// the given character sequence.
1233 ///
1234 /// \return Position of the first character not equal to any of the
1235 /// characters in the given string, or npos if no such character is found.
1236 [[nodiscard]] constexpr auto find_first_not_of(Char const* s, size_type pos, size_type count) const -> size_type
1237 {
1238 return basic_string_view<Char, Traits>{*this}.find_first_not_of(s, pos, count);
1239 }
1240
1241 /// \brief Finds the last character equal to one of characters in the given
1242 /// character sequence. The exact search algorithm is not specified. The
1243 /// search considers only the interval [0, pos]. If the character is not
1244 /// present in the interval, npos will be returned.
1245 [[nodiscard]] constexpr auto find_last_of(basic_inplace_string const& str, size_type pos = 0) const noexcept
1246 -> size_type
1247 {
1248 return basic_string_view<Char, Traits>{*this}.find_last_of(str, pos);
1249 }
1250
1251 /// \brief Finds the last character equal to one of characters in the given
1252 /// character sequence. The exact search algorithm is not specified. The
1253 /// search considers only the interval [0, pos]. If the character is not
1254 /// present in the interval, npos will be returned.
1255 [[nodiscard]] constexpr auto find_last_of(Char c, size_type pos = 0) const noexcept -> size_type
1256 {
1257 return basic_string_view<Char, Traits>{*this}.find_last_of(c, pos);
1258 }
1259
1260 /// \brief Finds the last character equal to one of characters in the given
1261 /// character sequence. The exact search algorithm is not specified. The
1262 /// search considers only the interval [0, pos]. If the character is not
1263 /// present in the interval, npos will be returned.
1264 [[nodiscard]] constexpr auto find_last_of(Char const* s, size_type pos, size_type count) const -> size_type
1265 {
1266 return basic_string_view<Char, Traits>{*this}.find_last_of(s, pos, count);
1267 }
1268
1269 /// \brief Finds the last character equal to one of characters in the given
1270 /// character sequence. The exact search algorithm is not specified. The
1271 /// search considers only the interval [0, pos]. If the character is not
1272 /// present in the interval, npos will be returned.
1273 [[nodiscard]] constexpr auto find_last_of(Char const* s, size_type pos = 0) const -> size_type
1274 {
1275 return basic_string_view<Char, Traits>{*this}.find_last_of(s, pos);
1276 }
1277
1278 /// \brief Finds the last character equal to none of the characters in the
1279 /// given character sequence. The search considers only the interval [0,
1280 /// pos]. If the character is not present in the interval, npos will be
1281 /// returned.
1282 [[nodiscard]] constexpr auto find_last_not_of(basic_inplace_string const& str, size_type pos = 0) const noexcept
1283 -> size_type
1284 {
1285 return basic_string_view<Char, Traits>{*this}.find_last_not_of(str, pos);
1286 }
1287
1288 /// \brief Finds the last character equal to none of the characters in the
1289 /// given character sequence. The search considers only the interval [0,
1290 /// pos]. If the character is not present in the interval, npos will be
1291 /// returned.
1292 [[nodiscard]] constexpr auto find_last_not_of(Char c, size_type pos = 0) const noexcept -> size_type
1293 {
1294 return basic_string_view<Char, Traits>{*this}.find_last_not_of(c, pos);
1295 }
1296
1297 /// \brief Finds the last character equal to none of the characters in the
1298 /// given character sequence. The search considers only the interval [0,
1299 /// pos]. If the character is not present in the interval, npos will be
1300 /// returned.
1301 [[nodiscard]] constexpr auto find_last_not_of(Char const* s, size_type pos, size_type count) const -> size_type
1302 {
1303 return basic_string_view<Char, Traits>{*this}.find_last_not_of(s, pos, count);
1304 }
1305
1306 /// \brief Finds the last character equal to none of the characters in the
1307 /// given character sequence. The search considers only the interval [0,
1308 /// pos]. If the character is not present in the interval, npos will be
1309 /// returned.
1310 [[nodiscard]] constexpr auto find_last_not_of(Char const* s, size_type pos = 0) const -> size_type
1311 {
1312 return basic_string_view<Char, Traits>{*this}.find_last_not_of(s, pos);
1313 }
1314
1315 /// \brief Checks if the string contains the given substring.
1316 [[nodiscard]] constexpr auto contains(etl::basic_string_view<Char, Traits> sv) const noexcept -> bool
1317 {
1318 return basic_string_view<Char, Traits>{*this}.contains(sv);
1319 }
1320
1321 /// \brief Checks if the string contains the given substring.
1322 [[nodiscard]] constexpr auto contains(Char c) const noexcept -> bool
1323 {
1324 return basic_string_view<Char, Traits>{*this}.contains(c);
1325 }
1326
1327 /// \brief Checks if the string contains the given substring.
1328 [[nodiscard]] constexpr auto contains(Char const* s) const -> bool
1329 {
1330 return basic_string_view<Char, Traits>{*this}.contains(s);
1331 }
1332
1333 /// \brief This is a special value equal to the maximum value representable
1334 /// by the type size_type. The exact meaning depends on context, but it is
1335 /// generally used either as end of string indicator by the functions that
1336 /// expect a string index or as the error indicator by the functions that
1337 /// return a string index.
1338 static constexpr size_type npos = numeric_limits<size_type>::max();
1339
1340private:
1341 [[nodiscard]] constexpr auto to_mutable_iterator(const_iterator it) -> iterator
1342 {
1343 auto const dist = etl::distance(cbegin(), it);
1344 return etl::next(begin(), static_cast<etl::ptrdiff_t>(dist));
1345 }
1346
1347 [[nodiscard]] constexpr auto unsafe_at(size_type index) noexcept -> reference
1348 {
1349 TETL_PRECONDITION(index < size() + 1);
1350 return *etl::next(_storage.data(), static_cast<etl::ptrdiff_t>(index));
1351 }
1352
1353 [[nodiscard]] constexpr auto unsafe_at(size_type index) const noexcept -> const_reference
1354 {
1355 TETL_PRECONDITION(index < size() + 1);
1356 return *etl::next(_storage.data(), static_cast<etl::ptrdiff_t>(index));
1357 }
1358
1359 constexpr auto unsafe_set_size(size_type const newSize) noexcept -> void
1360 {
1361 TETL_PRECONDITION(newSize <= Capacity);
1362 _storage.set_size(newSize);
1363 unsafe_at(newSize) = Char(0);
1364 }
1365
1366 constexpr auto insert_impl(iterator pos, const_pointer text, size_type count) -> void
1367 {
1368 // Insert text at end.
1369 auto* currentEnd = end();
1370 append(text, count);
1371
1372 // Rotate to correct position
1373 etl::rotate(pos, currentEnd, end());
1374 }
1375
1376 struct tiny_layout {
1377 constexpr tiny_layout() noexcept
1378 {
1379 _buffer[Capacity] = Capacity;
1380 }
1381
1382 [[nodiscard]] constexpr auto data() noexcept
1383 {
1384 return _buffer.data();
1385 }
1386
1387 [[nodiscard]] constexpr auto data() const noexcept
1388 {
1389 return _buffer.data();
1390 }
1391
1392 [[nodiscard]] constexpr auto get_size() const noexcept
1393 {
1394 return Capacity - size_type(_buffer[Capacity]);
1395 }
1396
1397 constexpr auto set_size(size_t size) noexcept
1398 {
1399 return _buffer[Capacity] = Char(Capacity - size);
1400 }
1401
1402 private:
1403 etl::array<Char, Capacity + 1> _buffer{};
1404 };
1405
1406 struct normal_layout {
1407 constexpr normal_layout() noexcept = default;
1408
1409 [[nodiscard]] constexpr auto data() noexcept
1410 {
1411 return _buffer.data();
1412 }
1413
1414 [[nodiscard]] constexpr auto data() const noexcept
1415 {
1416 return _buffer.data();
1417 }
1418
1419 [[nodiscard]] constexpr auto get_size() const noexcept
1420 {
1421 return size_t(_size);
1422 }
1423
1424 constexpr auto set_size(size_t size) noexcept
1425 {
1426 return _size = internal_size_t(size);
1427 }
1428
1429 private:
1430 internal_size_t _size{};
1431 etl::array<Char, Capacity + 1> _buffer{};
1432 };
1433
1434 using layout_type = etl::conditional_t<(Capacity < 16), tiny_layout, normal_layout>;
1435 layout_type _storage{};
1436};
1437
1438/// Typedef for a basic_inplace_string using 'char'
1439template <etl::size_t Capacity>
1440using inplace_string = basic_inplace_string<char, Capacity>;
1441
1442/// Typedef for a basic_inplace_string using 'wchar_t'
1443template <etl::size_t Capacity>
1444using inplace_wstring = basic_inplace_string<wchar_t, Capacity>;
1445
1446/// Typedef for a basic_inplace_string using 'char8_t'
1447template <etl::size_t Capacity>
1448using inplace_u8string = basic_inplace_string<char8_t, Capacity>;
1449
1450/// Typedef for a basic_inplace_string using 'char16_t'
1451template <etl::size_t Capacity>
1452using inplace_u16string = basic_inplace_string<char16_t, Capacity>;
1453
1454/// Typedef for a basic_inplace_string using 'char32_t'
1455template <etl::size_t Capacity>
1456using inplace_u32string = basic_inplace_string<char32_t, Capacity>;
1457
1458/// \brief Returns a string containing characters from lhs followed by the
1459/// characters from rhs.
1460template <typename Char, typename Traits, size_t Capacity1, size_t Capacity2>
1461[[nodiscard]] constexpr auto operator+(
1462 basic_inplace_string<Char, Capacity1, Traits> const& lhs,
1463 basic_inplace_string<Char, Capacity2, Traits> const& rhs
1464) noexcept -> basic_inplace_string<Char, Capacity1, Traits>
1465{
1466 auto str = basic_inplace_string<Char, Capacity1, Traits>{lhs};
1467 str.append(rhs);
1468 return str;
1469}
1470
1471/// \brief Returns a string containing characters from lhs followed by the
1472/// characters from rhs.
1473template <typename Char, typename Traits, size_t Capacity>
1474[[nodiscard]] constexpr auto
1475operator+(basic_inplace_string<Char, Capacity, Traits> const& lhs, Char const* rhs) noexcept
1476 -> basic_inplace_string<Char, Capacity, Traits>
1477{
1478 auto str = basic_inplace_string<Char, Capacity, Traits>{lhs};
1479 str.append(rhs);
1480 return str;
1481}
1482
1483/// \brief Returns a string containing characters from lhs followed by the
1484/// characters from rhs.
1485template <typename Char, typename Traits, size_t Capacity>
1486[[nodiscard]] constexpr auto operator+(basic_inplace_string<Char, Capacity, Traits> const& lhs, Char rhs) noexcept
1487 -> basic_inplace_string<Char, Capacity, Traits>
1488{
1489 auto str = basic_inplace_string<Char, Capacity, Traits>{lhs};
1490 str.append(1, rhs);
1491 return str;
1492}
1493
1494/// \brief Returns a string containing characters from lhs followed by the
1495/// characters from rhs.
1496template <typename Char, typename Traits, size_t Capacity>
1497[[nodiscard]] constexpr auto
1498operator+(Char const* lhs, basic_inplace_string<Char, Capacity, Traits> const& rhs) noexcept
1499 -> basic_inplace_string<Char, Capacity, Traits>
1500{
1501 auto str = basic_inplace_string<Char, Capacity, Traits>{lhs};
1502 str.append(rhs);
1503 return str;
1504}
1505
1506/// \brief Returns a string containing characters from lhs followed by the
1507/// characters from rhs.
1508template <typename Char, typename Traits, size_t Capacity>
1509[[nodiscard]] constexpr auto operator+(Char lhs, basic_inplace_string<Char, Capacity, Traits> const& rhs) noexcept
1510 -> basic_inplace_string<Char, Capacity, Traits>
1511{
1512 auto str = basic_inplace_string<Char, Capacity, Traits>{1, lhs};
1513 str.append(rhs);
1514 return str;
1515}
1516
1517/// \brief Compares the contents of a string with another string or a
1518/// null-terminated array of Char.
1519///
1520/// \details Two strings are equal if both the size of lhs and rhs are equal and
1521/// each character in lhs has equivalent character in rhs at the same position.
1522template <typename Char, typename Traits, etl::size_t Capacity1, etl::size_t Capacity2>
1523[[nodiscard]] constexpr auto operator==(
1524 etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs,
1525 etl::basic_inplace_string<Char, Capacity2, Traits> const& rhs
1526) noexcept -> bool
1527{
1528 return lhs.compare(rhs) == 0;
1529}
1530
1531/// \brief Compares the contents of a string with another string or a
1532/// null-terminated array of Char.
1533///
1534/// \details Two strings are equal if both the size of lhs and rhs are equal and
1535/// each character in lhs has equivalent character in rhs at the same position.
1536template <typename Char, typename Traits, etl::size_t Capacity>
1537[[nodiscard]] constexpr auto
1538operator==(etl::basic_inplace_string<Char, Capacity, Traits> const& lhs, Char const* rhs) noexcept -> bool
1539{
1540 return lhs.compare(rhs) == 0;
1541}
1542
1543/// \brief Compares the contents of a string with another string or a
1544/// null-terminated array of Char.
1545///
1546/// \details Two strings are equal if both the size of lhs and rhs are equal and
1547/// each character in lhs has equivalent character in rhs at the same position.
1548template <typename Char, typename Traits, etl::size_t Capacity>
1549[[nodiscard]] constexpr auto
1550operator==(Char const* lhs, etl::basic_inplace_string<Char, Capacity, Traits> const& rhs) noexcept -> bool
1551{
1552 return rhs.compare(lhs) == 0;
1553}
1554
1555/// \brief Compares the contents of a string with another string or a
1556/// null-terminated array of Char.
1557///
1558/// \details Two strings are equal if both the size of lhs and rhs are equal and
1559/// each character in lhs has equivalent character in rhs at the same position.
1560template <typename Char, typename Traits, etl::size_t Capacity1, etl::size_t Capacity2>
1561[[nodiscard]] constexpr auto operator!=(
1562 etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs,
1563 etl::basic_inplace_string<Char, Capacity2, Traits> const& rhs
1564) noexcept -> bool
1565{
1566 return lhs.compare(rhs) != 0;
1567}
1568
1569/// \brief Compares the contents of a string with another string or a
1570/// null-terminated array of Char.
1571///
1572/// \details Two strings are equal if both the size of lhs and rhs are equal and
1573/// each character in lhs has equivalent character in rhs at the same position.
1574template <typename Char, typename Traits, etl::size_t Capacity1>
1575[[nodiscard]] constexpr auto
1576operator!=(etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs, Char const* rhs) noexcept -> bool
1577{
1578 return lhs.compare(rhs) != 0;
1579}
1580
1581/// \brief Compares the contents of a string with another string or a
1582/// null-terminated array of Char.
1583///
1584/// \details Two strings are equal if both the size of lhs and rhs are equal and
1585/// each character in lhs has equivalent character in rhs at the same position.
1586template <typename Char, typename Traits, etl::size_t Capacity>
1587[[nodiscard]] constexpr auto
1588operator!=(Char const* lhs, etl::basic_inplace_string<Char, Capacity, Traits> const& rhs) noexcept -> bool
1589{
1590 return rhs.compare(lhs) != 0;
1591}
1592
1593/// \brief Compares the contents of a string with another string or a
1594/// null-terminated array of Char.
1595///
1596/// \details The ordering comparisons are done lexicographically.
1597template <typename Char, typename Traits, etl::size_t Capacity1, etl::size_t Capacity2>
1598[[nodiscard]] constexpr auto operator<(
1599 etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs,
1600 etl::basic_inplace_string<Char, Capacity2, Traits> const& rhs
1601) noexcept
1602{
1603 return lhs.compare(rhs) < 0;
1604}
1605
1606/// \brief Compares the contents of a string with another string or a
1607/// null-terminated array of Char.
1608///
1609/// \details The ordering comparisons are done lexicographically.
1610template <typename Char, typename Traits, etl::size_t Capacity1>
1611[[nodiscard]] constexpr auto
1612operator<(etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs, Char const* rhs) noexcept -> bool
1613{
1614 return lhs.compare(rhs) < 0;
1615}
1616
1617/// \brief Compares the contents of a string with another string or a
1618/// null-terminated array of Char.
1619///
1620/// \details The ordering comparisons are done lexicographically.
1621template <typename Char, typename Traits, etl::size_t Capacity1>
1622[[nodiscard]] constexpr auto
1623operator<(Char const* lhs, etl::basic_inplace_string<Char, Capacity1, Traits> const& rhs) noexcept -> bool
1624{
1625 return rhs.compare(lhs) > 0;
1626}
1627
1628/// \brief Compares the contents of a string with another string or a
1629/// null-terminated array of Char.
1630///
1631/// \details The ordering comparisons are done lexicographically.
1632template <typename Char, typename Traits, etl::size_t Capacity1, etl::size_t Capacity2>
1633[[nodiscard]] constexpr auto operator<=(
1634 etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs,
1635 etl::basic_inplace_string<Char, Capacity2, Traits> const& rhs
1636) noexcept
1637{
1638 return lhs.compare(rhs) <= 0;
1639}
1640
1641/// \brief Compares the contents of a string with another string or a
1642/// null-terminated array of Char.
1643///
1644/// \details The ordering comparisons are done lexicographically.
1645template <typename Char, typename Traits, etl::size_t Capacity1>
1646[[nodiscard]] constexpr auto
1647operator<=(etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs, Char const* rhs) noexcept -> bool
1648{
1649 return lhs.compare(rhs) <= 0;
1650}
1651
1652/// \brief Compares the contents of a string with another string or a
1653/// null-terminated array of Char.
1654///
1655/// \details The ordering comparisons are done lexicographically.
1656template <typename Char, typename Traits, etl::size_t Capacity1>
1657[[nodiscard]] constexpr auto
1658operator<=(Char const* lhs, etl::basic_inplace_string<Char, Capacity1, Traits> const& rhs) noexcept -> bool
1659{
1660 return rhs.compare(lhs) >= 0;
1661}
1662
1663/// \brief Compares the contents of a string with another string or a
1664/// null-terminated array of Char.
1665///
1666/// \details The ordering comparisons are done lexicographically.
1667template <typename Char, typename Traits, etl::size_t Capacity1, etl::size_t Capacity2>
1668[[nodiscard]] constexpr auto operator>(
1669 etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs,
1670 etl::basic_inplace_string<Char, Capacity2, Traits> const& rhs
1671) noexcept
1672{
1673 return lhs.compare(rhs) > 0;
1674}
1675
1676/// \brief Compares the contents of a string with another string or a
1677/// null-terminated array of Char.
1678///
1679/// \details The ordering comparisons are done lexicographically.
1680template <typename Char, typename Traits, etl::size_t Capacity1>
1681[[nodiscard]] constexpr auto
1682operator>(etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs, Char const* rhs) noexcept -> bool
1683{
1684 return lhs.compare(rhs) > 0;
1685}
1686
1687/// \brief Compares the contents of a string with another string or a
1688/// null-terminated array of Char.
1689///
1690/// \details The ordering comparisons are done lexicographically.
1691template <typename Char, typename Traits, etl::size_t Capacity1>
1692[[nodiscard]] constexpr auto
1693operator>(Char const* lhs, etl::basic_inplace_string<Char, Capacity1, Traits> const& rhs) noexcept -> bool
1694{
1695 return rhs.compare(lhs) < 0;
1696}
1697
1698/// \brief Compares the contents of a string with another string or a
1699/// null-terminated array of Char.
1700///
1701/// \details The ordering comparisons are done lexicographically.
1702template <typename Char, typename Traits, etl::size_t Capacity1, etl::size_t Capacity2>
1703[[nodiscard]] constexpr auto operator>=(
1704 etl::basic_inplace_string<Char, Capacity1, Traits> const& lhs,
1705 etl::basic_inplace_string<Char, Capacity2, Traits> const& rhs
1706) noexcept
1707{
1708 return lhs.compare(rhs) >= 0;
1709}
1710
1711/// \brief Compares the contents of a string with another string or a
1712/// null-terminated array of Char.
1713///
1714/// \details The ordering comparisons are done lexicographically.
1715template <typename Char, typename Traits, etl::size_t Capacity>
1716[[nodiscard]] constexpr auto
1717operator>=(etl::basic_inplace_string<Char, Capacity, Traits> const& lhs, Char const* rhs) noexcept -> bool
1718{
1719 return lhs.compare(rhs) >= 0;
1720}
1721
1722/// \brief Compares the contents of a string with another string or a
1723/// null-terminated array of Char.
1724///
1725/// \details The ordering comparisons are done lexicographically.
1726template <typename Char, typename Traits, etl::size_t Capacity>
1727[[nodiscard]] constexpr auto
1728operator>=(Char const* lhs, etl::basic_inplace_string<Char, Capacity, Traits> const& rhs) noexcept -> bool
1729{
1730 return rhs.compare(lhs) <= 0;
1731}
1732
1733/// \brief Specializes the etl::swap algorithm for etl::basic_inplace_string.
1734/// Swaps the contents of lhs and rhs. Equivalent to lhs.swap(rhs).
1735template <typename Char, typename Traits, etl::size_t Capacity>
1736constexpr auto swap(
1737 etl::basic_inplace_string<Char, Capacity, Traits>& lhs,
1738 etl::basic_inplace_string<Char, Capacity, Traits>& rhs
1739) noexcept(noexcept(lhs.swap(rhs))) -> void
1740{
1741 lhs.swap(rhs);
1742}
1743
1744/// \brief Erases all elements that compare equal to value from the container.
1745template <typename Char, typename Traits, etl::size_t Capacity, typename U>
1746constexpr auto erase(basic_inplace_string<Char, Capacity, Traits>& c, U const& value) noexcept ->
1747 typename basic_inplace_string<Char, Capacity, Traits>::size_type
1748{
1749 using return_type = typename basic_inplace_string<Char, Capacity, Traits>::size_type;
1750
1751 auto it = etl::remove(begin(c), end(c), value);
1752 auto r = etl::distance(it, end(c));
1753 c.erase(it, end(c));
1754 return static_cast<return_type>(r);
1755}
1756
1757/// \brief Erases all elements that satisfy the predicate pred from the
1758/// container.
1759template <typename Char, typename Traits, etl::size_t Capacity, typename Predicate>
1760constexpr auto erase_if(basic_inplace_string<Char, Capacity, Traits>& c, Predicate pred) noexcept ->
1761 typename basic_inplace_string<Char, Capacity, Traits>::size_type
1762{
1763 using return_type = typename basic_inplace_string<Char, Capacity, Traits>::size_type;
1764
1765 auto it = etl::remove_if(begin(c), end(c), pred);
1766 auto r = etl::distance(it, end(c));
1767 c.erase(it, end(c));
1768 return static_cast<return_type>(r);
1769}
1770
1771} // namespace etl
1772
1773#endif // TETL_STRING_BASIC_INPLACE_STRING_HPP
Definition find.hpp:9
Definition adjacent_find.hpp:9
constexpr auto operator+(Char const *lhs, basic_inplace_string< Char, Capacity, Traits > const &rhs) noexcept -> basic_inplace_string< Char, Capacity, Traits >
Returns a string containing characters from lhs followed by the characters from rhs.
Definition basic_inplace_string.hpp:1498
constexpr auto operator!=(Char const *lhs, etl::basic_inplace_string< Char, Capacity, Traits > const &rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1588
constexpr auto operator>(Char const *lhs, etl::basic_inplace_string< Char, Capacity1, Traits > const &rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1693
constexpr auto operator>=(etl::basic_inplace_string< Char, Capacity, Traits > const &lhs, Char const *rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1717
constexpr auto operator+(Char lhs, basic_inplace_string< Char, Capacity, Traits > const &rhs) noexcept -> basic_inplace_string< Char, Capacity, Traits >
Returns a string containing characters from lhs followed by the characters from rhs.
Definition basic_inplace_string.hpp:1509
constexpr auto operator==(etl::basic_inplace_string< Char, Capacity, Traits > const &lhs, Char const *rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1538
constexpr auto operator<=(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, etl::basic_inplace_string< Char, Capacity2, Traits > const &rhs) noexcept
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1633
constexpr auto operator<=(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, Char const *rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1647
constexpr auto operator>(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, Char const *rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1682
constexpr auto operator+(basic_inplace_string< Char, Capacity, Traits > const &lhs, Char const *rhs) noexcept -> basic_inplace_string< Char, Capacity, Traits >
Returns a string containing characters from lhs followed by the characters from rhs.
Definition basic_inplace_string.hpp:1475
constexpr auto operator+(basic_inplace_string< Char, Capacity, Traits > const &lhs, Char rhs) noexcept -> basic_inplace_string< Char, Capacity, Traits >
Returns a string containing characters from lhs followed by the characters from rhs.
Definition basic_inplace_string.hpp:1486
constexpr auto operator==(Char const *lhs, etl::basic_inplace_string< Char, Capacity, Traits > const &rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1550
constexpr auto operator>(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, etl::basic_inplace_string< Char, Capacity2, Traits > const &rhs) noexcept
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1668
constexpr auto operator!=(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, Char const *rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1576
constexpr auto swap(etl::basic_inplace_string< Char, Capacity, Traits > &lhs, etl::basic_inplace_string< Char, Capacity, Traits > &rhs) noexcept(noexcept(lhs.swap(rhs))) -> void
Specializes the etl::swap algorithm for etl::basic_inplace_string. Swaps the contents of lhs and rhs....
Definition basic_inplace_string.hpp:1736
constexpr auto operator>=(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, etl::basic_inplace_string< Char, Capacity2, Traits > const &rhs) noexcept
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1703
constexpr auto erase(basic_inplace_string< Char, Capacity, Traits > &c, U const &value) noexcept -> typename basic_inplace_string< Char, Capacity, Traits >::size_type
Erases all elements that compare equal to value from the container.
Definition basic_inplace_string.hpp:1746
constexpr auto operator<(Char const *lhs, etl::basic_inplace_string< Char, Capacity1, Traits > const &rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1623
constexpr auto operator+(basic_inplace_string< Char, Capacity1, Traits > const &lhs, basic_inplace_string< Char, Capacity2, Traits > const &rhs) noexcept -> basic_inplace_string< Char, Capacity1, Traits >
Returns a string containing characters from lhs followed by the characters from rhs.
Definition basic_inplace_string.hpp:1461
constexpr auto operator<=(Char const *lhs, etl::basic_inplace_string< Char, Capacity1, Traits > const &rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1658
constexpr auto operator==(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, etl::basic_inplace_string< Char, Capacity2, Traits > const &rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1523
constexpr auto erase_if(basic_inplace_string< Char, Capacity, Traits > &c, Predicate pred) noexcept -> typename basic_inplace_string< Char, Capacity, Traits >::size_type
Erases all elements that satisfy the predicate pred from the container.
Definition basic_inplace_string.hpp:1760
constexpr auto operator!=(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, etl::basic_inplace_string< Char, Capacity2, Traits > const &rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1561
constexpr auto operator>=(Char const *lhs, etl::basic_inplace_string< Char, Capacity, Traits > const &rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1728
constexpr auto operator<(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, etl::basic_inplace_string< Char, Capacity2, Traits > const &rhs) noexcept
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1598
constexpr auto operator<(etl::basic_inplace_string< Char, Capacity1, Traits > const &lhs, Char const *rhs) noexcept -> bool
Compares the contents of a string with another string or a null-terminated array of Char.
Definition basic_inplace_string.hpp:1612
A container that encapsulates fixed size arrays.
Definition array.hpp:49
basic_inplace_string class with fixed size capacity.
Definition basic_inplace_string.hpp:42
constexpr auto operator[](size_type index) const noexcept -> const_reference
Accesses the specified character without bounds checking.
Definition basic_inplace_string.hpp:258
constexpr auto rfind(basic_inplace_string const &str, size_type pos=0) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Search begins at pos,...
Definition basic_inplace_string.hpp:1097
constexpr basic_inplace_string(const_pointer str, size_type const len) noexcept
Character pointer constructor.
Definition basic_inplace_string.hpp:69
constexpr auto operator=(const_pointer s) noexcept -> basic_inplace_string &
Replaces the contents with those of null-terminated character string pointed to by s.
Definition basic_inplace_string.hpp:149
constexpr auto operator[](size_type index) noexcept -> reference
Accesses the specified character without bounds checking.
Definition basic_inplace_string.hpp:252
constexpr auto assign(size_type count, Char ch) noexcept -> basic_inplace_string &
Replaces the contents with count copies of character ch.
Definition basic_inplace_string.hpp:177
constexpr auto find_first_not_of(basic_inplace_string const &str, 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_inplace_string.hpp:1205
constexpr auto erase(const_iterator position) noexcept -> iterator
Removes the character at position.
Definition basic_inplace_string.hpp:474
constexpr auto insert(size_type const pos, StringView const &view) noexcept -> basic_inplace_string &
Implicitly converts view to a string view sv, then inserts the elements from sv before the element (i...
Definition basic_inplace_string.hpp:688
constexpr auto find_last_not_of(Char c, size_type pos=0) const noexcept -> size_type
Finds the last character equal to none of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1292
constexpr basic_inplace_string(size_type count, Char ch) noexcept
Constructs the string with count copies of character ch.
Definition basic_inplace_string.hpp:87
constexpr auto c_str() const noexcept -> const_pointer
Returns a pointer to a null-terminated character array.
Definition basic_inplace_string.hpp:441
constexpr auto operator+=(basic_inplace_string const &str) noexcept -> basic_inplace_string &
Appends string str.
Definition basic_inplace_string.hpp:582
constexpr auto operator=(Char ch) noexcept -> basic_inplace_string &
Replaces the contents with character ch.
Definition basic_inplace_string.hpp:160
constexpr auto rfind(const_pointer s, size_type pos, size_type count) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Search begins at pos,...
Definition basic_inplace_string.hpp:1114
static constexpr size_type npos
This is a special value equal to the maximum value representable by the type size_type....
Definition basic_inplace_string.hpp:1338
constexpr auto find_first_of(const_pointer s, size_type pos=0) const -> size_type
Finds the first character equal to one of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1176
constexpr auto find_first_not_of(Char ch, 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_inplace_string.hpp:1216
constexpr auto front() const noexcept -> const_reference
Accesses the first character.
Definition basic_inplace_string.hpp:349
constexpr auto find_last_of(Char c, size_type pos=0) const noexcept -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_inplace_string.hpp:1255
constexpr basic_inplace_string(basic_inplace_string const &) noexcept=default
Defaulted copy constructor.
constexpr auto insert(size_type const index, StringView const &view, size_type const indexStr, size_type const count=npos) noexcept -> basic_inplace_string &
Implicitly converts view to a string view sv, then inserts, before the element (if any) pointed by po...
Definition basic_inplace_string.hpp:700
constexpr auto operator=(StringView const &view) noexcept -> basic_inplace_string &
Implicitly converts view to a string view sv, then replaces the contents with those of the sv.
Definition basic_inplace_string.hpp:170
constexpr auto replace(const_iterator first, const_iterator last, basic_inplace_string const &str) -> basic_inplace_string &
Replaces the part of the string indicated [first, last) with a new string.
Definition basic_inplace_string.hpp:881
constexpr auto crbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first character of the reversed string. It corresponds to the last ...
Definition basic_inplace_string.hpp:315
constexpr auto find_last_of(basic_inplace_string const &str, size_type pos=0) const noexcept -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_inplace_string.hpp:1245
constexpr auto replace(const_iterator first, const_iterator last, size_type count2, Char ch) -> basic_inplace_string &
Definition basic_inplace_string.hpp:956
constexpr auto starts_with(basic_string_view< Char, Traits > sv) const noexcept -> bool
Checks if the string begins with the given prefix.
Definition basic_inplace_string.hpp:831
constexpr auto compare(size_type const pos, size_type const count, const_pointer s) const -> int
Compares a [pos1, pos1+count1) substring of this string to the null-terminated character sequence beg...
Definition basic_inplace_string.hpp:771
constexpr auto find_last_not_of(basic_inplace_string const &str, size_type pos=0) const noexcept -> size_type
Finds the last character equal to none of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1282
constexpr auto rfind(const_pointer s, size_type pos=0) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Search begins at pos,...
Definition basic_inplace_string.hpp:1129
constexpr auto insert(size_type const index, const_pointer s) noexcept -> basic_inplace_string &
Inserts null-terminated character string pointed to by s at the position index.
Definition basic_inplace_string.hpp:619
constexpr auto rbegin() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first character of the reversed string. It corresponds to the last ...
Definition basic_inplace_string.hpp:308
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_inplace_string.hpp:1264
constexpr auto find(Char ch, size_type pos=0) const noexcept -> size_type
Finds the first substring equal to the given character sequence. Search begins at pos,...
Definition basic_inplace_string.hpp:1082
constexpr auto replace(size_type pos, size_type count, basic_inplace_string const &str) -> basic_inplace_string &
Replaces the part of the string indicated [pos, pos + count) with a new string.
Definition basic_inplace_string.hpp:868
static constexpr auto reserve(size_type) -> void
Reserve is a nop, since the capacity is fixed.
Definition basic_inplace_string.hpp:408
constexpr auto resize(size_type count) noexcept -> void
Resizes the string to contain count characters.
Definition basic_inplace_string.hpp:1018
constexpr auto compare(size_type const pos, size_type const count, basic_inplace_string const &str) const -> int
Compares a [pos, pos+count) substring of this string to str. If count > size() - pos the substring is...
Definition basic_inplace_string.hpp:731
constexpr auto operator+=(StringView const &view) noexcept -> basic_inplace_string &
Implicitly converts view to a string view sv, then appends characters in the string view sv.
Definition basic_inplace_string.hpp:603
constexpr auto append(basic_inplace_string const &str, size_type pos, size_type count=npos) noexcept -> basic_inplace_string &
Appends a substring [ pos, pos + count ) of str.
Definition basic_inplace_string.hpp:555
constexpr auto operator=(basic_inplace_string &&) noexcept -> basic_inplace_string &=default
Defaulted move assignment.
constexpr auto substr(size_type pos=0, size_type count=npos) const -> basic_inplace_string
Returns a substring [pos, pos+count). If the requested substring extends past the end of the string,...
Definition basic_inplace_string.hpp:970
constexpr auto find_first_of(const_pointer s, size_type pos, size_type count) const -> size_type
Finds the first character equal to one of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1163
constexpr auto assign(InputIt first, InputIt last) noexcept -> basic_inplace_string &
Replaces the contents with copies of the characters in the range [ first , last ).
Definition basic_inplace_string.hpp:221
constexpr basic_inplace_string(const_pointer str) noexcept
Character pointer constructor. Calls traits_type::length.
Definition basic_inplace_string.hpp:78
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_inplace_string.hpp:1236
constexpr auto assign(basic_inplace_string const &str) noexcept -> basic_inplace_string &
Replaces the contents with a copy of str.
Definition basic_inplace_string.hpp:185
constexpr auto assign(StringView const &view) noexcept -> basic_inplace_string &
Implicitly converts view to a string view sv, then replaces the contents with the characters from sv.
Definition basic_inplace_string.hpp:231
constexpr auto back() noexcept -> reference
Accesses the last character.
Definition basic_inplace_string.hpp:356
constexpr auto append(InputIt first, InputIt last) noexcept -> basic_inplace_string &
Appends characters in the range [ first , last ).
Definition basic_inplace_string.hpp:540
constexpr auto ends_with(Char c) const noexcept -> bool
Checks if the string ends with the given prefix.
Definition basic_inplace_string.hpp:855
constexpr auto assign(StringView const &view, size_type pos, size_type count=npos) noexcept -> basic_inplace_string &
Implicitly converts view to a string view sv, then replaces the contents with the characters from the...
Definition basic_inplace_string.hpp:243
constexpr auto operator+=(const_pointer s) noexcept -> basic_inplace_string &
Appends the null-terminated character string pointed to by s.
Definition basic_inplace_string.hpp:594
constexpr auto find_last_of(Char const *s, size_type pos=0) const -> size_type
Finds the last character equal to one of characters in the given character sequence....
Definition basic_inplace_string.hpp:1273
constexpr auto find_last_not_of(Char const *s, size_type pos, size_type count) const -> size_type
Finds the last character equal to none of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1301
constexpr auto rend() noexcept -> reverse_iterator
Returns a reverse iterator to the first character of the reversed string. It corresponds to the last ...
Definition basic_inplace_string.hpp:322
constexpr auto begin() noexcept -> iterator
Returns an iterator to the beginning.
Definition basic_inplace_string.hpp:264
constexpr auto erase(size_type index=0, size_type count=npos) noexcept -> basic_inplace_string &
Removes min(count, size() - index) characters starting at index.
Definition basic_inplace_string.hpp:463
constexpr auto insert(size_type const index, const_pointer s, size_type const count) noexcept -> basic_inplace_string &
Inserts the characters in the range [s, s+count) at the position index. The range can contain null ch...
Definition basic_inplace_string.hpp:627
constexpr auto assign(basic_inplace_string const &str, size_type pos, size_type count=npos) noexcept -> basic_inplace_string &
Replaces the contents with a substring [ pos, pos + count ) of str.
Definition basic_inplace_string.hpp:193
constexpr auto ends_with(const_pointer str) const -> bool
Checks if the string ends with the given prefix.
Definition basic_inplace_string.hpp:861
constexpr auto end() noexcept -> iterator
Returns an iterator to the end.
Definition basic_inplace_string.hpp:282
constexpr auto begin() const noexcept -> const_iterator
Returns an const iterator to the beginning.
Definition basic_inplace_string.hpp:270
constexpr auto starts_with(const_pointer s) const -> bool
Checks if the string begins with the given prefix.
Definition basic_inplace_string.hpp:843
constexpr auto cbegin() const noexcept -> const_iterator
Returns an const iterator to the beginning.
Definition basic_inplace_string.hpp:276
constexpr auto append(const_pointer s) noexcept -> basic_inplace_string &
Appends the null-terminated character string pointed to by s. The length of the string is determined ...
Definition basic_inplace_string.hpp:521
constexpr auto contains(Char c) const noexcept -> bool
Checks if the string contains the given substring.
Definition basic_inplace_string.hpp:1322
constexpr auto append(const_pointer str, size_type count) noexcept -> basic_inplace_string &
Appends characters in the range [ str, str + count ). This range can contain null characters.
Definition basic_inplace_string.hpp:529
constexpr auto find(const_pointer s, size_type pos, size_type count) const noexcept -> size_type
Finds the first substring equal to the given character sequence. Search begins at pos,...
Definition basic_inplace_string.hpp:1056
constexpr auto compare(size_type pos1, size_type count1, StringView const &view) const noexcept -> int
Implicitly converts view to a string view sv, then compares a [pos1, pos1+count1) substring of this s...
Definition basic_inplace_string.hpp:805
constexpr auto compare(basic_inplace_string const &str) const noexcept -> int
Compares this string to str.
Definition basic_inplace_string.hpp:715
constexpr auto rfind(Char ch, size_type pos=0) const noexcept -> size_type
Finds the last substring equal to the given character sequence. Search begins at pos,...
Definition basic_inplace_string.hpp:1144
constexpr auto contains(Char const *s) const -> bool
Checks if the string contains the given substring.
Definition basic_inplace_string.hpp:1328
constexpr auto push_back(Char ch) noexcept -> void
Appends the given character ch to the end of the string.
Definition basic_inplace_string.hpp:495
constexpr auto append(size_type const count, Char const s) noexcept -> basic_inplace_string &
Appends count copies of character s.
Definition basic_inplace_string.hpp:510
constexpr auto operator=(basic_inplace_string const &) noexcept -> basic_inplace_string &=default
Defaulted copy assignment.
constexpr auto find_first_of(basic_string_view< Char, traits_type > str, size_type pos=0) const noexcept -> size_type
Finds the first character equal to one of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1195
constexpr auto replace(size_type pos, size_type count, Char const *str) -> basic_inplace_string &
Definition basic_inplace_string.hpp:925
constexpr auto append(StringView const &view) -> basic_inplace_string &
Implicitly converts view to a string_view sv, then appends all characters from sv.
Definition basic_inplace_string.hpp:565
constexpr auto empty() const noexcept -> bool
Checks whether the string is empty.
Definition basic_inplace_string.hpp:370
constexpr auto compare(const_pointer s) const -> int
Compares this string to the null-terminated character sequence beginning at the character pointed to ...
Definition basic_inplace_string.hpp:762
constexpr auto clear() noexcept -> void
Removes all characters from the string. Sets size to 0 and overrides the buffer with zeros.
Definition basic_inplace_string.hpp:454
constexpr auto pop_back() noexcept -> void
Removes the last character from the string.
Definition basic_inplace_string.hpp:503
constexpr auto find_first_of(Char ch, size_type pos=0) const noexcept -> size_type
Finds the first character equal to one of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1185
constexpr auto find_first_of(basic_inplace_string const &str, size_type pos=0) const noexcept -> size_type
Finds the first character equal to one of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1153
constexpr auto data() noexcept -> pointer
Returns a pointer to the underlying array serving as character storage. The pointer is such that the ...
Definition basic_inplace_string.hpp:419
constexpr auto back() const noexcept -> const_reference
Accesses the last character.
Definition basic_inplace_string.hpp:363
static constexpr bool string_view_like
Definition basic_inplace_string.hpp:44
constexpr auto length() const noexcept -> size_type
Returns the number of characters.
Definition basic_inplace_string.hpp:388
constexpr auto front() noexcept -> reference
Accesses the first character.
Definition basic_inplace_string.hpp:342
constexpr auto find(const_pointer s, size_type pos=0) const noexcept -> size_type
Finds the first substring equal to the given character sequence. Search begins at pos,...
Definition basic_inplace_string.hpp:1069
constexpr basic_inplace_string(basic_inplace_string const &other, size_type pos, size_type count)
Constructs the string with a substring [pos, pos+count) of other.
Definition basic_inplace_string.hpp:104
constexpr auto append(StringView const &view, size_type pos, size_type count=npos) -> basic_inplace_string &
Implicitly converts view to a string_view sv then appends the characters from the subview [ pos,...
Definition basic_inplace_string.hpp:575
constexpr auto swap(basic_inplace_string &other) noexcept -> void
Exchanges the contents of the string with those of other. All iterators and references may be invalid...
Definition basic_inplace_string.hpp:1025
constexpr auto insert(size_type const index, basic_inplace_string const &str, size_type const indexStr, size_type const count=npos) noexcept -> basic_inplace_string &
Inserts a string, obtained by str.substr(index_str, count) at the position index.
Definition basic_inplace_string.hpp:643
constexpr auto full() const noexcept -> bool
Checks whether the string is full. i.e. size() == capacity()
Definition basic_inplace_string.hpp:376
constexpr auto assign(const_pointer s) noexcept -> basic_inplace_string &
Replaces the contents with those of null-terminated character string pointed to by s.
Definition basic_inplace_string.hpp:211
static constexpr auto shrink_to_fit() -> void
Shrink to fit is a nop, since the capacity is fixed.
Definition basic_inplace_string.hpp:411
constexpr auto ends_with(basic_string_view< Char, Traits > sv) const noexcept -> bool
Checks if the string ends with the given prefix.
Definition basic_inplace_string.hpp:849
constexpr auto max_size() const noexcept -> size_type
Returns the number of characters that can be held in allocated storage, NOT including the null termin...
Definition basic_inplace_string.hpp:402
constexpr auto operator+=(Char ch) noexcept -> basic_inplace_string &
Appends character ch.
Definition basic_inplace_string.hpp:588
constexpr auto compare(size_type pos1, size_type count1, StringView const &view, size_type pos2, size_type count2=npos) const noexcept -> int
Implicitly converts view to a string view sv, then compares a [pos1, pos1+count1) substring of this s...
Definition basic_inplace_string.hpp:817
constexpr auto end() const noexcept -> const_iterator
Returns an const iterator to the end.
Definition basic_inplace_string.hpp:288
constexpr auto starts_with(Char c) const noexcept -> bool
Checks if the string begins with the given prefix.
Definition basic_inplace_string.hpp:837
constexpr auto find_first_not_of(Char const *s, size_type pos) const -> size_type
Finds the first character not equal to any of the characters in the given character sequence.
Definition basic_inplace_string.hpp:1226
constexpr auto replace(const_iterator first, const_iterator last, Char const *str, size_type count2) -> basic_inplace_string &
Definition basic_inplace_string.hpp:916
constexpr auto replace(size_type pos, size_type count, Char const *str, size_type count2) -> basic_inplace_string &
Definition basic_inplace_string.hpp:905
constexpr basic_inplace_string()=default
Default constructor.
constexpr auto assign(const_pointer s, size_type count) noexcept -> basic_inplace_string &
Replaces the contents with copies of the characters in the range [ s, s + count )....
Definition basic_inplace_string.hpp:202
constexpr basic_inplace_string(basic_inplace_string const &other, size_type pos)
Constructs the string with a substring [pos, other.size()).
Definition basic_inplace_string.hpp:110
constexpr basic_inplace_string(StringView const &view, size_type pos, size_type n)
Implicitly converts view to a string view sv, then initializes the string with the subrange [ pos,...
Definition basic_inplace_string.hpp:130
constexpr auto compare(size_type const pos1, size_type const count1, basic_inplace_string const &str, size_type const pos2, size_type const count2=npos) const -> int
Compares a [pos1, pos1+count1) substring of this string to a substring [pos2, pos2+count2) of str....
Definition basic_inplace_string.hpp:742
constexpr auto compare(basic_inplace_string< Char, OtherCapacity, traits_type > const &str) const noexcept -> int
Compares this string to str with other capacity.
Definition basic_inplace_string.hpp:723
constexpr auto crend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first character of the reversed string. It corresponds to the last ...
Definition basic_inplace_string.hpp:336
constexpr auto erase(const_iterator first, const_iterator last) noexcept -> iterator
Removes the characters in the range [first, last).
Definition basic_inplace_string.hpp:483
constexpr auto insert(size_type const index, basic_inplace_string const &str) noexcept -> basic_inplace_string &
Inserts string str at the position index.
Definition basic_inplace_string.hpp:635
constexpr auto replace(size_type pos, size_type count, basic_inplace_string const &str, size_type pos2, size_type count2=npos) -> basic_inplace_string &
Definition basic_inplace_string.hpp:891
constexpr auto resize(size_type count, Char ch) noexcept -> void
Resizes the string to contain count characters.
Definition basic_inplace_string.hpp:1003
constexpr operator basic_string_view< Char, traits_type >() const noexcept
Returns a etl::basic_string_view.
Definition basic_inplace_string.hpp:447
constexpr auto insert(size_type const index, size_type const count, Char const ch) noexcept -> basic_inplace_string &
Inserts count copies of character ch at the position index.
Definition basic_inplace_string.hpp:609
constexpr auto data() const noexcept -> const_pointer
Returns a pointer to the underlying array serving as character storage. The pointer is such that the ...
Definition basic_inplace_string.hpp:430
constexpr auto compare(size_type const pos1, size_type const count1, const_pointer s, size_type const count2) const -> int
Compares a [pos1, pos1+count1) substring of this string to the characters in the range [s,...
Definition basic_inplace_string.hpp:783
constexpr auto compare(StringView const &view) const noexcept -> int
Implicitly converts view to a string view sv, then compares the content of this string to sv.
Definition basic_inplace_string.hpp:794
constexpr basic_inplace_string(StringView const &view) noexcept
Implicitly converts view to a string view sv, then initializes the string with the contents of sv.
Definition basic_inplace_string.hpp:119
constexpr auto contains(etl::basic_string_view< Char, Traits > sv) const noexcept -> bool
Checks if the string contains the given substring.
Definition basic_inplace_string.hpp:1316
constexpr auto rend() const noexcept -> const_reverse_iterator
Returns a reverse iterator to the first character of the reversed string. It corresponds to the last ...
Definition basic_inplace_string.hpp:329
constexpr auto find_last_not_of(Char const *s, size_type pos=0) const -> size_type
Finds the last character equal to none of the characters in the given character sequence....
Definition basic_inplace_string.hpp:1310
constexpr auto append(basic_inplace_string const &str) noexcept -> basic_inplace_string &
Appends string str.
Definition basic_inplace_string.hpp:549
constexpr auto size() const noexcept -> size_type
Returns the number of characters.
Definition basic_inplace_string.hpp:382
constexpr auto cend() const noexcept -> const_iterator
Returns an const iterator to the end.
Definition basic_inplace_string.hpp:294
constexpr auto capacity() const noexcept -> size_type
Returns the number of characters that can be held in allocated storage, NOT including the null termin...
Definition basic_inplace_string.hpp:395
constexpr basic_inplace_string(nullptr_t)=delete
constexpr auto copy(pointer destination, size_type count, size_type pos=0) const -> size_type
Copies a substring [pos, pos+count) to character string pointed to by dest. If the requested substrin...
Definition basic_inplace_string.hpp:986
constexpr auto replace(const_iterator first, const_iterator last, Char const *str) -> basic_inplace_string &
Definition basic_inplace_string.hpp:936
constexpr basic_inplace_string(InputIt first, InputIt last) noexcept
Constructs the string with the contents of the range [ first, last). Fails silently if input length i...
Definition basic_inplace_string.hpp:98
constexpr auto rbegin() noexcept -> reverse_iterator
Returns a reverse iterator to the first character of the reversed string. It corresponds to the last ...
Definition basic_inplace_string.hpp:301
constexpr basic_inplace_string(basic_inplace_string &&) noexcept=default
Defaulted move constructor.
constexpr auto operator=(nullptr_t) -> basic_inplace_string &=delete
constexpr auto find(basic_inplace_string const &str, size_type pos=0) const noexcept -> size_type
Finds the first substring equal to the given character sequence. Search begins at pos,...
Definition basic_inplace_string.hpp:1043
The class template basic_string_view describes an object that can refer to a constant contiguous sequ...
Definition basic_string_view.hpp:35
static constexpr auto max() noexcept -> unsigned long
Definition numeric_limits.hpp:811
Definition numeric_limits.hpp:18