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 "char_traits.h"
39#include "alignment.h"
40#include "array.h"
41#include "algorithm.h"
42#include "type_traits.h"
43#include "error_handler.h"
44#include "integral_limits.h"
45#include "exception.h"
46#include "memory.h"
47#include "exception.h"
48#include "binary.h"
49#include "flags.h"
50
51#include <stddef.h>
52#include <stdint.h>
53#include <string.h>
54
55#include "private/minmax_push.h"
56
57//*****************************************************************************
61//*****************************************************************************
62
63namespace etl
64{
65 //***************************************************************************
68 //***************************************************************************
78
79 //***************************************************************************
82 //***************************************************************************
84 {
85 public:
86
88 : string_exception(ETL_ERROR_TEXT("string:empty", ETL_BASIC_STRING_FILE_ID"A"), file_name_, line_number_)
89 {
90 }
91 };
92
93 //***************************************************************************
96 //***************************************************************************
98 {
99 public:
100
102 : string_exception(ETL_ERROR_TEXT("string:bounds", ETL_BASIC_STRING_FILE_ID"B"), file_name_, line_number_)
103 {
104 }
105 };
106
107 //***************************************************************************
110 //***************************************************************************
112 {
113 public:
114
116 : string_exception(ETL_ERROR_TEXT("string:iterator", ETL_BASIC_STRING_FILE_ID"C"), file_name_, line_number_)
117 {
118 }
119 };
120
121 //***************************************************************************
124 //***************************************************************************
126 {
127 public:
128
130 : string_exception(ETL_ERROR_TEXT("string:iterator", ETL_BASIC_STRING_FILE_ID"D"), file_name_, line_number_)
131 {
132 }
133 };
134
135 //***************************************************************************
138 //***************************************************************************
139 namespace private_basic_string
140 {
141 //*************************************************************************
142 template <typename T = void>
144 {
145 public:
146
147 typedef size_t size_type;
148
149 static ETL_CONSTANT uint_least8_t IS_TRUNCATED = etl::bit<0>::value;
150 static ETL_CONSTANT uint_least8_t CLEAR_AFTER_USE = etl::bit<1>::value;
151
152 static ETL_CONSTANT size_type npos = etl::integral_limits<size_type>::max;
153 };
154
155 template <typename T>
157
158 template <typename T>
160
161 template <typename T>
163 }
164
165 //***************************************************************************
167 {
168 public:
169
170 typedef size_t size_type;
171
172 //*************************************************************************
175 //*************************************************************************
176 size_type size() const
177 {
178 return current_size;
179 }
180
181 //*************************************************************************
184 //*************************************************************************
185 size_type length() const
186 {
187 return current_size;
188 }
189
190 //*************************************************************************
193 //*************************************************************************
194 bool empty() const
195 {
196 return (current_size == 0);
197 }
198
199 //*************************************************************************
202 //*************************************************************************
203 bool full() const
204 {
205 return current_size == CAPACITY;
206 }
207
208 //*************************************************************************
211 //*************************************************************************
212 size_type capacity() const
213 {
214 return CAPACITY;
215 }
216
217 //*************************************************************************
220 //*************************************************************************
221 size_type max_size() const
222 {
223 return CAPACITY;
224 }
225
226 //*************************************************************************
229 //*************************************************************************
230 size_type available() const
231 {
232 return max_size() - size();
233 }
234
235#if ETL_HAS_STRING_TRUNCATION_CHECKS
236 //*************************************************************************
240 //*************************************************************************
241 ETL_DEPRECATED
242 bool truncated() const
243 {
244 return flags.test<IS_TRUNCATED>();
245 }
246
247 //*************************************************************************
250 //*************************************************************************
251 bool is_truncated() const
252 {
253 return flags.test<IS_TRUNCATED>();
254 }
255
256 //*************************************************************************
258 //*************************************************************************
260 {
261 flags.set<IS_TRUNCATED, false>();
262 }
263#endif
264
265#if ETL_HAS_STRING_CLEAR_AFTER_USE
266 //*************************************************************************
268 //*************************************************************************
270 {
271 flags.set<CLEAR_AFTER_USE>();
272 }
273
274 //*************************************************************************
276 //*************************************************************************
277 bool is_secure() const
278 {
279 return flags.test<CLEAR_AFTER_USE>();
280 }
281#endif
282
283 protected:
284
285 //*************************************************************************
287 //*************************************************************************
289 : current_size(0)
291 {
292 }
293
294#if ETL_HAS_STRING_TRUNCATION_CHECKS
295 //*************************************************************************
297 //*************************************************************************
298 void set_truncated(bool status)
299 {
300 flags.set<IS_TRUNCATED>(status);
301 }
302#endif
303
304 //*************************************************************************
306 //*************************************************************************
308 {
309 }
310
311 size_type current_size;
312 const size_type CAPACITY;
313
314#if ETL_HAS_STRING_TRUNCATION_CHECKS || ETL_HAS_STRING_CLEAR_AFTER_USE
316#endif
317 };
318
319 //***************************************************************************
323 //***************************************************************************
324 template <typename T>
326 {
327 public:
328
330
331 typedef T value_type;
332 typedef T& reference;
333 typedef const T& const_reference;
334 typedef T* pointer;
335 typedef const T* const_pointer;
336 typedef T* iterator;
337 typedef const T* const_iterator;
338 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
339 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
340
341 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
342
343 //*********************************************************************
346 //*********************************************************************
348 {
349 return &p_buffer[0];
350 }
351
352 //*********************************************************************
355 //*********************************************************************
357 {
358 return &p_buffer[0];
359 }
360
361 //*********************************************************************
364 //*********************************************************************
366 {
367 return &p_buffer[current_size];
368 }
369
370 //*********************************************************************
373 //*********************************************************************
375 {
376 return &p_buffer[current_size];
377 }
378
379 //*********************************************************************
382 //*********************************************************************
384 {
385 return &p_buffer[0];
386 }
387
388 //*********************************************************************
391 //*********************************************************************
393 {
394 return &p_buffer[current_size];
395 }
396
397 //*********************************************************************
400 //*********************************************************************
401 reverse_iterator rbegin()
402 {
403 return reverse_iterator(end());
404 }
405
406 //*********************************************************************
409 //*********************************************************************
410 const_reverse_iterator rbegin() const
411 {
412 return const_reverse_iterator(end());
413 }
414
415 //*********************************************************************
418 //*********************************************************************
419 reverse_iterator rend()
420 {
421 return reverse_iterator(begin());
422 }
423
424 //*********************************************************************
427 //*********************************************************************
428 const_reverse_iterator rend() const
429 {
430 return const_reverse_iterator(begin());
431 }
432
433 //*********************************************************************
436 //*********************************************************************
437 const_reverse_iterator crbegin() const
438 {
439 return const_reverse_iterator(cend());
440 }
441
442 //*********************************************************************
445 //*********************************************************************
446 const_reverse_iterator crend() const
447 {
448 return const_reverse_iterator(cbegin());
449 }
450
451 //*********************************************************************
455 //*********************************************************************
457 {
458 resize(new_size, 0);
459 }
460
461 //*********************************************************************
465 //*********************************************************************
467 {
468 if (new_size > CAPACITY)
469 {
470#if ETL_HAS_STRING_TRUNCATION_CHECKS
471 set_truncated(true);
472
473#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
474 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
475#endif
476#endif
477 }
478
479 new_size = etl::min(new_size, CAPACITY);
480
481 // Size up?
483 {
484 etl::fill(p_buffer + current_size, p_buffer + new_size, value);
485 }
486
488 p_buffer[new_size] = 0;
489 cleanup();
490 }
491
492 //*********************************************************************
496 //*********************************************************************
498 {
499 new_size = etl::min(new_size, CAPACITY);
500
502 p_buffer[new_size] = 0;
503 }
504
505 //*********************************************************************
509 //*********************************************************************
510 void fill(T value)
511 {
512 etl::fill(begin(), end(), value);
513 }
514
515 //*********************************************************************
519 //*********************************************************************
521 {
522 return p_buffer[i];
523 }
524
525 //*********************************************************************
529 //*********************************************************************
531 {
532 return p_buffer[i];
533 }
534
535 //*********************************************************************
540 //*********************************************************************
542 {
543 ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds));
544 return p_buffer[i];
545 }
546
547 //*********************************************************************
552 //*********************************************************************
554 {
555 ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds));
556 return p_buffer[i];
557 }
558
559 //*********************************************************************
562 //*********************************************************************
564 {
565 return p_buffer[0];
566 }
567
568 //*********************************************************************
571 //*********************************************************************
573 {
574 return p_buffer[0];
575 }
576
577 //*********************************************************************
580 //*********************************************************************
582 {
583 return p_buffer[current_size - 1];
584 }
585
586 //*********************************************************************
589 //*********************************************************************
591 {
592 return p_buffer[current_size - 1];
593 }
594
595 //*********************************************************************
598 //*********************************************************************
600 {
601 return p_buffer;
602 }
603
604 //*********************************************************************
607 //*********************************************************************
608 ETL_CONSTEXPR const_pointer data() const
609 {
610 return p_buffer;
611 }
612
613 //*********************************************************************
616 //*********************************************************************
618 {
619 return p_buffer + current_size;
620 }
621
622 //*********************************************************************
625 //*********************************************************************
626 const_pointer data_end() const
627 {
628 return p_buffer + current_size;
629 }
630
631 //*********************************************************************
635 //*********************************************************************
637 {
638 assign(other.begin(), other.end());
639
640#if ETL_HAS_STRING_TRUNCATION_CHECKS
641 if (other.is_truncated())
642 {
643 set_truncated(true);
644
645#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
646 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
647#endif
648 }
649#endif
650
651#if ETL_HAS_STRING_CLEAR_AFTER_USE
652 if (other.is_secure())
653 {
654 set_secure();
655 }
656#endif
657
658 cleanup();
659 }
660
661 //*********************************************************************
667 //*********************************************************************
669 {
670 if (sublength == npos)
671 {
672 sublength = other.size() - subposition;
673 }
674
675 ETL_ASSERT(subposition <= other.size(), ETL_ERROR(string_out_of_bounds));
676
677 assign(other.begin() + subposition, sublength);
678
679#if ETL_HAS_STRING_TRUNCATION_CHECKS
680 if (other.is_truncated())
681 {
682 this->set_truncated(true);
683
684#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
685 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
686#endif
687 }
688#endif
689
690#if ETL_HAS_STRING_CLEAR_AFTER_USE
691 if (other.is_secure())
692 {
693 set_secure();
694 }
695#endif
696 }
697
698 //*********************************************************************
702 //*********************************************************************
703 void assign(const_pointer other)
704 {
705 initialise();
706
707 while ((*other != 0) && (current_size < CAPACITY))
708 {
709 p_buffer[current_size++] = *other++;
710 }
711
712#if ETL_HAS_STRING_TRUNCATION_CHECKS
713 set_truncated(*other != 0);
714
715#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
716 ETL_ASSERT(flags.test<IS_TRUNCATED>() == false, ETL_ERROR(string_truncation));
717#endif
718#endif
719
720 p_buffer[current_size] = 0;
721 }
722
723 //*********************************************************************
728 //*********************************************************************
729 void assign(const_pointer other, size_type length_)
730 {
731 initialise();
732
733#if ETL_HAS_STRING_TRUNCATION_CHECKS
735
736#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
737 ETL_ASSERT(flags.test<IS_TRUNCATED>() == false, ETL_ERROR(string_truncation));
738#endif
739#endif
740
741 length_ = etl::min(length_, CAPACITY);
742
743 etl::copy_n(other, length_, begin());
744
746 p_buffer[current_size] = 0;
747 }
748
749 //*********************************************************************
755 //*********************************************************************
756 template <typename TIterator>
757 void assign(TIterator first, TIterator last)
758 {
759#if ETL_IS_DEBUG_BUILD
760 difference_type d = etl::distance(first, last);
761 ETL_ASSERT(d >= 0, ETL_ERROR(string_iterator));
762#endif
763
764 initialise();
765
766 while ((first != last) && (current_size != CAPACITY))
767 {
768 p_buffer[current_size++] = *first++;
769 }
770
771 p_buffer[current_size] = 0;
772
773#if ETL_HAS_STRING_TRUNCATION_CHECKS
774 set_truncated(first != last);
775
776#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
777 ETL_ASSERT(flags.test<IS_TRUNCATED>() == false, ETL_ERROR(string_truncation));
778#endif
779#endif
780 }
781
782 //*********************************************************************
787 //*********************************************************************
788 void assign(size_type n, T value)
789 {
790 initialise();
791
792#if ETL_HAS_STRING_TRUNCATION_CHECKS
794
795#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
796 ETL_ASSERT(flags.test<IS_TRUNCATED>() == false, ETL_ERROR(string_truncation));
797#endif
798#endif
799
800 n = etl::min(n, CAPACITY);
801
802 etl::fill_n(begin(), n, value);
803 current_size = n;
804 p_buffer[current_size] = 0;
805 }
806
807 //*************************************************************************
809 //*************************************************************************
810 void clear()
811 {
812 initialise();
813 }
814
815 //*********************************************************************
819 //*********************************************************************
820 void push_back(T value)
821 {
822 if (current_size != CAPACITY)
823 {
824 p_buffer[current_size++] = value;
825 p_buffer[current_size] = 0;
826 }
827 else
828 {
829#if ETL_HAS_STRING_TRUNCATION_CHECKS
830 set_truncated(true);
831
832#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
833 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
834#endif
835#endif
836 }
837 }
838
839 //*************************************************************************
842 //*************************************************************************
843 void pop_back()
844 {
845 if (current_size != 0)
846 {
847 p_buffer[--current_size] = 0;
848 }
849 }
850
851 //*********************************************************************
854 //*********************************************************************
856 {
857 insert(end(), str.begin(), str.end());
858
859#if ETL_HAS_STRING_TRUNCATION_CHECKS
860 if (str.is_truncated())
861 {
862 set_truncated(true);
863
864#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
865 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
866#endif
867 }
868#endif
869
870 return *this;
871 }
872
873 //*********************************************************************
878 //*********************************************************************
880 {
881 ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
882
884
885 return *this;
886 }
887
888 //*********************************************************************
891 //*********************************************************************
892 ibasic_string& append(const T* str)
893 {
894 insert(size(), str);
895 return *this;
896 }
897
898 //*********************************************************************
902 //*********************************************************************
904 {
905 insert(size(), str, n);
906 return *this;
907 }
908
909 //*********************************************************************
913 //*********************************************************************
915 {
916 insert(size(), n, c);
917 return *this;
918 }
919
920 //*********************************************************************
924 //*********************************************************************
925 template <class TIterator>
927 {
928 insert(end(), first, last);
929 return *this;
930 }
931
932 //*********************************************************************
936 //*********************************************************************
938 {
939 // Quick hack, as iterators are pointers.
941
943 {
944 // Not full yet.
945 if (position != end())
946 {
947 // Insert in the middle.
948 ++current_size;
949 etl::copy_backward(insert_position, end() - 1, end());
950 *insert_position = value;
951 }
952 else
953 {
954 // Insert at the end.
955 *insert_position = value;
956 ++current_size;
957 }
958 }
959 else
960 {
961 // Already full.
962 if (position != end())
963 {
964 // Insert in the middle.
965 etl::copy_backward(insert_position, end() - 1, end());
966 *insert_position = value;
967 }
968
969#if ETL_HAS_STRING_TRUNCATION_CHECKS
970 set_truncated(true);
971
972#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
973 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
974#endif
975#endif
976 }
977
978 p_buffer[current_size] = 0;
979
980 return insert_position;
981 }
982
983 //*********************************************************************
988 //*********************************************************************
990 {
991 iterator position_ = to_iterator(position);
992
993 if (n == 0)
994 {
995 return position_;
996 }
997
998 // Quick hack, as iterators are pointers.
1000 const size_type start = etl::distance(cbegin(), position);
1001
1002 // No effect.
1003 if (start >= CAPACITY)
1004 {
1005#if ETL_HAS_STRING_TRUNCATION_CHECKS
1006 set_truncated(true);
1007
1008#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1009 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1010#endif
1011#endif
1012 return to_iterator(position);;
1013 }
1014
1015 // Fills the string to the end?
1016 if ((start + n) >= CAPACITY)
1017 {
1018 if ((current_size + n) > CAPACITY)
1019 {
1020#if ETL_HAS_STRING_TRUNCATION_CHECKS
1021 set_truncated(true);
1022
1023#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1024 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1025#endif
1026#endif
1027 }
1028
1030 etl::fill(insert_position, end(), value);
1031 }
1032 else
1033 {
1034 // Lets do some shifting.
1035 const size_type shift_amount = n;
1036 const size_type to_position = start + shift_amount;
1040
1041 // Will the string truncate?
1042 if ((start + shift_amount + remaining_characters) > CAPACITY)
1043 {
1045
1046#if ETL_HAS_STRING_TRUNCATION_CHECKS
1047 set_truncated(true);
1048
1049#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1050 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1051#endif
1052#endif
1053 }
1054 else
1055 {
1057 }
1058
1060 etl::fill(insert_position, insert_position + shift_amount, value);
1061 }
1062
1063 p_buffer[current_size] = 0;
1064
1065 return position_;
1066 }
1067
1068 //*********************************************************************
1074 //*********************************************************************
1075 template <typename TIterator>
1077 {
1078 iterator position_ = to_iterator(position);
1079
1080 if (first == last)
1081 {
1082 return position_;
1083 }
1084
1085 const size_type start = etl::distance(begin(), position_);
1086 const size_type n = etl::distance(first, last);
1087
1088 // No effect.
1089 if (start >= CAPACITY)
1090 {
1091#if ETL_HAS_STRING_TRUNCATION_CHECKS
1092 set_truncated(true);
1093
1094#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1095 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1096#endif
1097#endif
1098 return position_;
1099 }
1100
1101 // Fills the string to the end?
1102 if ((start + n) >= CAPACITY)
1103 {
1104 if (((current_size + n) > CAPACITY))
1105 {
1106#if ETL_HAS_STRING_TRUNCATION_CHECKS
1107 set_truncated(true);
1108
1109#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1110 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1111#endif
1112#endif
1113 }
1114
1116
1117 while (position_ != end())
1118 {
1119 *position_++ = *first++;
1120 }
1121 }
1122 else
1123 {
1124 // Lets do some shifting.
1125 const size_type shift_amount = n;
1126 const size_type to_position = start + shift_amount;
1130
1131 // Will the string truncate?
1132 if ((start + shift_amount + remaining_characters) > CAPACITY)
1133 {
1135
1136#if ETL_HAS_STRING_TRUNCATION_CHECKS
1137 set_truncated(true);
1138
1139#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1140 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1141#endif
1142#endif
1143 }
1144 else
1145 {
1147 }
1148
1150
1151 while (first != last)
1152 {
1153 *position_++ = *first++;
1154 }
1155 }
1156
1157 p_buffer[current_size] = 0;
1158
1159 return position_;
1160 }
1161
1162 //*********************************************************************
1166 //*********************************************************************
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 //*********************************************************************
1193 //*********************************************************************
1195 {
1196 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1197 ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
1198
1199 if ((sublength == npos) || (subposition + sublength > str.size()))
1200 {
1201 sublength = str.size() - subposition;
1202 }
1203
1204 insert(begin() + position, str.cbegin() + subposition, str.cbegin() + subposition + sublength);
1205
1206#if ETL_HAS_STRING_TRUNCATION_CHECKS
1207 if (str.is_truncated())
1208 {
1209 set_truncated(true);
1210
1211#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1212 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1213#endif
1214 }
1215#endif
1216
1217 return *this;
1218 }
1219
1220 //*********************************************************************
1224 //*********************************************************************
1225 etl::ibasic_string<T>& insert(size_type position, const_pointer s)
1226 {
1227 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1228
1229 insert(begin() + position, s, s + etl::strlen(s));
1230 return *this;
1231 }
1232
1233 //*********************************************************************
1238 //*********************************************************************
1240 {
1241 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1242
1243 insert(begin() + position, s, s + n);
1244 return *this;
1245 }
1246
1247 //*********************************************************************
1252 //*********************************************************************
1254 {
1255 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1256
1257 insert(begin() + position, n, c);
1258 return *this;
1259 }
1260
1261 //*********************************************************************
1266 //*********************************************************************
1268 {
1269 // Limit the length.
1270 length_ = etl::min(length_, size() - position);
1271
1272 erase(begin() + position, begin() + position + length_);
1273
1274 return *this;
1275 }
1276
1277 //*********************************************************************
1281 //*********************************************************************
1283 {
1284 etl::copy(i_element + 1, end(), i_element);
1285 p_buffer[--current_size] = 0;
1286
1287 return i_element;
1288 }
1289
1290 //*********************************************************************
1294 //*********************************************************************
1296 {
1298
1299 etl::copy(i_element_ + 1, end(), i_element_);
1300 p_buffer[--current_size] = 0;
1301
1302 return i_element_;
1303 }
1304
1305 //*********************************************************************
1312 //*********************************************************************
1314 {
1315 iterator first_ = to_iterator(first);
1316 iterator last_ = to_iterator(last);
1317
1318 if (first_ == last_)
1319 {
1320 return first_;
1321 }
1322
1323 etl::copy(last_, end(), first_);
1324 size_type n_delete = etl::distance(first_, last_);
1325
1327 p_buffer[current_size] = 0;
1328 cleanup();
1329
1330 return first_;
1331 }
1332
1333 //*********************************************************************
1335 //*********************************************************************
1336 const_pointer c_str() const
1337 {
1338 return p_buffer;
1339 }
1340
1341 //*********************************************************************
1346 //*********************************************************************
1348 {
1349 if (pos < size())
1350 {
1351 if (count != npos)
1352 {
1353 count = etl::min(count, size() - pos);
1354 }
1355 else
1356 {
1357 count = size() - pos;
1358 }
1359
1360 etl::copy_n(p_buffer + pos, count, dest);
1361
1362 return count;
1363 }
1364 else
1365 {
1366 return 0U;
1367 }
1368 }
1369
1370 //*********************************************************************
1374 //*********************************************************************
1376 {
1377 if ((pos + str.size()) > size())
1378 {
1379 return npos;
1380 }
1381
1382 const_iterator iposition = etl::search(begin() + pos, end(), str.begin(), str.end());
1383
1384 if (iposition == end())
1385 {
1386 return npos;
1387 }
1388 else
1389 {
1390 return etl::distance(begin(), iposition);
1391 }
1392 }
1393
1394 //*********************************************************************
1398 //*********************************************************************
1399 size_type find(const_pointer s, size_type pos = 0) const
1400 {
1401#if ETL_IS_DEBUG_BUILD
1402 if ((pos + etl::strlen(s)) > size())
1403 {
1404 return npos;
1405 }
1406#endif
1407
1408 const_iterator iposition = etl::search(begin() + pos, end(), s, s + etl::strlen(s));
1409
1410 if (iposition == end())
1411 {
1412 return npos;
1413 }
1414 else
1415 {
1416 return etl::distance(begin(), iposition);
1417 }
1418 }
1419
1420 //*********************************************************************
1425 //*********************************************************************
1426 size_type find(const_pointer s, size_type pos, size_type n) const
1427 {
1428#if ETL_IS_DEBUG_BUILD
1429 if ((pos + etl::strlen(s) - n) > size())
1430 {
1431 return npos;
1432 }
1433#endif
1434
1435 const_iterator iposition = etl::search(begin() + pos, end(), s, s + n);
1436
1437 if (iposition == end())
1438 {
1439 return npos;
1440 }
1441 else
1442 {
1443 return etl::distance(begin(), iposition);
1444 }
1445 }
1446
1447 //*********************************************************************
1451 //*********************************************************************
1452 size_type find(T c, size_type position = 0) const
1453 {
1454 const_iterator i = etl::find(begin() + position, end(), c);
1455
1456 if (i != end())
1457 {
1458 return etl::distance(begin(), i);
1459 }
1460 else
1461 {
1462 return npos;
1463 }
1464 }
1465
1466 //*********************************************************************
1470 //*********************************************************************
1471 size_type rfind(const ibasic_string<T>& str, size_type position = npos) const
1472 {
1473 if ((str.size()) > size())
1474 {
1475 return npos;
1476 }
1477
1478 if (position >= size())
1479 {
1480 position = size();
1481 }
1482
1483 position = size() - position;
1484
1485 const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), str.rbegin(), str.rend());
1486
1487 if (iposition == rend())
1488 {
1489 return npos;
1490 }
1491 else
1492 {
1493 return size() - str.size() - etl::distance(rbegin(), iposition);
1494 }
1495 }
1496
1497 //*********************************************************************
1501 //*********************************************************************
1502 size_type rfind(const_pointer s, size_type position = npos) const
1503 {
1505
1506 if (len > size())
1507 {
1508 return npos;
1509 }
1510
1511 if (position >= size())
1512 {
1513 position = size();
1514 }
1515
1516 position = size() - position;
1517
1518 const_reverse_iterator srbegin(s + len);
1519 const_reverse_iterator srend(s);
1520
1521 const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), srbegin, srend);
1522
1523 if (iposition == rend())
1524 {
1525 return npos;
1526 }
1527 else
1528 {
1529 return size() - len - etl::distance(rbegin(), iposition);
1530 }
1531 }
1532
1533 //*********************************************************************
1537 //*********************************************************************
1538 size_type rfind(const_pointer s, size_type position, size_type length_) const
1539 {
1540 if (length_ > size())
1541 {
1542 return npos;
1543 }
1544
1545 if (position >= size())
1546 {
1547 position = size();
1548 }
1549
1550 position = size() - position;
1551
1552 const_reverse_iterator srbegin(s + length_);
1553 const_reverse_iterator srend(s);
1554
1555 const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), srbegin, srend);
1556
1557 if (iposition == rend())
1558 {
1559 return npos;
1560 }
1561 else
1562 {
1563 return size() - length_ - etl::distance(rbegin(), iposition);
1564 }
1565 }
1566
1567 //*********************************************************************
1571 //*********************************************************************
1572 size_type rfind(T c, size_type position = npos) const
1573 {
1574 if (position >= size())
1575 {
1576 position = size();
1577 }
1578
1579 position = size() - position;
1580
1581 const_reverse_iterator i = etl::find(rbegin() + position, rend(), c);
1582
1583 if (i != rend())
1584 {
1585 return size() - etl::distance(rbegin(), i) - 1;
1586 }
1587 else
1588 {
1589 return npos;
1590 }
1591 }
1592
1593 //*********************************************************************
1598 //*********************************************************************
1600 {
1601 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1602
1603 // Limit the length.
1604 length_ = etl::min(length_, size() - position);
1605
1606 // Erase the bit we want to replace.
1607 erase(position, length_);
1608
1609 // Insert the new stuff.
1610 insert(position, str);
1611
1612 return *this;
1613 }
1614
1615 //*********************************************************************
1620 //*********************************************************************
1622 {
1623 // Quick hack, as iterators are pointers.
1624 iterator first_ = to_iterator(first);
1625 iterator last_ = to_iterator(last);
1626
1627 // Erase the bit we want to replace.
1628 erase(first_, last_);
1629
1630 // Insert the new stuff.
1631 insert(first_, str.begin(), str.end());
1632
1633#if ETL_HAS_STRING_TRUNCATION_CHECKS
1634 if (str.is_truncated())
1635 {
1636 set_truncated(true);
1637
1638#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1639 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1640#endif
1641 }
1642#endif
1643
1644 return *this;
1645 }
1646
1647 //*********************************************************************
1649 //*********************************************************************
1651 {
1652 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1653 ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
1654
1655 // Limit the lengths.
1656 length_ = etl::min(length_, size() - position);
1657 sublength = etl::min(sublength, str.size() - subposition);
1658
1659 // Erase the bit we want to replace.
1660 erase(position, length_);
1661
1662 // Insert the new stuff.
1663 insert(position, str, subposition, sublength);
1664
1665#if ETL_HAS_STRING_TRUNCATION_CHECKS
1666 if (str.is_truncated())
1667 {
1668 set_truncated(true);
1669
1670#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
1671 ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
1672#endif
1673 }
1674#endif
1675
1676 return *this;
1677 }
1678
1679 //*********************************************************************
1681 //*********************************************************************
1683 {
1684 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1685
1686 // Limit the length.
1687 length_ = etl::min(length_, size() - position);
1688
1689 // Erase the bit we want to replace.
1690 erase(position, length_);
1691
1692 // Insert the new stuff.
1693 insert(position, s, etl::strlen(s));
1694
1695 return *this;
1696 }
1697
1698 //*********************************************************************
1700 //*********************************************************************
1702 {
1703 // Quick hack, as iterators are pointers.
1704 iterator first_ = to_iterator(first);
1705 iterator last_ = to_iterator(last);
1706
1707 // Erase the bit we want to replace.
1708 erase(first_, last_);
1709
1710 // Insert the new stuff.
1711 insert(first_, s, s + etl::strlen(s));
1712
1713 return *this;
1714 }
1715
1716 //*********************************************************************
1718 //*********************************************************************
1720 {
1721 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1722
1723 // Limit the length.
1724 length_ = etl::min(length_, size() - position);
1725
1726 // Erase the bit we want to replace.
1727 erase(position, length_);
1728
1729 // Insert the new stuff.
1730 insert(position, s, n);
1731
1732 return *this;
1733 }
1734
1735 //*********************************************************************
1737 //*********************************************************************
1739 {
1740 // Quick hack, as iterators are pointers.
1741 iterator first_ = to_iterator(first);
1742 iterator last_ = to_iterator(last);
1743
1744 // Erase the bit we want to replace.
1745 erase(first_, last_);
1746
1747 // Insert the new stuff.
1748 insert(first_, s, s + n);
1749
1750 return *this;
1751 }
1752
1753 //*********************************************************************
1755 //*********************************************************************
1757 {
1758 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1759
1760 // Limit the length.
1761 length_ = etl::min(length_, size() - position);
1762
1763 // Erase the bit we want to replace.
1764 erase(position, length_);
1765
1766 // Insert the new stuff.
1767 insert(position, n, c);
1768
1769 return *this;
1770 }
1771
1772 //*********************************************************************
1774 //*********************************************************************
1776 {
1777 // Quick hack, as iterators are pointers.
1778 iterator first_ = to_iterator(first);
1779 iterator last_ = to_iterator(last);
1780
1781 // Erase the bit we want to replace.
1782 erase(first_, last_);
1783
1784 // Insert the new stuff.
1785 insert(first_, n, c);
1786
1787 return *this;
1788 }
1789
1790 //*********************************************************************
1792 //*********************************************************************
1793 template <typename TIterator>
1795 {
1796 // Quick hack, as iterators are pointers.
1797 iterator first_ = to_iterator(first);
1798 iterator last_ = to_iterator(last);
1799
1800 // Erase the bit we want to replace.
1801 erase(first_, last_);
1802
1803 // Insert the new stuff.
1805
1806 return *this;
1807 }
1808
1809 //*************************************************************************
1811 //*************************************************************************
1812 int compare(const ibasic_string& str) const
1813 {
1814 return compare(p_buffer,
1815 p_buffer + size(),
1816 str.p_buffer,
1817 str.p_buffer + str.size());
1818 }
1819
1820 //*************************************************************************
1822 //*************************************************************************
1823 int compare(size_type position, size_type length_, const ibasic_string& str) const
1824 {
1825 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1826
1827 // Limit the length.
1828 length_ = etl::min(length_, size() - position);
1829
1830 return compare(p_buffer + position,
1831 p_buffer + position + length_,
1832 str.p_buffer,
1833 str.p_buffer + str.size());
1834 }
1835
1836 //*************************************************************************
1838 //*************************************************************************
1840 {
1841 ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
1842 ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
1843
1844 // Limit the lengths.
1845 length_ = etl::min(length_, size() - position);
1846 sublength = etl::min(sublength, str.size() - subposition);
1847
1848 return compare(p_buffer + position,
1849 p_buffer + position + length_,
1850 str.p_buffer + subposition,
1851 str.p_buffer + subposition + sublength);
1852 }
1853
1854 //*************************************************************************
1856 //*************************************************************************
1857 int compare(const value_type* s) const
1858 {
1859 return compare(p_buffer,
1860 p_buffer + size(),
1861 s,
1862 s + etl::strlen(s));
1863 }
1864
1865 //*************************************************************************
1867 //*************************************************************************
1868 int compare(size_type position, size_type length_, const_pointer s) const
1869 {
1870 return compare(p_buffer + position,
1871 p_buffer + position + length_,
1872 s,
1873 s + etl::strlen(s));
1874 }
1875
1876 //*************************************************************************
1878 //*************************************************************************
1879 int compare(size_type position, size_type length_, const_pointer s, size_type n) const
1880 {
1881 return compare(p_buffer + position,
1882 p_buffer + position + length_,
1883 s,
1884 s + n);
1885 }
1886
1887 //*********************************************************************
1891 //*********************************************************************
1892 size_type find_first_of(const ibasic_string<T>& str, size_type position = 0) const
1893 {
1894 return find_first_of(str.c_str(), position, str.size());
1895 }
1896
1897 //*********************************************************************
1901 //*********************************************************************
1902 size_type find_first_of(const_pointer s, size_type position = 0) const
1903 {
1904 return find_first_of(s, position, etl::strlen(s));
1905 }
1906
1907 //*********************************************************************
1912 //*********************************************************************
1913 size_type find_first_of(const_pointer s, size_type position, size_type n) const
1914 {
1915 if (position < size())
1916 {
1917 for (size_type i = position; i < size(); ++i)
1918 {
1919 for (size_type j = 0; j < n; ++j)
1920 {
1921 if (p_buffer[i] == s[j])
1922 {
1923 return i;
1924 }
1925 }
1926 }
1927 }
1928
1929 return npos;
1930 }
1931
1932 //*********************************************************************
1936 //*********************************************************************
1938 {
1939 if (position < size())
1940 {
1941 for (size_type i = position; i < size(); ++i)
1942 {
1943 if (p_buffer[i] == c)
1944 {
1945 return i;
1946 }
1947 }
1948 }
1949
1950 return npos;
1951 }
1952
1953 //*********************************************************************
1957 //*********************************************************************
1958 size_type find_last_of(const ibasic_string<T>& str, size_type position = npos) const
1959 {
1960 return find_last_of(str.c_str(), position, str.size());
1961 }
1962
1963 //*********************************************************************
1967 //*********************************************************************
1968 size_type find_last_of(const_pointer s, size_type position = npos) const
1969 {
1970 return find_last_of(s, position, etl::strlen(s));
1971 }
1972
1973 //*********************************************************************
1978 //*********************************************************************
1979 size_type find_last_of(const_pointer s, size_type position, size_type n) const
1980 {
1981 if (empty())
1982 {
1983 return npos;
1984 }
1985
1986 position = etl::min(position, size() - 1);
1987
1988 const_reverse_iterator it = rbegin() + size() - position - 1;
1989
1990 while (it != rend())
1991 {
1992 for (size_type j = 0; j < n; ++j)
1993 {
1994 if (p_buffer[position] == s[j])
1995 {
1996 return position;
1997 }
1998 }
1999
2000 ++it;
2001 --position;
2002 }
2003
2004 return npos;
2005 }
2006
2007 //*********************************************************************
2011 //*********************************************************************
2013 {
2014 if (empty())
2015 {
2016 return npos;
2017 }
2018
2019 position = etl::min(position, size() - 1);
2020
2021 const_reverse_iterator it = rbegin() + size() - position - 1;
2022
2023 while (it != rend())
2024 {
2025 if (p_buffer[position] == c)
2026 {
2027 return position;
2028 }
2029
2030 ++it;
2031 --position;
2032 }
2033
2034 return npos;
2035 }
2036
2037 //*********************************************************************
2041 //*********************************************************************
2043 {
2044 return find_first_not_of(str.c_str(), position, str.size());
2045 }
2046
2047 //*********************************************************************
2051 //*********************************************************************
2052 size_type find_first_not_of(const_pointer s, size_type position = 0) const
2053 {
2054 return find_first_not_of(s, position, etl::strlen(s));
2055 }
2056
2057 //*********************************************************************
2062 //*********************************************************************
2063 size_type find_first_not_of(const_pointer s, size_type position, size_type n) const
2064 {
2065 if (position < size())
2066 {
2067 for (size_type i = position; i < size(); ++i)
2068 {
2069 bool found = false;
2070
2071 for (size_type j = 0; j < n; ++j)
2072 {
2073 if (p_buffer[i] == s[j])
2074 {
2075 found = true;
2076 }
2077 }
2078
2079 if (!found)
2080 {
2081 return i;
2082 }
2083 }
2084 }
2085
2086 return npos;
2087 }
2088
2089 //*********************************************************************
2093 //*********************************************************************
2095 {
2096 if (position < size())
2097 {
2098 for (size_type i = position; i < size(); ++i)
2099 {
2100 if (*(p_buffer + i) != c)
2101 {
2102 return i;
2103 }
2104 }
2105 }
2106
2107 return npos;
2108 }
2109
2110 //*********************************************************************
2114 //*********************************************************************
2115 size_type find_last_not_of(const ibasic_string<T>& str, size_type position = npos) const
2116 {
2117 return find_last_not_of(str.c_str(), position, str.size());
2118 }
2119
2120 //*********************************************************************
2124 //*********************************************************************
2125 size_type find_last_not_of(const_pointer s, size_type position = npos) const
2126 {
2127 return find_last_not_of(s, position, etl::strlen(s));
2128 }
2129
2130 //*********************************************************************
2135 //*********************************************************************
2136 size_type find_last_not_of(const_pointer s, size_type position, size_type n) const
2137 {
2138 if (empty())
2139 {
2140 return npos;
2141 }
2142
2143 position = etl::min(position, size() - 1);
2144
2145 const_reverse_iterator it = rbegin() + size() - position - 1;
2146
2147 while (it != rend())
2148 {
2149 bool found = false;
2150
2151 for (size_type j = 0; j < n; ++j)
2152 {
2153 if (p_buffer[position] == s[j])
2154 {
2155 found = true;
2156 }
2157 }
2158
2159 if (!found)
2160 {
2161 return position;
2162 }
2163
2164 ++it;
2165 --position;
2166 }
2167
2168 return npos;
2169 }
2170
2171 //*********************************************************************
2172 //
2173 //*********************************************************************
2174 size_type find_last_not_of(value_type c, size_type position = npos) const
2175 {
2176 if (empty())
2177 {
2178 return npos;
2179 }
2180
2181 position = etl::min(position, size() - 1);
2182
2183 const_reverse_iterator it = rbegin() + size() - position - 1;
2184
2185 while (it != rend())
2186 {
2187 if (p_buffer[position] != c)
2188 {
2189 return position;
2190 }
2191
2192 ++it;
2193 --position;
2194 }
2195
2196 return npos;
2197 }
2198
2199 //*************************************************************************
2201 //*************************************************************************
2203 {
2204 if (&rhs != this)
2205 {
2206 assign(rhs);
2207 }
2208
2209 return *this;
2210 }
2211
2212 //*************************************************************************
2214 //*************************************************************************
2216 {
2217 assign(rhs);
2218
2219 return *this;
2220 }
2221
2222 //*************************************************************************
2224 //*************************************************************************
2226 {
2227 append(rhs);
2228
2229 return *this;
2230 }
2231
2232 //*************************************************************************
2234 //*************************************************************************
2236 {
2237 append(rhs);
2238
2239 return *this;
2240 }
2241
2242 //*************************************************************************
2244 //*************************************************************************
2246 {
2247 append(size_type(1), rhs);
2248
2249 return *this;
2250 }
2251
2252#if ETL_HAS_ISTRING_REPAIR
2253 //*************************************************************************
2255 //*************************************************************************
2256 virtual void repair() = 0;
2257#endif
2258
2259 //*********************************************************************
2261 //*********************************************************************
2263 {
2264#if ETL_HAS_STRING_TRUNCATION_CHECKS
2265 set_truncated(false);
2266#endif
2267 etl::fill(&p_buffer[current_size], &p_buffer[CAPACITY + 1U], T(0));
2268 }
2269
2270 //*********************************************************************
2274 //*********************************************************************
2276 {
2277#if ETL_HAS_STRING_TRUNCATION_CHECKS
2278 set_truncated(p_buffer[CAPACITY] != T(0));
2279#endif
2280
2281 p_buffer[CAPACITY] = T(0); // Ensure a terminating null.
2282 current_size = etl::strlen(p_buffer);
2283 }
2284
2285 protected:
2286
2287 //*********************************************************************
2289 //*********************************************************************
2292 p_buffer(p_buffer_)
2293 {
2294 }
2295
2296 //*********************************************************************
2298 //*********************************************************************
2300 {
2301 current_size = 0U;
2302 cleanup();
2303 p_buffer[0] = 0;
2304#if ETL_HAS_STRING_TRUNCATION_CHECKS
2305 set_truncated(false);
2306#endif
2307 }
2308
2309 //*************************************************************************
2311 //*************************************************************************
2313 {
2314 p_buffer = p_buffer_;
2315 }
2316
2317 private:
2318
2319 //*************************************************************************
2321 //*************************************************************************
2322 int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) const
2323 {
2324 while ((first1 != last1) && (first2 != last2))
2325 {
2326 if (*first1 < *first2)
2327 {
2328 // Compared character is lower.
2329 return -1;
2330 }
2331 else if (*first1 > *first2)
2332 {
2333 // Compared character is higher.
2334 return 1;
2335 }
2336
2337 ++first1;
2338 ++first2;
2339 }
2340
2341 // We reached the end of one or both of the strings.
2342 if ((first1 == last1) && (first2 == last2))
2343 {
2344 // Same length.
2345 return 0;
2346 }
2347 else if (first1 == last1)
2348 {
2349 // Compared string is shorter.
2350 return -1;
2351 }
2352 else
2353 {
2354 // Compared string is longer.
2355 return 1;
2356 }
2357 }
2358
2359 //*************************************************************************
2361 //*************************************************************************
2362 void cleanup()
2363 {
2364#if ETL_HAS_STRING_CLEAR_AFTER_USE
2365 if (is_secure())
2366 {
2367 etl::memory_clear_range(&p_buffer[current_size], &p_buffer[CAPACITY]);
2368 }
2369#endif
2370 }
2371
2372 //*************************************************************************
2374 //*************************************************************************
2375 ibasic_string(const ibasic_string&);
2376
2377 //*************************************************************************
2379 //*************************************************************************
2380 T* p_buffer;
2381
2382 //*************************************************************************
2384 //*************************************************************************
2385#if defined(ETL_POLYMORPHIC_STRINGS) || defined(ETL_POLYMORPHIC_CONTAINERS) || defined(ETL_ISTRING_REPAIR_ENABLE)
2386 public:
2387 virtual
2388#else
2389 protected:
2390#endif
2392 {
2393#if ETL_HAS_STRING_CLEAR_AFTER_USE
2394 if (is_secure())
2395 {
2396 initialise();
2397 }
2398#endif
2399 }
2400
2401 protected:
2402
2403 //*************************************************************************
2405 //*************************************************************************
2407 {
2408 return const_cast<iterator>(itr);
2409 }
2410 };
2411
2412 //***************************************************************************
2418 //***************************************************************************
2419 template <typename T>
2421 {
2422 return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
2423 }
2424
2425 //***************************************************************************
2431 //***************************************************************************
2432 template <typename T>
2434 {
2435 return (lhs.size() == etl::strlen(rhs)) && etl::equal(lhs.begin(), lhs.end(), rhs);
2436 }
2437
2438 //***************************************************************************
2444 //***************************************************************************
2445 template <typename T>
2447 {
2448 return (rhs.size() == etl::strlen(lhs)) && etl::equal(rhs.begin(), rhs.end(), lhs);
2449 }
2450
2451 //***************************************************************************
2457 //***************************************************************************
2458 template <typename T>
2460 {
2461 return !(lhs == rhs);
2462 }
2463
2464 //***************************************************************************
2470 //***************************************************************************
2471 template <typename T>
2473 {
2474 return !(lhs == rhs);
2475 }
2476
2477 //***************************************************************************
2483 //***************************************************************************
2484 template <typename T>
2486 {
2487 return !(lhs == rhs);
2488 }
2489
2490 //***************************************************************************
2496 //***************************************************************************
2497 template <typename T>
2499 {
2500 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
2501 }
2502
2503 //***************************************************************************
2509 //***************************************************************************
2510 template <typename T>
2512 {
2513 return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs, rhs + etl::strlen(rhs));
2514 }
2515
2516 //***************************************************************************
2522 //***************************************************************************
2523 template <typename T>
2525 {
2526 return etl::lexicographical_compare(lhs, lhs + etl::strlen(lhs), rhs.begin(), rhs.end());
2527 }
2528
2529
2530 //***************************************************************************
2536 //***************************************************************************
2537 template <typename T>
2539 {
2540 return (rhs < lhs);
2541 }
2542
2543 //***************************************************************************
2549 //***************************************************************************
2550 template <typename T>
2552 {
2553 return (rhs < lhs);
2554 }
2555
2556 //***************************************************************************
2562 //***************************************************************************
2563 template <typename T>
2565 {
2566 return (rhs < lhs);
2567 }
2568
2569
2570 //***************************************************************************
2576 //***************************************************************************
2577 template <typename T>
2579 {
2580 return !(lhs > rhs);
2581 }
2582
2583 //***************************************************************************
2589 //***************************************************************************
2590 template <typename T>
2592 {
2593 return !(lhs > rhs);
2594 }
2595
2596 //***************************************************************************
2602 //***************************************************************************
2603 template <typename T>
2605 {
2606 return !(lhs > rhs);
2607 }
2608
2609
2610 //***************************************************************************
2616 //***************************************************************************
2617 template <typename T>
2619 {
2620 return !(lhs < rhs);
2621 }
2622
2623 //***************************************************************************
2629 //***************************************************************************
2630 template <typename T>
2632 {
2633 return !(lhs < rhs);
2634 }
2635
2636 //***************************************************************************
2642 //***************************************************************************
2643 template <typename T>
2645 {
2646 return !(lhs < rhs);
2647 }
2648}
2649
2650#include "private/minmax_pop.h"
2651
2652#endif
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:326
int compare(size_type position, size_type length_, const ibasic_string &str) const
Compare position / length with string.
Definition basic_string.h:1823
ibasic_string & append(TIterator first, TIterator last)
Definition basic_string.h:926
size_type find_last_of(const_pointer s, size_type position=npos) const
Definition basic_string.h:1968
size_type rfind(const_pointer s, size_type position=npos) const
Definition basic_string.h:1502
etl::ibasic_string< T > & insert(size_type position, const etl::ibasic_string< T > &str)
Definition basic_string.h:1167
ibasic_string & append(const T *str)
Definition basic_string.h:892
size_type find_last_not_of(const_pointer s, size_type position=npos) const
Definition basic_string.h:2125
size_type find(const_pointer s, size_type pos=0) const
Definition basic_string.h:1399
ibasic_string & operator=(const ibasic_string &rhs)
Assignment operator.
Definition basic_string.h:2202
ibasic_string & append(const ibasic_string &str, size_type subposition, size_type sublength=npos)
Definition basic_string.h:879
const_reverse_iterator rbegin() const
Definition basic_string.h:410
reference operator[](size_type i)
Definition basic_string.h:520
void assign(const etl::ibasic_string< T > &other, size_type subposition, size_type sublength)
Definition basic_string.h:668
pointer data_end()
Definition basic_string.h:617
iterator erase(const_iterator first, const_iterator last)
Definition basic_string.h:1313
iterator insert(const_iterator position, TIterator first, TIterator last)
Definition basic_string.h:1076
size_type find_last_of(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:1958
size_type find_first_of(value_type c, size_type position=0) const
Definition basic_string.h:1937
size_type find(T c, size_type position=0) const
Definition basic_string.h:1452
void pop_back()
Definition basic_string.h:843
size_type rfind(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:1471
void initialize_free_space()
Clears the free space to string terminator value.
Definition basic_string.h:2262
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:1719
iterator to_iterator(const_iterator itr) const
Convert from const_iterator to iterator.
Definition basic_string.h:2406
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:1756
ibasic_string & replace(const_iterator first, const_iterator last, const ibasic_string &str)
Definition basic_string.h:1621
size_type find_first_of(const ibasic_string< T > &str, size_type position=0) const
Definition basic_string.h:1892
const_reference back() const
Definition basic_string.h:590
const_iterator begin() const
Definition basic_string.h:356
size_type find_last_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:1979
reverse_iterator rbegin()
Definition basic_string.h:401
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:1794
void resize(size_type new_size)
Definition basic_string.h:456
size_type find_last_not_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2136
size_type find_first_not_of(const_pointer s, size_type position=0) const
Definition basic_string.h:2052
size_type rfind(T c, size_type position=npos) const
Definition basic_string.h:1572
etl::ibasic_string< T > & erase(size_type position, size_type length_=npos)
Definition basic_string.h:1267
int compare(const value_type *s) const
Compare with C string.
Definition basic_string.h:1857
int compare(size_type position, size_type length_, const_pointer s) const
Compare position / length with C string.
Definition basic_string.h:1868
iterator insert(const_iterator position, size_type n, T value)
Definition basic_string.h:989
const_reference at(size_type i) const
Definition basic_string.h:553
void clear()
Clears the string.
Definition basic_string.h:810
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:1839
reverse_iterator rend()
Definition basic_string.h:419
iterator erase(iterator i_element)
Definition basic_string.h:1282
const_reverse_iterator crend() const
Definition basic_string.h:446
reference at(size_type i)
Definition basic_string.h:541
~ibasic_string()
Destructor.
Definition basic_string.h:2391
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:1701
size_type find(const_pointer s, size_type pos, size_type n) const
Definition basic_string.h:1426
size_type find_first_of(const_pointer s, size_type position=0) const
Definition basic_string.h:1902
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:1650
iterator begin()
Definition basic_string.h:347
iterator end()
Definition basic_string.h:365
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:1775
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:1738
void assign(TIterator first, TIterator last)
Definition basic_string.h:757
etl::ibasic_string< T > & insert(size_type position, const etl::ibasic_string< T > &str, size_type subposition, size_type sublength)
Definition basic_string.h:1194
size_type find(const ibasic_string< T > &str, size_type pos=0) const
Definition basic_string.h:1375
void push_back(T value)
Definition basic_string.h:820
size_type find_first_not_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2063
void assign(size_type n, T value)
Definition basic_string.h:788
const_reverse_iterator crbegin() const
Definition basic_string.h:437
iterator insert(const_iterator position, T value)
Definition basic_string.h:937
etl::ibasic_string< T > & insert(size_type position, const_pointer s, size_type n)
Definition basic_string.h:1239
ibasic_string & replace(size_type position, size_type length_, const ibasic_string &str)
Definition basic_string.h:1599
ibasic_string(T *p_buffer_, size_type MAX_SIZE_)
Constructor.
Definition basic_string.h:2290
etl::ibasic_string< T > & insert(size_type position, size_type n, value_type c)
Definition basic_string.h:1253
const_reverse_iterator rend() const
Definition basic_string.h:428
size_type find_last_not_of(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:2115
const_pointer data_end() const
Definition basic_string.h:626
void assign(const etl::ibasic_string< T > &other)
Definition basic_string.h:636
const_iterator cend() const
Definition basic_string.h:392
const_pointer c_str() const
Return a pointer to a C string.
Definition basic_string.h:1336
void assign(const_pointer other, size_type length_)
Definition basic_string.h:729
void resize(size_type new_size, T value)
Definition basic_string.h:466
ETL_CONSTEXPR const_pointer data() const
Definition basic_string.h:608
const_reference front() const
Definition basic_string.h:572
pointer data()
Definition basic_string.h:599
size_type find_first_not_of(value_type c, size_type position=0) const
Definition basic_string.h:2094
ibasic_string & append(size_type n, T c)
Definition basic_string.h:914
size_type find_first_not_of(const ibasic_string< T > &str, size_type position=0) const
Definition basic_string.h:2042
size_type find_last_of(value_type c, size_type position=npos) const
Definition basic_string.h:2012
size_type copy(pointer dest, size_type count, size_type pos=0) const
Definition basic_string.h:1347
ibasic_string & append(const ibasic_string &str)
Definition basic_string.h:855
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:1682
reference front()
Definition basic_string.h:563
reference back()
Definition basic_string.h:581
const_iterator cbegin() const
Definition basic_string.h:383
void initialise()
Initialise the string.
Definition basic_string.h:2299
ibasic_string & operator+=(const ibasic_string &rhs)
+= operator.
Definition basic_string.h:2225
void trim_to_terminator()
Definition basic_string.h:2275
void uninitialized_resize(size_type new_size)
Definition basic_string.h:497
ibasic_string & append(const T *str, size_type n)
Definition basic_string.h:903
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:1879
size_type rfind(const_pointer s, size_type position, size_type length_) const
Definition basic_string.h:1538
size_type find_first_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:1913
int compare(const ibasic_string &str) const
Compare with string.
Definition basic_string.h:1812
const_iterator end() const
Definition basic_string.h:374
iterator erase(const_iterator i_element)
Definition basic_string.h:1295
etl::ibasic_string< T > & insert(size_type position, const_pointer s)
Definition basic_string.h:1225
void fill(T value)
Definition basic_string.h:510
void repair_buffer(T *p_buffer_)
Fix the internal pointers after a low level memory copy.
Definition basic_string.h:2312
void assign(const_pointer other)
Definition basic_string.h:703
Definition basic_string.h:167
void set_secure()
Sets the 'secure' flag to the requested state.
Definition basic_string.h:269
bool is_secure() const
Gets the 'secure' state flag.
Definition basic_string.h:277
const size_type CAPACITY
The maximum number of elements in the string.
Definition basic_string.h:312
bool full() const
Definition basic_string.h:203
~string_base()
Destructor.
Definition basic_string.h:307
ETL_DEPRECATED bool truncated() const
Definition basic_string.h:242
void set_truncated(bool status)
Sets the 'truncated' flag.
Definition basic_string.h:298
size_type max_size() const
Definition basic_string.h:221
string_base(size_type max_size_)
Constructor.
Definition basic_string.h:288
void clear_truncated()
Clears the 'truncated' flag.
Definition basic_string.h:259
size_type length() const
Definition basic_string.h:185
size_type current_size
The current number of elements in the string.
Definition basic_string.h:311
size_type available() const
Definition basic_string.h:230
bool empty() const
Definition basic_string.h:194
size_type capacity() const
Definition basic_string.h:212
bool is_truncated() const
Definition basic_string.h:251
size_type size() const
Definition basic_string.h:176
Definition basic_string.h:84
Definition basic_string.h:70
Definition basic_string.h:112
Definition basic_string.h:98
Definition basic_string.h:126
Definition binary.h:353
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
Definition exception.h:47
Definition integral_limits.h:516
bitset_ext
Definition absolute.h:38
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:693
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:705
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:654
ETL_CONSTEXPR14 size_t strlen(const T *t)
Alternative strlen for all character types.
Definition char_traits.h:285
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:642
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:666
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:681
Definition compare.h:51
pair holds two objects of arbitrary type
Definition utility.h:164