Embedded Template Library 1.0
Loading...
Searching...
No Matches
basic_string.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2016 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_BASIC_STRING_INCLUDED
32#define ETL_BASIC_STRING_INCLUDED
33
34#include "platform.h"
35#include "algorithm.h"
36#include "iterator.h"
37#include "functional.h"
38#include "alignment.h"
39#include "array.h"
40#include "type_traits.h"
41#include "error_handler.h"
42#include "integral_limits.h"
43#include "exception.h"
44#include "memory.h"
45#include "binary.h"
46#include "flags.h"
47#include "string_utilities.h"
48
49#include <stddef.h>
50#include <stdint.h>
51#include <string.h>
52
53#if ETL_USING_LIBC_WCHAR_H
54 #include <wchar.h>
55#endif
56
57#if ETL_USING_STL && ETL_USING_CPP17
58 #include <string_view>
59#endif
60
61#if ETL_USING_STL
62 #include <ostream>
63#endif
64
65#include "private/minmax_push.h"
66
67//*****************************************************************************
71//*****************************************************************************
72
73// Forward declaration of string_view
74namespace etl
75{
76 template <typename T, typename TTraits>
77 class basic_string_view;
78}
79
80namespace etl
81{
82 //***************************************************************************
85 //***************************************************************************
87 {
88 public:
89
90 string_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
92 {
93 }
94 };
95
96 //***************************************************************************
99 //***************************************************************************
101 {
102 public:
103
104 string_empty(string_type file_name_, numeric_type line_number_)
105 : string_exception(ETL_ERROR_TEXT("string:empty", ETL_BASIC_STRING_FILE_ID"A"), file_name_, line_number_)
106 {
107 }
108 };
109
110 //***************************************************************************
113 //***************************************************************************
115 {
116 public:
117
118 string_out_of_bounds(string_type file_name_, numeric_type line_number_)
119 : string_exception(ETL_ERROR_TEXT("string:bounds", ETL_BASIC_STRING_FILE_ID"B"), file_name_, line_number_)
120 {
121 }
122 };
123
124 //***************************************************************************
127 //***************************************************************************
129 {
130 public:
131
132 string_iterator(string_type file_name_, numeric_type line_number_)
133 : string_exception(ETL_ERROR_TEXT("string:iterator", ETL_BASIC_STRING_FILE_ID"C"), file_name_, line_number_)
134 {
135 }
136 };
137
138 //***************************************************************************
141 //***************************************************************************
143 {
144 public:
145
146 string_truncation(string_type file_name_, numeric_type line_number_)
147 : string_exception(ETL_ERROR_TEXT("string:truncation", ETL_BASIC_STRING_FILE_ID"D"), file_name_, line_number_)
148 {
149 }
150 };
151
152 //***************************************************************************
155 //***************************************************************************
156 namespace private_basic_string
157 {
158 //*************************************************************************
159 template <typename T = void>
161 {
162 public:
163
164 typedef size_t size_type;
165
166 static ETL_CONSTANT uint_least8_t IS_TRUNCATED = etl::bit<0>::value;
167 static ETL_CONSTANT uint_least8_t CLEAR_AFTER_USE = etl::bit<1>::value;
168
169 static ETL_CONSTANT size_type npos = etl::integral_limits<size_type>::max;
170 };
171
172 template <typename T>
174
175 template <typename T>
177
178 template <typename T>
179 ETL_CONSTANT typename string_base_statics<T>::size_type string_base_statics<T>::npos;
180 }
181
182 //***************************************************************************
184 {
185 public:
186
187 typedef size_t size_type;
188
189 //*************************************************************************
192 //*************************************************************************
193 size_type size() const
194 {
195 return current_size;
196 }
197
198 //*************************************************************************
201 //*************************************************************************
202 size_type length() const
203 {
204 return current_size;
205 }
206
207 //*************************************************************************
210 //*************************************************************************
211 bool empty() const
212 {
213 return (current_size == 0);
214 }
215
216 //*************************************************************************
219 //*************************************************************************
220 bool full() const
221 {
222 return current_size == CAPACITY;
223 }
224
225 //*************************************************************************
228 //*************************************************************************
229 size_type capacity() const
230 {
231 return CAPACITY;
232 }
233
234 //*************************************************************************
237 //*************************************************************************
238 size_type max_size() const
239 {
240 return CAPACITY;
241 }
242
243 //*************************************************************************
246 //*************************************************************************
247 size_type available() const
248 {
249 return max_size() - size();
250 }
251
252 //*************************************************************************
255 //*************************************************************************
256 bool is_truncated() const
257 {
258#if ETL_HAS_STRING_TRUNCATION_CHECKS
259 return flags.test<IS_TRUNCATED>();
260#else
261 return false;
262#endif
263 }
264
265 //*************************************************************************
269 //*************************************************************************
270 ETL_DEPRECATED
271 bool truncated() const
272 {
273 return is_truncated();
274 }
275
276#if ETL_HAS_STRING_TRUNCATION_CHECKS
277 //*************************************************************************
279 //*************************************************************************
281 {
282 flags.set<IS_TRUNCATED, false>();
283 }
284#endif
285
286#if ETL_HAS_STRING_CLEAR_AFTER_USE
287 //*************************************************************************
289 //*************************************************************************
291 {
292 flags.set<CLEAR_AFTER_USE>();
293 }
294#endif
295
296 //*************************************************************************
298 //*************************************************************************
299 bool is_secure() const
300 {
301#if ETL_HAS_STRING_CLEAR_AFTER_USE
302 return flags.test<CLEAR_AFTER_USE>();
303#else
304 return false;
305#endif
306 }
307
308 protected:
309
310 //*************************************************************************
312 //*************************************************************************
314 : current_size(0)
316 {
317 }
318
319#if ETL_HAS_STRING_TRUNCATION_CHECKS
320 //*************************************************************************
322 //*************************************************************************
323 void set_truncated(bool status)
324 {
325 flags.set<IS_TRUNCATED>(status);
326 }
327#endif
328
329 //*************************************************************************
331 //*************************************************************************
333 {
334 }
335
336 size_type current_size;
337 const size_type CAPACITY;
338
339#if ETL_HAS_STRING_TRUNCATION_CHECKS || ETL_HAS_STRING_CLEAR_AFTER_USE
341#endif
342 };
343
344 //***************************************************************************
348 //***************************************************************************
349 template <typename T>
351 {
352 public:
353
355
356 typedef T value_type;
357 typedef T& reference;
358 typedef const T& const_reference;
359 typedef T* pointer;
360 typedef const T* const_pointer;
361 typedef T* iterator;
362 typedef const T* const_iterator;
363 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
364 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
365
366 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
367
368 //*********************************************************************
371 //*********************************************************************
372 iterator begin()
373 {
374 return &p_buffer[0];
375 }
376
377 //*********************************************************************
380 //*********************************************************************
381 const_iterator begin() const
382 {
383 return &p_buffer[0];
384 }
385
386 //*********************************************************************
389 //*********************************************************************
390 iterator end()
391 {
392 return &p_buffer[current_size];
393 }
394
395 //*********************************************************************
398 //*********************************************************************
399 const_iterator end() const
400 {
401 return &p_buffer[current_size];
402 }
403
404 //*********************************************************************
407 //*********************************************************************
408 const_iterator cbegin() const
409 {
410 return &p_buffer[0];
411 }
412
413 //*********************************************************************
416 //*********************************************************************
417 const_iterator cend() const
418 {
419 return &p_buffer[current_size];
420 }
421
422 //*********************************************************************
425 //*********************************************************************
426 reverse_iterator rbegin()
427 {
428 return reverse_iterator(end());
429 }
430
431 //*********************************************************************
434 //*********************************************************************
435 const_reverse_iterator rbegin() const
436 {
437 return const_reverse_iterator(end());
438 }
439
440 //*********************************************************************
443 //*********************************************************************
444 reverse_iterator rend()
445 {
446 return reverse_iterator(begin());
447 }
448
449 //*********************************************************************
452 //*********************************************************************
453 const_reverse_iterator rend() const
454 {
455 return const_reverse_iterator(begin());
456 }
457
458 //*********************************************************************
461 //*********************************************************************
462 const_reverse_iterator crbegin() const
463 {
464 return const_reverse_iterator(cend());
465 }
466
467 //*********************************************************************
470 //*********************************************************************
471 const_reverse_iterator crend() const
472 {
473 return const_reverse_iterator(cbegin());
474 }
475
476 //*********************************************************************
480 //*********************************************************************
481 void resize(size_type new_size)
482 {
483 resize(new_size, 0);
484 }
485
486 //*********************************************************************
490 //*********************************************************************
491 void resize(size_type new_size, T value)
492 {
493 if (new_size > CAPACITY)
494 {
495#if ETL_HAS_STRING_TRUNCATION_CHECKS
496 set_truncated(true);
497
498#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
499 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
500#endif
501#endif
502 }
503
504 new_size = etl::min(new_size, CAPACITY);
505
506 // Size up?
508 {
509 etl::fill(p_buffer + current_size, p_buffer + new_size, value);
510 }
511
513 p_buffer[new_size] = 0;
514 cleanup();
515 }
516
517 //*********************************************************************
519 //*********************************************************************
520 template <typename TOperation>
521 void resize_and_overwrite(size_type new_size, TOperation operation)
522 {
523 if (new_size > CAPACITY)
524 {
525 ETL_ASSERT_FAIL(ETL_ERROR(string_out_of_bounds));
526 }
527
528 current_size = operation(p_buffer, new_size);
529 p_buffer[current_size] = '\0';
530 cleanup();
531 }
532
533 //*********************************************************************
537 //*********************************************************************
539 {
540 new_size = etl::min(new_size, CAPACITY);
541
543 p_buffer[new_size] = 0;
544 }
545
546 //*********************************************************************
550 //*********************************************************************
551 void fill(T value)
552 {
553 etl::fill(begin(), end(), value);
554 }
555
556 //*********************************************************************
560 //*********************************************************************
561 reference operator [](size_type i)
562 {
563 return p_buffer[i];
564 }
565
566 //*********************************************************************
570 //*********************************************************************
571 const_reference operator [](size_type i) const
572 {
573 return p_buffer[i];
574 }
575
576 //*********************************************************************
581 //*********************************************************************
582 reference at(size_type i)
583 {
584 ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds));
585 return p_buffer[i];
586 }
587
588 //*********************************************************************
593 //*********************************************************************
594 const_reference at(size_type i) const
595 {
596 ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds));
597 return p_buffer[i];
598 }
599
600 //*********************************************************************
603 //*********************************************************************
604 reference front()
605 {
606 return p_buffer[0];
607 }
608
609 //*********************************************************************
612 //*********************************************************************
613 const_reference front() const
614 {
615 return p_buffer[0];
616 }
617
618 //*********************************************************************
621 //*********************************************************************
622 reference back()
623 {
624 return p_buffer[current_size - 1];
625 }
626
627 //*********************************************************************
630 //*********************************************************************
631 const_reference back() const
632 {
633 return p_buffer[current_size - 1];
634 }
635
636 //*********************************************************************
639 //*********************************************************************
640 pointer data()
641 {
642 return p_buffer;
643 }
644
645 //*********************************************************************
648 //*********************************************************************
649 ETL_CONSTEXPR const_pointer data() const
650 {
651 return p_buffer;
652 }
653
654 //*********************************************************************
657 //*********************************************************************
658 pointer data_end()
659 {
660 return p_buffer + current_size;
661 }
662
663 //*********************************************************************
666 //*********************************************************************
667 const_pointer data_end() const
668 {
669 return p_buffer + current_size;
670 }
671
672 //*********************************************************************
676 //*********************************************************************
678 {
679 if (&other != this)
680 {
681 append_impl(begin(), other.begin(), other.end(), other.is_truncated(), other.is_secure());
682 }
683 }
684
685 //*********************************************************************
691 //*********************************************************************
692 void assign(const etl::ibasic_string<T>& other, size_type subposition, size_type sublength)
693 {
694 if (&other != this)
695 {
696 if (sublength == npos)
697 {
698 sublength = other.size() - subposition;
699 }
700
701 ETL_ASSERT(subposition <= other.size(), ETL_ERROR(string_out_of_bounds));
702
703 append_impl(begin(), other.begin() + subposition, other.begin() + subposition + sublength, other.is_truncated(), other.is_secure());
704 }
705 }
706
707 //*********************************************************************
713 //*********************************************************************
714 template <typename TIterator>
715 void assign(TIterator first, TIterator last)
716 {
717 append_impl(begin(), first, last, false, false);
718 }
719
720 //*********************************************************************
724 //*********************************************************************
725 void assign(const_pointer str)
726 {
727 append_impl(begin(), str, false, false);
728 }
729
730 //*********************************************************************
735 //*********************************************************************
736 void assign(const_pointer str, size_type n)
737 {
738 append_impl(begin(), str, str + n, false, false);
739 }
740
741 //*********************************************************************
743 //*********************************************************************
744 template <typename TOtherTraits>
746 {
747 append_impl(begin(), view.begin(), view.end(), false, false);
748 }
749
750 //*********************************************************************
755 //*********************************************************************
756 void assign(size_type n, T c)
757 {
758 clear();
759
760#if ETL_HAS_STRING_TRUNCATION_CHECKS
762
763#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
764 ETL_ASSERT(is_truncated == false, ETL_ERROR(string_truncation));
765#endif
766#endif
767
768 n = etl::min(n, CAPACITY);
769
770 etl::fill_n(begin(), n, c);
771 current_size = n;
772 p_buffer[current_size] = 0;
773 }
774
775 //*************************************************************************
777 //*************************************************************************
778 void clear()
779 {
780 initialise();
781 cleanup();
782 }
783
784 //*********************************************************************
788 //*********************************************************************
789 void push_back(T value)
790 {
791 if (current_size != CAPACITY)
792 {
793 p_buffer[current_size++] = value;
794 p_buffer[current_size] = 0;
795 }
796 else
797 {
798#if ETL_HAS_STRING_TRUNCATION_CHECKS
799 set_truncated(true);
800
801#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
802 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
803#endif
804#endif
805 }
806 }
807
808 //*************************************************************************
811 //*************************************************************************
812 void pop_back()
813 {
814 if (current_size != 0)
815 {
816 p_buffer[--current_size] = 0;
817 }
818 }
819
820 //*********************************************************************
823 //*********************************************************************
825 {
826 append_impl(end(), str.begin(), str.end(), str.is_truncated(), str.is_secure());
827
828 return *this;
829 }
830
831 //*********************************************************************
836 //*********************************************************************
837 ibasic_string& append(const ibasic_string& str, size_type subposition, size_type sublength = npos)
838 {
839 if (sublength == npos)
840 {
841 sublength = str.size() - subposition;
842 }
843
844 ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
845
846 append_impl(end(), str.begin() + subposition, str.begin() + subposition + sublength, str.is_truncated(), str.is_secure());
847
848 return *this;
849 }
850
851 //*********************************************************************
855 //*********************************************************************
856 template <class TIterator>
858 {
859 append_impl(end(), first, last, false, false);
860
861 return *this;
862 }
863
864 //*********************************************************************
867 //*********************************************************************
868 ibasic_string& append(const_pointer str)
869 {
870 append_impl(end(), str, false, false);
871
872 return *this;
873 }
874
875 //*********************************************************************
879 //*********************************************************************
880 ibasic_string& append(const_pointer str, size_type n)
881 {
882 append_impl(end(), str, str + n, false, false);
883
884 return *this;
885 }
886
887 //*********************************************************************
890 //*********************************************************************
891 template <typename TOtherTraits>
893 {
894 append_impl(end(), view.begin(), view.end(), false, false);
895
896 return *this;
897 }
898
899 //*********************************************************************
903 //*********************************************************************
904 ibasic_string& append(size_type n, T c)
905 {
906 size_type free_space = CAPACITY - current_size;
907
908#if ETL_HAS_STRING_TRUNCATION_CHECKS
910
911#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
912 ETL_ASSERT(is_truncated == false, ETL_ERROR(string_truncation));
913#endif
914#endif
915
916 n = etl::min(n, size_t(free_space));
917
918 etl::fill_n(end(), n, c);
919 current_size += n;
920 p_buffer[current_size] = 0;
921
922 return *this;
923 }
924
925 //*********************************************************************
929 //*********************************************************************
930 iterator insert(const_iterator position, T value)
931 {
932 // Quick hack, as iterators are pointers.
933 iterator insert_position = to_iterator(position);
934
936 {
937 // Not full yet.
938 if (position != end())
939 {
940 // Insert in the middle.
941 ++current_size;
942 etl::mem_move(insert_position, end() - 1, insert_position + 1);
943 *insert_position = value;
944 }
945 else
946 {
947 // Insert at the end.
948 *insert_position = value;
949 ++current_size;
950 }
951 }
952 else
953 {
954 // Already full.
955 if (position != end())
956 {
957 // Insert in the middle.
958 etl::mem_move(insert_position, end() - 1, insert_position + 1);
959 *insert_position = value;
960 }
961
962#if ETL_HAS_STRING_TRUNCATION_CHECKS
963 set_truncated(true);
964
965#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
966 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
967#endif
968#endif
969 }
970
971 p_buffer[current_size] = 0;
972
973 return insert_position;
974 }
975
976 //*********************************************************************
981 //*********************************************************************
982 iterator insert(const_iterator position, size_type n, T value)
983 {
984 iterator position_ = to_iterator(position);
985
986 if (n == 0)
987 {
988 return position_;
989 }
990
991 // Quick hack, as iterators are pointers.
992 iterator insert_position = to_iterator(position);
993 const size_type start = etl::distance(cbegin(), position);
994
995 // No effect.
996 if (start >= CAPACITY)
997 {
998#if ETL_HAS_STRING_TRUNCATION_CHECKS
999 set_truncated(true);
1000
1001#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1002 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1003#endif
1004#endif
1005 return to_iterator(position);;
1006 }
1007
1008 // Fills the string to the end?
1009 if ((start + n) >= CAPACITY)
1010 {
1011 if ((current_size + n) > CAPACITY)
1012 {
1013#if ETL_HAS_STRING_TRUNCATION_CHECKS
1014 set_truncated(true);
1015
1016#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1017 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1018#endif
1019#endif
1020 }
1021
1023 etl::fill(insert_position, end(), value);
1024 }
1025 else
1026 {
1027 // Lets do some shifting.
1028 const size_type shift_amount = n;
1029 const size_type to_position = start + shift_amount;
1030 const size_type remaining_characters = current_size - start;
1031 const size_type max_shift_characters = CAPACITY - start - shift_amount;
1033
1034 // Will the string truncate?
1035 if ((start + shift_amount + remaining_characters) > CAPACITY)
1036 {
1038
1039#if ETL_HAS_STRING_TRUNCATION_CHECKS
1040 set_truncated(true);
1041
1042#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1043 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1044#endif
1045#endif
1046 }
1047 else
1048 {
1050 }
1051
1053 etl::fill(insert_position, insert_position + shift_amount, value);
1054 }
1055
1056 p_buffer[current_size] = 0;
1057
1058 return position_;
1059 }
1060
1061 //*********************************************************************
1067 //*********************************************************************
1068 template <typename TIterator>
1069 iterator insert(const_iterator position, TIterator first, TIterator last)
1070 {
1071 iterator position_ = to_iterator(position);
1072
1073 if (first == last)
1074 {
1075 return position_;
1076 }
1077
1078 const size_type start = etl::distance(begin(), position_);
1079 const size_type n = etl::distance(first, last);
1080
1081 // No effect.
1082 if (start >= CAPACITY)
1083 {
1084#if ETL_HAS_STRING_TRUNCATION_CHECKS
1085 set_truncated(true);
1086
1087#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1088 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1089#endif
1090#endif
1091 return position_;
1092 }
1093
1094 // Fills the string to the end?
1095 if ((start + n) >= CAPACITY)
1096 {
1097 if (((current_size + n) > CAPACITY))
1098 {
1099#if ETL_HAS_STRING_TRUNCATION_CHECKS
1100 set_truncated(true);
1101
1102#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1103 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1104#endif
1105#endif
1106 }
1107
1109
1110 position_ = copy_characters(first, etl::distance(position_, end()), position_);
1111 }
1112 else
1113 {
1114 // Lets do some shifting.
1115 const size_type shift_amount = n;
1116 const size_type to_position = start + shift_amount;
1117 const size_type remaining_characters = current_size - start;
1118 const size_type max_shift_characters = CAPACITY - start - shift_amount;
1120
1121 // Will the string truncate?
1122 if ((start + shift_amount + remaining_characters) > CAPACITY)
1123 {
1125
1126#if ETL_HAS_STRING_TRUNCATION_CHECKS
1127 set_truncated(true);
1128
1129#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1130 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1131#endif
1132#endif
1133 }
1134 else
1135 {
1137 }
1138
1140 //etl::copy_backward(position_, position_ + characters_to_shift, begin() + to_position + characters_to_shift);
1141
1142 position_ = copy_characters(first, etl::distance(first, last), position_);
1143 }
1144
1145 p_buffer[current_size] = 0;
1146
1147 return position_;
1148 }
1149
1150 //*********************************************************************
1155 //*********************************************************************
1156 template <typename TOtherTraits>
1157 iterator insert(const_iterator position, const etl::basic_string_view<T, TOtherTraits>& view)
1158 {
1159 return insert(position, view.begin(), view.end());
1160 }
1161
1162 //*********************************************************************
1166 //*********************************************************************
1167 etl::ibasic_string<T>& insert(size_type position, const etl::ibasic_string<T>& str)
1168 {
1169 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1170
1171 insert(begin() + position, str.cbegin(), str.cend());
1172
1173#if ETL_HAS_STRING_TRUNCATION_CHECKS
1174 if (str.is_truncated())
1175 {
1176 set_truncated(true);
1177
1178#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1179 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1180#endif
1181 }
1182#endif
1183
1184 return *this;
1185 }
1186
1187 //*********************************************************************
1191 //*********************************************************************
1192 template <typename TOtherTraits>
1194 {
1195 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1196
1197 insert(begin() + position, view.cbegin(), view.cend());
1198
1199 return *this;
1200 }
1201
1202 //*********************************************************************
1208 //*********************************************************************
1209 etl::ibasic_string<T>& insert(size_type position, const etl::ibasic_string<T>& str, size_type subposition, size_type sublength)
1210 {
1211 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1212 ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
1213
1214 if ((sublength == npos) || (subposition + sublength > str.size()))
1215 {
1216 sublength = str.size() - subposition;
1217 }
1218
1219 insert(begin() + position, str.cbegin() + subposition, str.cbegin() + subposition + sublength);
1220
1221#if ETL_HAS_STRING_TRUNCATION_CHECKS
1222 if (str.is_truncated())
1223 {
1224 set_truncated(true);
1225
1226#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1227 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1228#endif
1229 }
1230#endif
1231
1232 return *this;
1233 }
1234
1235 //*********************************************************************
1241 //*********************************************************************
1242 template <typename TOtherTraits>
1244 {
1245 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1246 ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
1247
1248 if ((sublength == npos) || (subposition + sublength > view.size()))
1249 {
1250 sublength = view.size() - subposition;
1251 }
1252
1253 insert(begin() + position, view.cbegin() + subposition, view.cbegin() + subposition + sublength);
1254
1255 return *this;
1256 }
1257
1258 //*********************************************************************
1262 //*********************************************************************
1263 etl::ibasic_string<T>& insert(size_type position, const_pointer s)
1264 {
1265 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1266
1267 insert(begin() + position, s, s + etl::strlen(s));
1268 return *this;
1269 }
1270
1271 //*********************************************************************
1276 //*********************************************************************
1277 etl::ibasic_string<T>& insert(size_type position, const_pointer s, size_type n)
1278 {
1279 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1280
1281 insert(begin() + position, s, s + n);
1282 return *this;
1283 }
1284
1285 //*********************************************************************
1290 //*********************************************************************
1291 etl::ibasic_string<T>& insert(size_type position, size_type n, value_type c)
1292 {
1293 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1294
1295 insert(begin() + position, n, c);
1296 return *this;
1297 }
1298
1299 //*********************************************************************
1304 //*********************************************************************
1305 etl::ibasic_string<T>& erase(size_type position, size_type length_ = npos)
1306 {
1307 // Limit the length.
1308 length_ = etl::min(length_, size() - position);
1309
1310 erase(begin() + position, begin() + position + length_);
1311
1312 return *this;
1313 }
1314
1315 //*********************************************************************
1319 //*********************************************************************
1320 iterator erase(iterator i_element)
1321 {
1322 etl::mem_move(i_element + 1, end(), i_element);
1323 p_buffer[--current_size] = 0;
1324
1325 return i_element;
1326 }
1327
1328 //*********************************************************************
1332 //*********************************************************************
1333 iterator erase(const_iterator i_element)
1334 {
1335 iterator i_element_(to_iterator(i_element));
1336
1337 etl::mem_move(i_element + 1, end(), i_element_);
1338 p_buffer[--current_size] = 0;
1339
1340 return i_element_;
1341 }
1342
1343 //*********************************************************************
1350 //*********************************************************************
1351 iterator erase(const_iterator first, const_iterator last)
1352 {
1353 iterator first_ = to_iterator(first);
1354 iterator last_ = to_iterator(last);
1355
1356 if (first_ == last_)
1357 {
1358 return first_;
1359 }
1360
1361 etl::mem_move(last_, end(), first_);
1362 size_type n_delete = etl::distance(first_, last_);
1363
1365 p_buffer[current_size] = 0;
1366 cleanup();
1367
1368 return first_;
1369 }
1370
1371 //*********************************************************************
1373 //*********************************************************************
1374 const_pointer c_str() const
1375 {
1376 return p_buffer;
1377 }
1378
1379 //*********************************************************************
1384 //*********************************************************************
1385 size_type copy(pointer dest, size_type count, size_type pos = 0) const
1386 {
1387 if (pos < size())
1388 {
1389 if (count != npos)
1390 {
1391 count = etl::min(count, size() - pos);
1392 }
1393 else
1394 {
1395 count = size() - pos;
1396 }
1397
1398 etl::mem_move(p_buffer + pos, count, dest);
1399
1400 return count;
1401 }
1402 else
1403 {
1404 return 0U;
1405 }
1406 }
1407
1408 //*********************************************************************
1412 //*********************************************************************
1413 size_type find(const ibasic_string<T>& str, size_type pos = 0) const
1414 {
1415 return find_impl(str.begin(), str.end(), str.size(), pos);
1416 }
1417
1418 //*********************************************************************
1422 //*********************************************************************
1423 template <typename TOtherTraits>
1424 size_type find(const etl::basic_string_view<T, TOtherTraits>& view, size_type pos = 0) const
1425 {
1426 return find_impl(view.begin(), view.end(), view.size(), pos);
1427 }
1428
1429 //*********************************************************************
1433 //*********************************************************************
1434 size_type find(const_pointer s, size_type pos = 0) const
1435 {
1436 size_t sz = etl::strlen(s);
1437
1438 return find_impl(s, s + sz, sz, pos);
1439 }
1440
1441 //*********************************************************************
1446 //*********************************************************************
1447 size_type find(const_pointer s, size_type pos, size_type n) const
1448 {
1449 size_t sz = etl::strlen(s);
1450
1451 return find_impl(s, s + n, sz, pos);
1452 }
1453
1454 //*********************************************************************
1458 //*********************************************************************
1459 size_type find(T c, size_type position = 0) const
1460 {
1461 const_iterator i = etl::find(begin() + position, end(), c);
1462
1463 if (i != end())
1464 {
1465 return etl::distance(begin(), i);
1466 }
1467 else
1468 {
1469 return npos;
1470 }
1471 }
1472
1473 //*********************************************************************
1477 //*********************************************************************
1478 size_type rfind(const ibasic_string<T>& str, size_type position = npos) const
1479 {
1480 return rfind_impl(str.rbegin(), str.rend(), str.size(), position);
1481 }
1482
1483 //*********************************************************************
1487 //*********************************************************************
1488 template <typename TOtherTraits>
1489 size_type rfind(const etl::basic_string_view<T, TOtherTraits>& view, size_type pos = 0) const
1490 {
1491 return rfind_impl(view.rbegin(), view.rend(), view.size(), pos);
1492 }
1493
1494 //*********************************************************************
1498 //*********************************************************************
1499 size_type rfind(const_pointer s, size_type position = npos) const
1500 {
1501 size_type len = etl::strlen(s);
1502
1503 const_reverse_iterator srbegin(s + len);
1504 const_reverse_iterator srend(s);
1505
1506 return rfind_impl(srbegin, srend, len, position);
1507 }
1508
1509 //*********************************************************************
1513 //*********************************************************************
1514 size_type rfind(const_pointer s, size_type position, size_type length_) const
1515 {
1516 const_reverse_iterator srbegin(s + length_);
1517 const_reverse_iterator srend(s);
1518
1519 return rfind_impl(srbegin, srend, length_, position);
1520 }
1521
1522 //*********************************************************************
1526 //*********************************************************************
1527 size_type rfind(T c, size_type position = npos) const
1528 {
1529 if (position >= size())
1530 {
1531 position = size();
1532 }
1533
1534 position = size() - position;
1535
1536 const_reverse_iterator i = etl::find(rbegin() + position, rend(), c);
1537
1538 if (i != rend())
1539 {
1540 return size() - etl::distance(rbegin(), i) - 1;
1541 }
1542 else
1543 {
1544 return npos;
1545 }
1546 }
1547
1548 //*********************************************************************
1550 //*********************************************************************
1551 bool contains(const etl::ibasic_string<T>& str) const
1552 {
1553 return find(str) != npos;
1554 }
1555
1556 //*********************************************************************
1558 //*********************************************************************
1559 template <typename TOtherTraits>
1561 {
1562 return find(view) != npos;
1563 }
1564
1565 //*********************************************************************
1567 //*********************************************************************
1568 bool contains(const_pointer s) const
1569 {
1570 return find(s) != npos;
1571 }
1572
1573 //*********************************************************************
1575 //*********************************************************************
1576 bool contains(value_type c) const
1577 {
1578 return find(c) != npos;
1579 }
1580
1581 //*********************************************************************
1583 //*********************************************************************
1584 bool starts_with(const etl::ibasic_string<T>& str) const
1585 {
1586 return compare(0, str.size(), str) == 0;
1587 }
1588
1589 //*********************************************************************
1591 //*********************************************************************
1592 template <typename TOtherTraits>
1594 {
1595 return compare(0, view.size(), view) == 0;
1596 }
1597
1598 //*********************************************************************
1600 //*********************************************************************
1601 bool starts_with(const_pointer s) const
1602 {
1603 size_t len = etl::strlen(s);
1604
1605 return compare(0, len, s, len) == 0;
1606 }
1607
1608 //*********************************************************************
1610 //*********************************************************************
1611 bool starts_with(value_type c) const
1612 {
1613 return !empty() && (front() == c);
1614 }
1615
1616 //*********************************************************************
1618 //*********************************************************************
1619 bool ends_with(const etl::ibasic_string<T>& str) const
1620 {
1621 if (str.size() > size())
1622 {
1623 return false;
1624 }
1625
1626 return compare(size() - str.size(), str.size(), str) == 0;
1627 }
1628
1629 //*********************************************************************
1631 //*********************************************************************
1632 template <typename TOtherTraits>
1634 {
1635 if (view.size() > size())
1636 {
1637 return false;
1638 }
1639
1640 return compare(size() - view.size(), view.size(), view) == 0;
1641 }
1642
1643 //*********************************************************************
1645 //*********************************************************************
1646 bool ends_with(const_pointer s) const
1647 {
1648 size_t len = etl::strlen(s);
1649
1650 if (len > size())
1651 {
1652 return false;
1653 }
1654
1655 return compare(size() - len, len, s, len) == 0;
1656 }
1657
1658 //*********************************************************************
1660 //*********************************************************************
1661 bool ends_with(value_type c) const
1662 {
1663 return !empty() && (back() == c);
1664 }
1665
1666 //*********************************************************************
1671 //*********************************************************************
1672 ibasic_string& replace(size_type position, size_type length_, const ibasic_string& str)
1673 {
1674 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1675
1676 // Limit the length.
1677 length_ = etl::min(length_, size() - position);
1678
1679 // Erase the bit we want to replace.
1680 erase(position, length_);
1681
1682 // Insert the new stuff.
1683 insert(position, str);
1684
1685 return *this;
1686 }
1687
1688 //*********************************************************************
1693 //*********************************************************************
1694 template <typename TOtherTraits>
1696 {
1697 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1698
1699 // Limit the length.
1700 length_ = etl::min(length_, size() - position);
1701
1702 // Erase the bit we want to replace.
1703 erase(position, length_);
1704
1705 // Insert the new stuff.
1706 insert(position, view);
1707
1708 return *this;
1709 }
1710
1711 //*********************************************************************
1716 //*********************************************************************
1717 ibasic_string& replace(const_iterator first, const_iterator last, const ibasic_string& str)
1718 {
1719 // Quick hack, as iterators are pointers.
1720 iterator first_ = to_iterator(first);
1721 iterator last_ = to_iterator(last);
1722
1723 // Erase the bit we want to replace.
1724 erase(first_, last_);
1725
1726 // Insert the new stuff.
1727 insert(first_, str.begin(), str.end());
1728
1729#if ETL_HAS_STRING_TRUNCATION_CHECKS
1730 if (str.is_truncated())
1731 {
1732 set_truncated(true);
1733
1734#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1735 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1736#endif
1737 }
1738#endif
1739
1740 return *this;
1741 }
1742
1743 //*********************************************************************
1748 //*********************************************************************
1749 template <typename TOtherTraits>
1750 ibasic_string& replace(const_iterator first, const_iterator last, const etl::basic_string_view<T, TOtherTraits>& view)
1751 {
1752 // Quick hack, as iterators are pointers.
1753 iterator first_ = to_iterator(first);
1754 iterator last_ = to_iterator(last);
1755
1756 // Erase the bit we want to replace.
1757 erase(first_, last_);
1758
1759 // Insert the new stuff.
1760 insert(first_, view.begin(), view.end());
1761
1762 return *this;
1763 }
1764
1765 //*********************************************************************
1767 //*********************************************************************
1768 ibasic_string& replace(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength)
1769 {
1770 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1771 ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
1772
1773 // Limit the lengths.
1774 length_ = etl::min(length_, size() - position);
1775 sublength = etl::min(sublength, str.size() - subposition);
1776
1777 // Erase the bit we want to replace.
1778 erase(position, length_);
1779
1780 // Insert the new stuff.
1781 insert(position, str, subposition, sublength);
1782
1783#if ETL_HAS_STRING_TRUNCATION_CHECKS
1784 if (str.is_truncated())
1785 {
1786 set_truncated(true);
1787
1788#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1789 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1790#endif
1791 }
1792#endif
1793
1794 return *this;
1795 }
1796
1797 //*********************************************************************
1799 //*********************************************************************
1800 template <typename TOtherTraits>
1801 ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view<T, TOtherTraits>& view, size_type subposition, size_type sublength)
1802 {
1803 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1804 ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
1805
1806 // Limit the lengths.
1807 length_ = etl::min(length_, size() - position);
1808 sublength = etl::min(sublength, view.size() - subposition);
1809
1810 // Erase the bit we want to replace.
1811 erase(position, length_);
1812
1813 // Insert the new stuff.
1814 insert(position, view, subposition, sublength);
1815
1816 return *this;
1817 }
1818
1819 //*********************************************************************
1821 //*********************************************************************
1822 ibasic_string& replace(size_type position, size_type length_, const_pointer s)
1823 {
1824 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1825
1826 // Limit the length.
1827 length_ = etl::min(length_, size() - position);
1828
1829 // Erase the bit we want to replace.
1830 erase(position, length_);
1831
1832 // Insert the new stuff.
1833 insert(position, s, etl::strlen(s));
1834
1835 return *this;
1836 }
1837
1838 //*********************************************************************
1840 //*********************************************************************
1841 ibasic_string& replace(const_iterator first, const_iterator last, const_pointer s)
1842 {
1843 // Quick hack, as iterators are pointers.
1844 iterator first_ = to_iterator(first);
1845 iterator last_ = to_iterator(last);
1846
1847 // Erase the bit we want to replace.
1848 erase(first_, last_);
1849
1850 // Insert the new stuff.
1851 insert(first_, s, s + etl::strlen(s));
1852
1853 return *this;
1854 }
1855
1856 //*********************************************************************
1858 //*********************************************************************
1859 ibasic_string& replace(size_type position, size_type length_, const_pointer s, size_type n)
1860 {
1861 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1862
1863 // Limit the length.
1864 length_ = etl::min(length_, size() - position);
1865
1866 // Erase the bit we want to replace.
1867 erase(position, length_);
1868
1869 // Insert the new stuff.
1870 insert(position, s, n);
1871
1872 return *this;
1873 }
1874
1875 //*********************************************************************
1877 //*********************************************************************
1878 ibasic_string& replace(const_iterator first, const_iterator last, const_pointer s, size_type n)
1879 {
1880 // Quick hack, as iterators are pointers.
1881 iterator first_ = to_iterator(first);
1882 iterator last_ = to_iterator(last);
1883
1884 // Erase the bit we want to replace.
1885 erase(first_, last_);
1886
1887 // Insert the new stuff.
1888 insert(first_, s, s + n);
1889
1890 return *this;
1891 }
1892
1893 //*********************************************************************
1895 //*********************************************************************
1896 ibasic_string& replace(size_type position, size_type length_, size_type n, value_type c)
1897 {
1898 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1899
1900 // Limit the length.
1901 length_ = etl::min(length_, size() - position);
1902
1903 // Erase the bit we want to replace.
1904 erase(position, length_);
1905
1906 // Insert the new stuff.
1907 insert(position, n, c);
1908
1909 return *this;
1910 }
1911
1912 //*********************************************************************
1914 //*********************************************************************
1915 ibasic_string& replace(const_iterator first, const_iterator last, size_type n, value_type c)
1916 {
1917 // Quick hack, as iterators are pointers.
1918 iterator first_ = to_iterator(first);
1919 iterator last_ = to_iterator(last);
1920
1921 // Erase the bit we want to replace.
1922 erase(first_, last_);
1923
1924 // Insert the new stuff.
1925 insert(first_, n, c);
1926
1927 return *this;
1928 }
1929
1930 //*********************************************************************
1932 //*********************************************************************
1933 template <typename TIterator>
1934 ibasic_string& replace(const_iterator first, const_iterator last, TIterator first_replace, TIterator last_replace)
1935 {
1936 // Quick hack, as iterators are pointers.
1937 iterator first_ = to_iterator(first);
1938 iterator last_ = to_iterator(last);
1939
1940 // Erase the bit we want to replace.
1941 erase(first_, last_);
1942
1943 // Insert the new stuff.
1945
1946 return *this;
1947 }
1948
1949 //*************************************************************************
1951 //*************************************************************************
1952 int compare(const ibasic_string& str) const
1953 {
1954 return compare(p_buffer,
1955 p_buffer + size(),
1956 str.p_buffer,
1957 str.p_buffer + str.size());
1958 }
1959
1960 //*************************************************************************
1962 //*************************************************************************
1963 template <typename TOtherTraits>
1965 {
1966 return compare(p_buffer,
1967 p_buffer + size(),
1968 view.data(),
1969 view.data() + view.size());
1970 }
1971
1972 //*************************************************************************
1974 //*************************************************************************
1975 int compare(size_type position, size_type length_, const ibasic_string& str) const
1976 {
1977 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1978
1979 // Limit the length.
1980 length_ = etl::min(length_, size() - position);
1981
1982 return compare(p_buffer + position,
1983 p_buffer + position + length_,
1984 str.p_buffer,
1985 str.p_buffer + str.size());
1986 }
1987
1988 //*************************************************************************
1990 //*************************************************************************
1991 template <typename TOtherTraits>
1992 int compare(size_type position, size_type length_, const etl::basic_string_view<T, TOtherTraits>& view) const
1993 {
1994 return compare(p_buffer + position,
1995 p_buffer + position + length_,
1996 view.data(),
1997 view.data() + view.size());
1998 }
1999
2000 //*************************************************************************
2002 //*************************************************************************
2003 int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const
2004 {
2005 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
2006 ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
2007
2008 // Limit the lengths.
2009 length_ = etl::min(length_, size() - position);
2010 sublength = etl::min(sublength, str.size() - subposition);
2011
2012 return compare(p_buffer + position,
2013 p_buffer + position + length_,
2014 str.p_buffer + subposition,
2015 str.p_buffer + subposition + sublength);
2016 }
2017
2018 //*************************************************************************
2020 //*************************************************************************
2021 template <typename TOtherTraits>
2022 int compare(size_type position, size_type length_, const etl::basic_string_view<T, TOtherTraits>& view, size_type subposition, size_type sublength) const
2023 {
2024 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
2025 ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
2026
2027 // Limit the lengths.
2028 length_ = etl::min(length_, size() - position);
2029 sublength = etl::min(sublength, view.size() - subposition);
2030
2031 return compare(p_buffer + position,
2032 p_buffer + position + length_,
2033 view.data() + subposition,
2034 view.data() + subposition + sublength);
2035 }
2036
2037 //*************************************************************************
2039 //*************************************************************************
2040 int compare(const value_type* s) const
2041 {
2042 return compare(p_buffer,
2043 p_buffer + size(),
2044 s,
2045 s + etl::strlen(s));
2046 }
2047
2048 //*************************************************************************
2050 //*************************************************************************
2051 int compare(size_type position, size_type length_, const_pointer s) const
2052 {
2053 return compare(p_buffer + position,
2054 p_buffer + position + length_,
2055 s,
2056 s + etl::strlen(s));
2057 }
2058
2059 //*************************************************************************
2061 //*************************************************************************
2062 int compare(size_type position, size_type length_, const_pointer s, size_type n) const
2063 {
2064 return compare(p_buffer + position,
2065 p_buffer + position + length_,
2066 s,
2067 s + n);
2068 }
2069
2070 //*********************************************************************
2074 //*********************************************************************
2075 size_type find_first_of(const ibasic_string<T>& str, size_type position = 0) const
2076 {
2077 return find_first_of(str.c_str(), position, str.size());
2078 }
2079
2080 //*********************************************************************
2084 //*********************************************************************
2085 size_type find_first_of(const_pointer s, size_type position = 0) const
2086 {
2087 return find_first_of(s, position, etl::strlen(s));
2088 }
2089
2090 //*********************************************************************
2094 //*********************************************************************
2095 template <typename TOtherTraits>
2096 size_type find_first_of(const etl::basic_string_view<T, TOtherTraits>& view, size_type position = 0) const
2097 {
2098 return find_first_of(view.data(), position, view.size());
2099 }
2100
2101 //*********************************************************************
2106 //*********************************************************************
2107 size_type find_first_of(const_pointer s, size_type position, size_type n) const
2108 {
2109 if (position < size())
2110 {
2111 for (size_type i = position; i < size(); ++i)
2112 {
2113 for (size_type j = 0; j < n; ++j)
2114 {
2115 if (p_buffer[i] == s[j])
2116 {
2117 return i;
2118 }
2119 }
2120 }
2121 }
2122
2123 return npos;
2124 }
2125
2126 //*********************************************************************
2130 //*********************************************************************
2131 size_type find_first_of(value_type c, size_type position = 0) const
2132 {
2133 if (position < size())
2134 {
2135 for (size_type i = position; i < size(); ++i)
2136 {
2137 if (p_buffer[i] == c)
2138 {
2139 return i;
2140 }
2141 }
2142 }
2143
2144 return npos;
2145 }
2146
2147 //*********************************************************************
2151 //*********************************************************************
2152 size_type find_last_of(const ibasic_string<T>& str, size_type position = npos) const
2153 {
2154 return find_last_of(str.c_str(), position, str.size());
2155 }
2156
2157 //*********************************************************************
2161 //*********************************************************************
2162 size_type find_last_of(const_pointer s, size_type position = npos) const
2163 {
2164 return find_last_of(s, position, etl::strlen(s));
2165 }
2166
2167 //*********************************************************************
2171 //*********************************************************************
2172 template <typename TOtherTraits>
2173 size_type find_last_of(const etl::basic_string_view<T, TOtherTraits>& view, size_type position = npos) const
2174 {
2175 return find_last_of(view.data(), position, view.size());
2176 }
2177
2178 //*********************************************************************
2183 //*********************************************************************
2184 size_type find_last_of(const_pointer s, size_type position, size_type n) const
2185 {
2186 if (empty())
2187 {
2188 return npos;
2189 }
2190
2191 position = etl::min(position, size() - 1);
2192
2193 const_reverse_iterator it = rbegin() + size() - position - 1;
2194
2195 while (it != rend())
2196 {
2197 for (size_type j = 0; j < n; ++j)
2198 {
2199 if (p_buffer[position] == s[j])
2200 {
2201 return position;
2202 }
2203 }
2204
2205 ++it;
2206 --position;
2207 }
2208
2209 return npos;
2210 }
2211
2212 //*********************************************************************
2216 //*********************************************************************
2217 size_type find_last_of(value_type c, size_type position = npos) const
2218 {
2219 if (empty())
2220 {
2221 return npos;
2222 }
2223
2224 position = etl::min(position, size() - 1);
2225
2226 const_reverse_iterator it = rbegin() + size() - position - 1;
2227
2228 while (it != rend())
2229 {
2230 if (p_buffer[position] == c)
2231 {
2232 return position;
2233 }
2234
2235 ++it;
2236 --position;
2237 }
2238
2239 return npos;
2240 }
2241
2242 //*********************************************************************
2246 //*********************************************************************
2247 size_type find_first_not_of(const ibasic_string<T>& str, size_type position = 0) const
2248 {
2249 return find_first_not_of(str.c_str(), position, str.size());
2250 }
2251
2252 //*********************************************************************
2256 //*********************************************************************
2257 size_type find_first_not_of(const_pointer s, size_type position = 0) const
2258 {
2259 return find_first_not_of(s, position, etl::strlen(s));
2260 }
2261
2262 //*********************************************************************
2266 //*********************************************************************
2267 template <typename TOtherTraits>
2268 size_type find_first_not_of(const etl::basic_string_view<T, TOtherTraits>& view, size_type position = 0) const
2269 {
2270 return find_first_not_of(view.data(), position, view.size());
2271 }
2272
2273 //*********************************************************************
2278 //*********************************************************************
2279 size_type find_first_not_of(const_pointer s, size_type position, size_type n) const
2280 {
2281 if (position < size())
2282 {
2283 for (size_type i = position; i < size(); ++i)
2284 {
2285 bool found = false;
2286
2287 for (size_type j = 0; j < n; ++j)
2288 {
2289 if (p_buffer[i] == s[j])
2290 {
2291 found = true;
2292 }
2293 }
2294
2295 if (!found)
2296 {
2297 return i;
2298 }
2299 }
2300 }
2301
2302 return npos;
2303 }
2304
2305 //*********************************************************************
2309 //*********************************************************************
2310 size_type find_first_not_of(value_type c, size_type position = 0) const
2311 {
2312 if (position < size())
2313 {
2314 for (size_type i = position; i < size(); ++i)
2315 {
2316 if (*(p_buffer + i) != c)
2317 {
2318 return i;
2319 }
2320 }
2321 }
2322
2323 return npos;
2324 }
2325
2326 //*********************************************************************
2330 //*********************************************************************
2331 size_type find_last_not_of(const ibasic_string<T>& str, size_type position = npos) const
2332 {
2333 return find_last_not_of(str.c_str(), position, str.size());
2334 }
2335
2336 //*********************************************************************
2340 //*********************************************************************
2341 size_type find_last_not_of(const_pointer s, size_type position = npos) const
2342 {
2343 return find_last_not_of(s, position, etl::strlen(s));
2344 }
2345
2346 //*********************************************************************
2350 //*********************************************************************
2351 template <typename TOtherTraits>
2352 size_type find_last_not_of(const etl::basic_string_view<T, TOtherTraits>& view, size_type position = npos) const
2353 {
2354 return find_last_not_of(view.data(), position, view.size());
2355 }
2356
2357 //*********************************************************************
2362 //*********************************************************************
2363 size_type find_last_not_of(const_pointer s, size_type position, size_type n) const
2364 {
2365 if (empty())
2366 {
2367 return npos;
2368 }
2369
2370 position = etl::min(position, size() - 1);
2371
2372 const_reverse_iterator it = rbegin() + size() - position - 1;
2373
2374 while (it != rend())
2375 {
2376 bool found = false;
2377
2378 for (size_type j = 0; j < n; ++j)
2379 {
2380 if (p_buffer[position] == s[j])
2381 {
2382 found = true;
2383 }
2384 }
2385
2386 if (!found)
2387 {
2388 return position;
2389 }
2390
2391 ++it;
2392 --position;
2393 }
2394
2395 return npos;
2396 }
2397
2398 //*********************************************************************
2399 //
2400 //*********************************************************************
2401 size_type find_last_not_of(value_type c, size_type position = npos) const
2402 {
2403 if (empty())
2404 {
2405 return npos;
2406 }
2407
2408 position = etl::min(position, size() - 1);
2409
2410 const_reverse_iterator it = rbegin() + size() - position - 1;
2411
2412 while (it != rend())
2413 {
2414 if (p_buffer[position] != c)
2415 {
2416 return position;
2417 }
2418
2419 ++it;
2420 --position;
2421 }
2422
2423 return npos;
2424 }
2425
2426 //*************************************************************************
2428 //*************************************************************************
2430 {
2431 if (&rhs != this)
2432 {
2433 assign(rhs);
2434 }
2435
2436 return *this;
2437 }
2438
2439 //*************************************************************************
2441 //*************************************************************************
2443 {
2444 assign(rhs);
2445
2446 return *this;
2447 }
2448
2449 //*************************************************************************
2451 //*************************************************************************
2452 template <typename TOtherTraits>
2454 {
2455 assign(view);
2456
2457 return *this;
2458 }
2459
2460 //*************************************************************************
2462 //*************************************************************************
2464 {
2465 append(rhs);
2466
2467 return *this;
2468 }
2469
2470 //*************************************************************************
2472 //*************************************************************************
2473 template <typename TOtherTraits>
2475 {
2476 append(rhs);
2477
2478 return *this;
2479 }
2480
2481 //*************************************************************************
2483 //*************************************************************************
2485 {
2486 append(rhs);
2487
2488 return *this;
2489 }
2490
2491 //*************************************************************************
2493 //*************************************************************************
2495 {
2496 append(size_type(1), rhs);
2497
2498 return *this;
2499 }
2500
2501#if ETL_HAS_ISTRING_REPAIR
2502 //*************************************************************************
2504 //*************************************************************************
2505 virtual void repair() = 0;
2506#endif
2507
2508 //*********************************************************************
2510 //*********************************************************************
2512 {
2513#if ETL_HAS_STRING_TRUNCATION_CHECKS
2514 set_truncated(false);
2515#endif
2516 etl::mem_set(&p_buffer[current_size], &p_buffer[CAPACITY + 1U], char(0));
2517 }
2518
2519 //*********************************************************************
2523 //*********************************************************************
2525 {
2526#if ETL_HAS_STRING_TRUNCATION_CHECKS
2527 set_truncated(p_buffer[CAPACITY] != T(0));
2528#endif
2529
2530 p_buffer[CAPACITY] = T(0); // Ensure a terminating null.
2531 current_size = etl::strlen(p_buffer);
2532 }
2533
2534 protected:
2535
2536 //*********************************************************************
2538 //*********************************************************************
2541 p_buffer(p_buffer_)
2542 {
2543 }
2544
2545 //*********************************************************************
2547 //*********************************************************************
2549 {
2550 current_size = 0U;
2551 p_buffer[0] = 0;
2552#if ETL_HAS_STRING_TRUNCATION_CHECKS
2553 set_truncated(false);
2554#endif
2555 }
2556
2557 //*************************************************************************
2559 //*************************************************************************
2561 {
2562 p_buffer = p_buffer_;
2563 }
2564
2565 private:
2566
2567 //*************************************************************************
2569 //*************************************************************************
2570 static int compare(const_pointer first1, const_pointer last1,
2571 const_pointer first2, const_pointer last2)
2572 {
2573 typedef typename etl::make_unsigned<value_type>::type type;
2574
2575 difference_type length1 = etl::distance(first1, last1);
2576 difference_type length2 = etl::distance(first2, last2);
2577 difference_type compare_length = etl::min(length1, length2);
2578
2579 // First compare the string characters.
2580 while (compare_length != 0)
2581 {
2582 if (static_cast<type>(*first1) < static_cast<type>(*first2))
2583 {
2584 // Compared character is lower.
2585 return -1;
2586 }
2587 else if (static_cast<type>(*first1) > static_cast<type>(*first2))
2588 {
2589 // Compared character is higher.
2590 return 1;
2591 }
2592
2593 ++first1;
2594 ++first2;
2596 }
2597
2598 // Then compare the string lengths.
2599 if (length1 < length2)
2600 {
2601 // First string is shorter.
2602 return -1;
2603 }
2604
2605 if (length1 > length2)
2606 {
2607 // First string is longer.
2608 return 1;
2609 }
2610
2611 // Strings are the same length.
2612 return 0;
2613 }
2614
2615 //*************************************************************************
2617 //*************************************************************************
2618 void cleanup()
2619 {
2620#if ETL_HAS_STRING_CLEAR_AFTER_USE
2621 if (is_secure())
2622 {
2623 etl::memory_clear_range(&p_buffer[current_size], &p_buffer[CAPACITY]);
2624 }
2625#endif
2626 }
2627
2628 //*************************************************************************
2630 //*************************************************************************
2631 ibasic_string(const ibasic_string&);
2632
2633 //*************************************************************************
2635 //*************************************************************************
2636 T* p_buffer;
2637
2638 //*************************************************************************
2640 //*************************************************************************
2641#if defined(ETL_POLYMORPHIC_STRINGS) || defined(ETL_POLYMORPHIC_CONTAINERS) || defined(ETL_ISTRING_REPAIR_ENABLE)
2642 public:
2643 virtual
2644#else
2645 protected:
2646#endif
2648 {
2649#if ETL_HAS_STRING_CLEAR_AFTER_USE
2650 if (is_secure())
2651 {
2652 clear();
2653 }
2654#endif
2655 }
2656
2657 protected:
2658
2659 //*************************************************************************
2661 //*************************************************************************
2662 iterator to_iterator(const_iterator itr) const
2663 {
2664 return const_cast<iterator>(itr);
2665 }
2666
2667 private:
2668
2669 //*********************************************************************
2672 //*********************************************************************
2673 template <typename TIterator1, typename TIterator2>
2674 static
2676 copy_characters(TIterator1 from, size_t n, TIterator2 to)
2677 {
2678 etl::mem_move(from, n, to);
2679
2680 return to + n;
2681 }
2682
2683 //*********************************************************************
2686 //*********************************************************************
2687 template <typename TIterator1, typename TIterator2>
2688 static
2690 copy_characters(TIterator1 from, size_t n, TIterator2 to)
2691 {
2692 size_t count = 0;
2693
2694 while (count != n)
2695 {
2696 *to++ = *from++;
2697 ++count;
2698 }
2699
2700 return to;
2701 }
2702
2703 //*********************************************************************
2705 //*********************************************************************
2706 template <typename TIterator>
2707 void append_impl(iterator position, TIterator first, TIterator last, bool truncated, bool secure)
2708 {
2709 difference_type start = etl::distance(p_buffer, position);
2710 difference_type count = etl::distance(first, last);
2711 difference_type free_space = etl::distance(position, p_buffer + CAPACITY);
2712
2713#if ETL_IS_DEBUG_BUILD
2714 ETL_ASSERT(count >= 0, ETL_ERROR(string_iterator));
2715#endif
2716
2717#if ETL_HAS_STRING_TRUNCATION_CHECKS
2718 set_truncated((count > free_space) || this->is_truncated() || truncated);
2719
2720#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
2721 ETL_ASSERT(is_truncated == false, ETL_ERROR(string_truncation));
2722#endif
2723#endif
2724
2725#if ETL_HAS_STRING_CLEAR_AFTER_USE
2726 if (secure)
2727 {
2728 set_secure();
2729 }
2730#endif
2731
2732 // Limit the actual distance to the capacity.
2733 count = etl::min(count, free_space);
2734 copy_characters(first, size_t(count), position);
2735 current_size = size_t(start + count);
2736 p_buffer[current_size] = 0;
2737
2738 cleanup();
2739 }
2740
2741 //*********************************************************************
2743 //*********************************************************************
2744 void append_impl(iterator position, const_pointer src, bool truncated, bool secure)
2745 {
2746 if (src == ETL_NULLPTR)
2747 {
2748 clear();
2749 return;
2750 }
2751
2752 difference_type start = etl::distance(p_buffer, position);
2753 difference_type free_space = etl::distance(position, p_buffer + CAPACITY);
2754
2755 pointer dst = position;
2756 size_t length = get_string_length(src);
2757 size_t count = (length < size_t(free_space)) ? length : size_t(free_space);
2758 etl::mem_move(src, count, dst);
2759
2760 truncated |= (src[count] != 0);
2761 current_size = size_t(start) + count;
2762 p_buffer[current_size] = 0;
2763
2764#if ETL_HAS_STRING_TRUNCATION_CHECKS
2766#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
2767 ETL_ASSERT(is_truncated == false, ETL_ERROR(string_truncation));
2768#endif
2769#endif
2770
2771#if ETL_HAS_STRING_CLEAR_AFTER_USE
2772 if (secure)
2773 {
2774 set_secure();
2775 }
2776#endif
2777
2778 cleanup();
2779 }
2780
2781 //*************************************************************************
2783 //*************************************************************************
2784 template <typename TIterator>
2785 size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const
2786 {
2787 if ((pos + sz) > size())
2788 {
2789 return npos;
2790 }
2791
2792 const_iterator iposition = etl::search(begin() + pos, end(), first, last);
2793
2794 if (iposition == end())
2795 {
2796 return npos;
2797 }
2798 else
2799 {
2800 return etl::distance(begin(), iposition);
2801 }
2802 }
2803
2804 //*************************************************************************
2806 //*************************************************************************
2807 template <typename TIterator>
2808 size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const
2809 {
2810 if (sz > size())
2811 {
2812 return npos;
2813 }
2814
2815 if (pos >= size())
2816 {
2817 pos = size();
2818 }
2819
2820 pos = size() - pos;
2821
2822 const_reverse_iterator iposition = etl::search(rbegin() + pos, rend(), rfirst, rlast);
2823
2824 if (iposition == rend())
2825 {
2826 return npos;
2827 }
2828 else
2829 {
2830 return size() - sz - etl::distance(rbegin(), iposition);
2831 }
2832 }
2833
2834 //*********************************************************************
2836 //*********************************************************************
2837 template <typename U>
2838 static
2839 typename etl::enable_if<sizeof(U) == sizeof(char), size_t>::type
2840 get_string_length(const U* str)
2841 {
2842 return ::strlen(reinterpret_cast<const char*>(str));
2843 }
2844
2845#if ETL_USING_LIBC_WCHAR_H
2846 //*********************************************************************
2848 //*********************************************************************
2849 template <typename U>
2850 static
2851 typename etl::enable_if<sizeof(U) == sizeof(wchar_t), size_t>::type
2852 get_string_length(const U* str)
2853 {
2854 return ::wcslen(reinterpret_cast<const wchar_t*>(str));
2855 }
2856#endif
2857
2858 //*********************************************************************
2860 //*********************************************************************
2861 template <typename U>
2862 static
2863#if ETL_USING_LIBC_WCHAR_H
2864 typename etl::enable_if<(sizeof(U) != sizeof(char)) && (sizeof(U) != sizeof(wchar_t)), size_t>::type
2865#else
2866 typename etl::enable_if<(sizeof(U) != sizeof(char)), size_t>::type
2867#endif
2868 get_string_length(const U* str)
2869 {
2870 if (str == ETL_NULLPTR)
2871 {
2872 return 0;
2873 }
2874
2875 const U* end = str;
2876
2877 while (*end++ != 0)
2878 {
2879 // Do nothing.
2880 }
2881
2882 return size_t(end - str) - 1;
2883 }
2884 };
2885
2886 //***************************************************************************
2892 //***************************************************************************
2893 template <typename T>
2895 {
2896 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
2897 }
2898
2899 //***************************************************************************
2905 //***************************************************************************
2906 template <typename T>
2908 {
2909 return (lhs.size() == etl::strlen(rhs)) && etl::equal(lhs.begin(), lhs.end(), rhs);
2910 }
2911
2912 //***************************************************************************
2918 //***************************************************************************
2919 template <typename T>
2921 {
2922 return (rhs.size() == etl::strlen(lhs)) && etl::equal(rhs.begin(), rhs.end(), lhs);
2923 }
2924
2925 //***************************************************************************
2931 //***************************************************************************
2932 template <typename T>
2934 {
2935 return !(lhs == rhs);
2936 }
2937
2938 //***************************************************************************
2944 //***************************************************************************
2945 template <typename T>
2947 {
2948 return !(lhs == rhs);
2949 }
2950
2951 //***************************************************************************
2957 //***************************************************************************
2958 template <typename T>
2960 {
2961 return !(lhs == rhs);
2962 }
2963
2964 //***************************************************************************
2970 //***************************************************************************
2971 template <typename T>
2973 {
2974 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
2975 }
2976
2977 //***************************************************************************
2983 //***************************************************************************
2984 template <typename T>
2986 {
2987 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs, rhs + etl::strlen(rhs));
2988 }
2989
2990 //***************************************************************************
2996 //***************************************************************************
2997 template <typename T>
2999 {
3000 return etl::lexicographical_compare(lhs, lhs + etl::strlen(lhs), rhs.begin(), rhs.end());
3001 }
3002
3003
3004 //***************************************************************************
3010 //***************************************************************************
3011 template <typename T>
3013 {
3014 return (rhs < lhs);
3015 }
3016
3017 //***************************************************************************
3023 //***************************************************************************
3024 template <typename T>
3026 {
3027 return (rhs < lhs);
3028 }
3029
3030 //***************************************************************************
3036 //***************************************************************************
3037 template <typename T>
3039 {
3040 return (rhs < lhs);
3041 }
3042
3043
3044 //***************************************************************************
3050 //***************************************************************************
3051 template <typename T>
3053 {
3054 return !(lhs > rhs);
3055 }
3056
3057 //***************************************************************************
3063 //***************************************************************************
3064 template <typename T>
3066 {
3067 return !(lhs > rhs);
3068 }
3069
3070 //***************************************************************************
3076 //***************************************************************************
3077 template <typename T>
3079 {
3080 return !(lhs > rhs);
3081 }
3082
3083
3084 //***************************************************************************
3090 //***************************************************************************
3091 template <typename T>
3093 {
3094 return !(lhs < rhs);
3095 }
3096
3097 //***************************************************************************
3103 //***************************************************************************
3104 template <typename T>
3106 {
3107 return !(lhs < rhs);
3108 }
3109
3110 //***************************************************************************
3116 //***************************************************************************
3117 template <typename T>
3119 {
3120 return !(lhs < rhs);
3121 }
3122
3123 //***************************************************************************
3129 //***************************************************************************
3130#if ETL_USING_STL
3131 template <typename T>
3132 std::basic_ostream<T, std::char_traits<T> > &operator<<(std::basic_ostream<T, std::char_traits<T> > &os,
3133 const etl::ibasic_string<T>& str)
3134 {
3135 os.write(str.data(), str.size());
3136 return os;
3137 }
3138#endif
3139}
3140
3141#undef ETL_USING_WCHAR_T_H
3142
3143#include "private/minmax_pop.h"
3144
3145#endif
String view.
Definition string_view.h:104
Definition flags.h:53
ETL_CONSTEXPR14 flags< T, MASK > & set() ETL_NOEXCEPT
Set the bits.
Definition flags.h:102
ETL_CONSTEXPR bool test() const ETL_NOEXCEPT
Tests bits.
Definition flags.h:87
Definition basic_string.h:351
int compare(size_type position, size_type length_, const ibasic_string &str) const
Compare position / length with string.
Definition basic_string.h:1975
ibasic_string & append(TIterator first, TIterator last)
Definition basic_string.h:857
size_type find_last_of(const_pointer s, size_type position=npos) const
Definition basic_string.h:2162
size_type rfind(const_pointer s, size_type position=npos) const
Definition basic_string.h:1499
ibasic_string & replace(const_iterator first, const_iterator last, const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:1750
etl::ibasic_string< T > & insert(size_type position, const etl::ibasic_string< T > &str)
Definition basic_string.h:1167
size_type find_last_not_of(const_pointer s, size_type position=npos) const
Definition basic_string.h:2341
size_type find(const_pointer s, size_type pos=0) const
Definition basic_string.h:1434
ibasic_string & operator=(const ibasic_string &rhs)
Assignment operator.
Definition basic_string.h:2429
ibasic_string & append(const ibasic_string &str, size_type subposition, size_type sublength=npos)
Definition basic_string.h:837
const_reverse_iterator rbegin() const
Definition basic_string.h:435
bool contains(const etl::ibasic_string< T > &str) const
Checks that the string is within this string.
Definition basic_string.h:1551
reference operator[](size_type i)
Definition basic_string.h:561
void assign(const etl::ibasic_string< T > &other, size_type subposition, size_type sublength)
Definition basic_string.h:692
etl::ibasic_string< T > & insert(size_type position, const etl::basic_string_view< T, TOtherTraits > &view, size_type subposition, size_type sublength)
Definition basic_string.h:1243
pointer data_end()
Definition basic_string.h:658
iterator erase(const_iterator first, const_iterator last)
Definition basic_string.h:1351
iterator insert(const_iterator position, TIterator first, TIterator last)
Definition basic_string.h:1069
bool contains(value_type c) const
Checks that character is within this string.
Definition basic_string.h:1576
size_type find_last_of(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:2152
size_type find_first_of(value_type c, size_type position=0) const
Definition basic_string.h:2131
bool starts_with(const etl::ibasic_string< T > &str) const
Checks that the string is the start of this string.
Definition basic_string.h:1584
size_type find(T c, size_type position=0) const
Definition basic_string.h:1459
ibasic_string & replace(size_type position, size_type length_, const etl::basic_string_view< T, TOtherTraits > &view, size_type subposition, size_type sublength)
Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'.
Definition basic_string.h:1801
bool ends_with(value_type c) const
Checks that the character is the end of this string.
Definition basic_string.h:1661
void pop_back()
Definition basic_string.h:812
size_type rfind(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:1478
bool contains(const_pointer s) const
Checks that text is within this string.
Definition basic_string.h:1568
etl::ibasic_string< T > & insert(size_type position, const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:1193
void resize_and_overwrite(size_type new_size, TOperation operation)
Resizes the string and overwrites to data using the operation.
Definition basic_string.h:521
void initialize_free_space()
Clears the free space to string terminator value.
Definition basic_string.h:2511
ibasic_string & replace(size_type position, size_type length_, const_pointer s, size_type n)
Replace characters from 'position' of 'length' with 'n' characters from pointed to string.
Definition basic_string.h:1859
iterator to_iterator(const_iterator itr) const
Convert from const_iterator to iterator.
Definition basic_string.h:2662
ibasic_string & replace(size_type position, size_type length_, size_type n, value_type c)
Replace characters from 'position' of 'length' with 'n' copies of 'c'.
Definition basic_string.h:1896
ibasic_string & replace(const_iterator first, const_iterator last, const ibasic_string &str)
Definition basic_string.h:1717
size_type find_first_of(const ibasic_string< T > &str, size_type position=0) const
Definition basic_string.h:2075
size_type find_first_of(const etl::basic_string_view< T, TOtherTraits > &view, size_type position=0) const
Definition basic_string.h:2096
const_reference back() const
Definition basic_string.h:631
void assign(const_pointer str, size_type n)
Definition basic_string.h:736
const_iterator begin() const
Definition basic_string.h:381
size_type find_last_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2184
bool ends_with(const etl::basic_string_view< T, TOtherTraits > &view) const
Checks that the view is the end of this string.
Definition basic_string.h:1633
reverse_iterator rbegin()
Definition basic_string.h:426
ibasic_string & replace(const_iterator first, const_iterator last, TIterator first_replace, TIterator last_replace)
Replace characters from 'first' of 'last' with characters from 'first_replace' to 'last_replace'.
Definition basic_string.h:1934
void resize(size_type new_size)
Definition basic_string.h:481
size_type find_last_not_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2363
ibasic_string & replace(size_type position, size_type length_, const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:1695
size_type find_first_not_of(const_pointer s, size_type position=0) const
Definition basic_string.h:2257
size_type rfind(T c, size_type position=npos) const
Definition basic_string.h:1527
etl::ibasic_string< T > & erase(size_type position, size_type length_=npos)
Definition basic_string.h:1305
int compare(const value_type *s) const
Compare with C string.
Definition basic_string.h:2040
int compare(size_type position, size_type length_, const_pointer s) const
Compare position / length with C string.
Definition basic_string.h:2051
iterator insert(const_iterator position, size_type n, T value)
Definition basic_string.h:982
ibasic_string & append(const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:892
const_reference at(size_type i) const
Definition basic_string.h:594
void assign(const etl::basic_string_view< T, TOtherTraits > &view)
Assigns values to the string from a view.
Definition basic_string.h:745
void clear()
Clears the string.
Definition basic_string.h:778
int compare(size_type position, size_type length_, const ibasic_string &str, size_type subposition, size_type sublength) const
Compare position / length with string / subposition / sublength.
Definition basic_string.h:2003
reverse_iterator rend()
Definition basic_string.h:444
size_type find_last_of(const etl::basic_string_view< T, TOtherTraits > &view, size_type position=npos) const
Definition basic_string.h:2173
iterator erase(iterator i_element)
Definition basic_string.h:1320
ibasic_string & append(const_pointer str, size_type n)
Definition basic_string.h:880
const_reverse_iterator crend() const
Definition basic_string.h:471
bool contains(const etl::basic_string_view< T, TOtherTraits > &view) const
Checks that the view is within this string.
Definition basic_string.h:1560
reference at(size_type i)
Definition basic_string.h:582
size_type rfind(const etl::basic_string_view< T, TOtherTraits > &view, size_type pos=0) const
Definition basic_string.h:1489
bool starts_with(value_type c) const
Checks that the character is the start of this string.
Definition basic_string.h:1611
int compare(const etl::basic_string_view< T, TOtherTraits > &view) const
Compare with etl::basic_string_view.
Definition basic_string.h:1964
~ibasic_string()
Destructor.
Definition basic_string.h:2647
ibasic_string & replace(const_iterator first, const_iterator last, const_pointer s)
Replace characters from 'first' 'last' with pointed to string.
Definition basic_string.h:1841
size_type find(const_pointer s, size_type pos, size_type n) const
Definition basic_string.h:1447
size_type find_first_of(const_pointer s, size_type position=0) const
Definition basic_string.h:2085
ibasic_string & replace(size_type position, size_type length_, const ibasic_string &str, size_type subposition, size_type sublength)
Replace characters from 'position' of 'length' with 'str' from 'subposition' of 'sublength'.
Definition basic_string.h:1768
iterator begin()
Definition basic_string.h:372
iterator end()
Definition basic_string.h:390
ibasic_string & replace(const_iterator first, const_iterator last, size_type n, value_type c)
Replace characters from 'first' of 'last' with 'n' copies of 'c'.
Definition basic_string.h:1915
ibasic_string & replace(const_iterator first, const_iterator last, const_pointer s, size_type n)
Replace characters from 'first' to 'last' with 'n' characters from pointed to string.
Definition basic_string.h:1878
void assign(TIterator first, TIterator last)
Definition basic_string.h:715
etl::ibasic_string< T > & insert(size_type position, const etl::ibasic_string< T > &str, size_type subposition, size_type sublength)
Definition basic_string.h:1209
size_type find(const ibasic_string< T > &str, size_type pos=0) const
Definition basic_string.h:1413
void push_back(T value)
Definition basic_string.h:789
size_type find_first_not_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2279
const_reverse_iterator crbegin() const
Definition basic_string.h:462
iterator insert(const_iterator position, T value)
Definition basic_string.h:930
etl::ibasic_string< T > & insert(size_type position, const_pointer s, size_type n)
Definition basic_string.h:1277
ibasic_string & replace(size_type position, size_type length_, const ibasic_string &str)
Definition basic_string.h:1672
ibasic_string(T *p_buffer_, size_type MAX_SIZE_)
Constructor.
Definition basic_string.h:2539
bool ends_with(const_pointer s) const
Checks that the string is the end of this string.
Definition basic_string.h:1646
etl::ibasic_string< T > & insert(size_type position, size_type n, value_type c)
Definition basic_string.h:1291
const_reverse_iterator rend() const
Definition basic_string.h:453
size_type find_last_not_of(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:2331
size_type find(const etl::basic_string_view< T, TOtherTraits > &view, size_type pos=0) const
Definition basic_string.h:1424
const_pointer data_end() const
Definition basic_string.h:667
void assign(const etl::ibasic_string< T > &other)
Definition basic_string.h:677
const_iterator cend() const
Definition basic_string.h:417
const_pointer c_str() const
Return a pointer to a C string.
Definition basic_string.h:1374
void resize(size_type new_size, T value)
Definition basic_string.h:491
ETL_CONSTEXPR const_pointer data() const
Definition basic_string.h:649
const_reference front() const
Definition basic_string.h:613
pointer data()
Definition basic_string.h:640
size_type find_first_not_of(value_type c, size_type position=0) const
Definition basic_string.h:2310
ibasic_string & append(const_pointer str)
Definition basic_string.h:868
ibasic_string & append(size_type n, T c)
Definition basic_string.h:904
size_type find_first_not_of(const ibasic_string< T > &str, size_type position=0) const
Definition basic_string.h:2247
size_type find_last_of(value_type c, size_type position=npos) const
Definition basic_string.h:2217
size_type copy(pointer dest, size_type count, size_type pos=0) const
Definition basic_string.h:1385
ibasic_string & append(const ibasic_string &str)
Definition basic_string.h:824
size_type find_last_not_of(const etl::basic_string_view< T, TOtherTraits > &view, size_type position=npos) const
Definition basic_string.h:2352
ibasic_string & replace(size_type position, size_type length_, const_pointer s)
Replace characters from 'position' of 'length' with pointed to string.
Definition basic_string.h:1822
reference front()
Definition basic_string.h:604
reference back()
Definition basic_string.h:622
bool starts_with(const_pointer s) const
Checks that the string is the start of this string.
Definition basic_string.h:1601
const_iterator cbegin() const
Definition basic_string.h:408
size_type find_first_not_of(const etl::basic_string_view< T, TOtherTraits > &view, size_type position=0) const
Definition basic_string.h:2268
int compare(size_type position, size_type length_, const etl::basic_string_view< T, TOtherTraits > &view, size_type subposition, size_type sublength) const
Compare position / length with etl::basic_string_view. / subposition / sublength.
Definition basic_string.h:2022
void assign(size_type n, T c)
Definition basic_string.h:756
void initialise()
Initialise the string.
Definition basic_string.h:2548
bool starts_with(const etl::basic_string_view< T, TOtherTraits > &view) const
Checks that the view is the start of this string.
Definition basic_string.h:1593
ibasic_string & operator+=(const ibasic_string &rhs)
+= operator.
Definition basic_string.h:2463
void trim_to_terminator()
Definition basic_string.h:2524
void uninitialized_resize(size_type new_size)
Definition basic_string.h:538
int compare(size_type position, size_type length_, const_pointer s, size_type n) const
Compare position / length with C string / n.
Definition basic_string.h:2062
size_type rfind(const_pointer s, size_type position, size_type length_) const
Definition basic_string.h:1514
bool ends_with(const etl::ibasic_string< T > &str) const
Checks that the string is the end of this string.
Definition basic_string.h:1619
size_type find_first_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2107
int compare(const ibasic_string &str) const
Compare with string.
Definition basic_string.h:1952
const_iterator end() const
Definition basic_string.h:399
iterator erase(const_iterator i_element)
Definition basic_string.h:1333
int compare(size_type position, size_type length_, const etl::basic_string_view< T, TOtherTraits > &view) const
Compare position / length with etl::basic_string_view.
Definition basic_string.h:1992
etl::ibasic_string< T > & insert(size_type position, const_pointer s)
Definition basic_string.h:1263
void assign(const_pointer str)
Definition basic_string.h:725
void fill(T value)
Definition basic_string.h:551
void repair_buffer(T *p_buffer_)
Fix the internal pointers after a low level memory copy.
Definition basic_string.h:2560
iterator insert(const_iterator position, const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:1157
Definition basic_string.h:184
void set_secure()
Sets the 'secure' flag to the requested state.
Definition basic_string.h:290
bool is_secure() const
Gets the 'secure' state flag.
Definition basic_string.h:299
const size_type CAPACITY
The maximum number of elements in the string.
Definition basic_string.h:337
bool full() const
Definition basic_string.h:220
~string_base()
Destructor.
Definition basic_string.h:332
ETL_DEPRECATED bool truncated() const
Definition basic_string.h:271
void set_truncated(bool status)
Sets the 'truncated' flag.
Definition basic_string.h:323
size_type max_size() const
Definition basic_string.h:238
string_base(size_type max_size_)
Constructor.
Definition basic_string.h:313
void clear_truncated()
Clears the 'truncated' flag.
Definition basic_string.h:280
size_type length() const
Definition basic_string.h:202
size_type current_size
The current number of elements in the string.
Definition basic_string.h:336
size_type available() const
Definition basic_string.h:247
bool empty() const
Definition basic_string.h:211
size_type capacity() const
Definition basic_string.h:229
bool is_truncated() const
Definition basic_string.h:256
size_type size() const
Definition basic_string.h:193
Definition basic_string.h:101
Definition basic_string.h:87
Definition basic_string.h:129
Definition basic_string.h:115
Definition basic_string.h:143
Definition binary.h:354
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
Definition integral_limits.h:516
enable_if
Definition type_traits_generator.h:1230
is_pointer
Definition type_traits_generator.h:1140
make_unsigned
Definition type_traits_generator.h:1220
bitset_ext
Definition absolute.h:38
std::basic_ostream< T, std::char_traits< T > > & operator<<(std::basic_ostream< T, std::char_traits< T > > &os, const etl::ibasic_string< T > &str)
Definition basic_string.h:3132
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1148
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1160
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1109
ETL_CONSTEXPR14 size_t strlen(const T *t)
Alternative strlen for all character types.
Definition char_traits.h:287
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1097
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1121
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1136
Definition compare.h:51