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