COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
StaticString.h
Go to the documentation of this file.
1//
2// Copyright 2015 - 2024 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
10
11#pragma once
12
13#include <algorithm>
14#include <iterator>
15#include <string>
16#include <initializer_list>
17
19#include "comms/Assert.h"
20#include "StaticVector.h"
21
22namespace comms
23{
24
25namespace util
26{
27
28namespace details
29{
30
31template <typename TChar>
32class StaticStringBase
33{
34 using VecType = StaticVectorBase<TChar>;
35 using CellType = typename VecType::CellType;
36protected:
37
38 static const auto npos = static_cast<std::size_t>(-1);
39
40 StaticStringBase(TChar* buf, std::size_t cap)
41 : vec_(reinterpret_cast<CellType*>(buf), cap)
42 {
43 endString();
44 }
45
46 void assign(std::size_t count, TChar ch)
47 {
48 COMMS_ASSERT(count <= capacity());
49 auto countLimit = std::min(count, capacity());
50 vec_.clear();
51 std::fill_n(std::back_inserter(vec_), countLimit, ch);
52 endString();
53 }
54
55 void assign(const StaticStringBase& other)
56 {
57 assign(other, 0, other.size());
58 }
59
60 void assign(const StaticStringBase& other, std::size_t pos, std::size_t count)
61 {
62 COMMS_ASSERT(&other != this);
63 auto updatedCount = std::min(other.size() - pos, count);
64 auto countLimit = std::min(updatedCount, capacity());
65 vec_.clear();
66 std::copy_n(other.cbegin() + pos, countLimit, std::back_inserter(vec_));
67 endString();
68 }
69
70 void assign(const TChar* str, std::size_t count)
71 {
72 vec_.clear();
73 auto countLimit = std::min(count, capacity());
74 while ((vec_.size() < countLimit) && (*str != Ends)) {
75 vec_.push_back(*str);
76 ++str;
77 }
78 endString();
79 }
80
81 void assign(const TChar* str)
82 {
83 assign(str, capacity());
84 }
85
86 template <typename TIter>
87 void assign(TIter first, TIter last)
88 {
89 vec_.assign(first, last);
90 endString();
91 }
92
93 TChar& at(std::size_t pos)
94 {
95 COMMS_ASSERT(pos < size());
96 return operator[](pos);
97 }
98
99 const TChar& at(std::size_t pos) const
100 {
101 COMMS_ASSERT(pos < size());
102 return operator[](pos);
103 }
104
105 TChar& operator[](std::size_t pos)
106 {
107 return vec_[pos];
108 }
109
110 const TChar& operator[](std::size_t pos) const
111 {
112 return vec_[pos];
113 }
114
115 TChar& front()
116 {
117 COMMS_ASSERT(!empty());
118 return vec_.front();
119 }
120
121 const TChar& front() const
122 {
123 COMMS_ASSERT(!empty());
124 return vec_.front();
125 }
126
127 TChar& back()
128 {
129 COMMS_ASSERT(!empty());
130 return vec_[size() - 1];
131 }
132
133 const TChar& back() const
134 {
135 COMMS_ASSERT(!empty());
136 return vec_[size() - 1];
137 }
138
139 const TChar* data() const
140 {
141 COMMS_ASSERT(!vec_.empty());
142 return vec_.data();
143 }
144
145 TChar* begin()
146 {
147 return vec_.begin();
148 }
149
150 const TChar* cbegin() const
151 {
152 return vec_.cbegin();
153 }
154
155 TChar* end()
156 {
157 return begin() + size();
158 }
159
160 const TChar* cend() const
161 {
162 return cbegin() + size();
163 }
164
165 bool empty() const
166 {
167 return size() == 0;
168 }
169
170 std::size_t size() const
171 {
172 COMMS_ASSERT(!vec_.empty());
173 return vec_.size() - 1;
174 }
175
176 std::size_t capacity() const
177 {
178 return vec_.capacity() - 1;
179 }
180
181 void clear()
182 {
183 vec_.clear();
184 endString();
185 }
186
187 void insert(std::size_t idx, std::size_t count, TChar ch)
188 {
189 COMMS_ASSERT(idx <= size());
190 vec_.insert(vec_.begin() + idx, count, ch);
191 }
192
193 void insert(std::size_t idx, const TChar* str)
194 {
195 COMMS_ASSERT(idx <= size());
196 vec_.insert(vec_.begin() + idx, str, str + strlen(str));
197 }
198
199 void insert(std::size_t idx, const TChar* str, std::size_t count)
200 {
201 COMMS_ASSERT(idx <= size());
202 auto endStr = str + count;
203 vec_.insert(vec_.begin() + idx, str, endStr);
204 }
205
206 void insert(std::size_t idx, const StaticStringBase& other)
207 {
208 COMMS_ASSERT(idx <= size());
209 vec_.insert(vec_.begin() + idx, other.cbegin(), other.cend());
210 }
211
212 void insert(std::size_t idx, const StaticStringBase& str, std::size_t str_idx, std::size_t count)
213 {
214 COMMS_ASSERT(idx <= size());
215 COMMS_ASSERT(str_idx < str.size());
216 auto begIter = str.cbegin() + str_idx;
217 auto endIter = begIter + std::min((str.size() - str_idx), count);
218 vec_.insert(vec_.begin() + idx, begIter, endIter);
219 }
220
221 TChar* insert(const TChar* pos, TChar ch)
222 {
223 return vec_.insert(pos, ch);
224 }
225
226 TChar* insert(const TChar* pos, std::size_t count, TChar ch)
227 {
228 return vec_.insert(pos, count, ch);
229 }
230
231 template <typename TIter>
232 TChar* insert(const TChar* pos, TIter first, TIter last)
233 {
234 return vec_.insert(pos, first, last);
235 }
236
237 void erase(std::size_t idx, std::size_t count)
238 {
239 COMMS_ASSERT(idx < size());
240 auto begIter = begin() + idx;
241 auto endIter = begIter + std::min(count, size() - idx);
242 vec_.erase(begIter, endIter);
243 COMMS_ASSERT(!vec_.empty()); // Must contain '\0'
244 }
245
246 TChar* erase(const TChar* pos)
247 {
248 return vec_.erase(pos, pos + 1);
249 }
250
251 TChar* erase(const TChar* first, const TChar* last)
252 {
253 return vec_.erase(first, last);
254 }
255
256 void push_back(TChar ch)
257 {
258 static constexpr bool The_string_is_full = false;
259 static_cast<void>(The_string_is_full);
260 COMMS_ASSERT((size() < capacity()) || The_string_is_full);
261 vec_.insert(end(), ch);
262 }
263
264 void pop_back()
265 {
266 static constexpr bool The_string_is_empty = false;
267 static_cast<void>(The_string_is_empty);
268 COMMS_ASSERT((!empty()) || The_string_is_empty);
269 vec_.erase(end() - 1, end());
270 }
271
272 int compare(
273 std::size_t pos1,
274 std::size_t count1,
275 const StaticStringBase& other,
276 std::size_t pos2,
277 std::size_t count2) const
278 {
279 COMMS_ASSERT(pos1 <= size());
280 COMMS_ASSERT(pos2 <= other.size());
281 count1 = std::min(count1, size() - pos1);
282 count2 = std::min(count2, other.size() - pos2);
283 auto minCount = std::min(count1, count2);
284 for (auto idx = 0U; idx < minCount; ++idx) {
285 auto thisCh = (*this)[pos1 + idx];
286 auto otherCh = other[pos2 + idx];
287 auto diff = static_cast<int>(thisCh) - static_cast<int>(otherCh);
288 if (diff != 0) {
289 return diff;
290 }
291 }
292
293 return static_cast<int>(count1) - static_cast<int>(count2);
294 }
295
296 int compare(std::size_t pos, std::size_t count, const TChar* str) const
297 {
298 COMMS_ASSERT(pos <= size());
299 count = std::min(count, size() - pos);
300 for (auto idx = 0U; idx < count; ++idx) {
301 auto ch = (*this)[pos + idx];
302 auto diff = static_cast<int>(ch) - static_cast<int>(*str);
303 if (diff != 0) {
304 return diff;
305 }
306
307 if (*str == Ends) {
308 return 1;
309 }
310 ++str;
311 }
312
313 if (*str != Ends) {
314 return 0 - static_cast<int>(*str);
315 }
316
317 return 0;
318 }
319
320 int compare(
321 std::size_t pos1,
322 std::size_t count1,
323 const char* str,
324 std::size_t count2) const
325 {
326 COMMS_ASSERT(pos1 <= size());
327 count1 = std::min(count1, size() - pos1);
328 auto minCount = std::min(count1, count2);
329 for (auto idx = 0U; idx < minCount; ++idx) {
330 auto thisCh = (*this)[pos1 + idx];
331 auto diff = static_cast<int>(thisCh) - static_cast<int>(*str);
332 if (diff != 0) {
333 return diff;
334 }
335
336 ++str;
337 }
338
339 return static_cast<int>(count1) - static_cast<int>(count2);
340 }
341
342 template <typename TIter>
343 void replace(
344 const TChar* first,
345 const TChar* last,
346 TIter first2,
347 TIter last2)
348 {
349 COMMS_ASSERT(first <= end());
350 COMMS_ASSERT(last <= end());
351 COMMS_ASSERT(first <= last);
352 auto begIter = begin() + std::distance(cbegin(), first);
353 auto endIter = begin() + std::distance(cbegin(), last);
354 for (auto iter = begIter; iter != endIter; ++iter) {
355 if (last2 <= first2) {
356 vec_.erase(iter, endIter);
357 return;
358 }
359
360 COMMS_GNU_WARNING_PUSH
361#if COMMS_IS_GCC_11_OR_ABOVE
362 COMMS_GNU_WARNING_DISABLE("-Wstringop-overflow")
363#endif // #if COMMS_IS_GCC_12
364 *iter = static_cast<TChar>(*first2); // Wrong warning reported by gcc-12
365 COMMS_GNU_WARNING_POP
366 ++first2;
367 }
368
369 vec_.insert(last, first2, last2);
370 }
371
372 void replace(
373 const TChar* first,
374 const TChar* last,
375 const TChar* str)
376 {
377 COMMS_ASSERT(first <= end());
378 COMMS_ASSERT(last <= end());
379 COMMS_ASSERT(first <= last);
380 auto begIter = begin() + std::distance(cbegin(), first);
381 auto endIter = begin() + std::distance(cbegin(), last);
382 for (auto iter = begIter; iter != endIter; ++iter) {
383 if (*str == Ends) {
384 vec_.erase(iter, endIter);
385 return;
386 }
387
388 *iter = *str;
389 ++str;
390 }
391
392 auto remCapacity = capacity() - size();
393 auto endStr = str + remCapacity;
394 auto lastStrIter = std::find(str, endStr, TChar(Ends));
395 vec_.insert(last, str, lastStrIter);
396 }
397
398 void replace(
399 const TChar* first,
400 const TChar* last,
401 std::size_t count2,
402 TChar ch)
403 {
404 COMMS_ASSERT(first <= end());
405 COMMS_ASSERT(last <= end());
406 COMMS_ASSERT(first <= last);
407 auto dist = static_cast<std::size_t>(std::distance(first, last));
408 auto fillDist = std::min(dist, count2);
409 auto fillIter = begin() + std::distance(cbegin(), first);
410 std::fill_n(fillIter, fillDist, ch);
411 if (count2 <= dist) {
412 vec_.erase(first + fillDist, last);
413 return;
414 }
415
416 vec_.insert(last, count2 - fillDist, ch);
417 }
418
419 std::size_t copy(TChar* dest, std::size_t count, std::size_t pos) const
420 {
421 COMMS_ASSERT(pos <= size());
422 count = std::min(count, size() - pos);
423 std::copy_n(cbegin() + pos, count, dest);
424 return count;
425 }
426
427 void resize(std::size_t count)
428 {
429 resize(count, Ends);
430 }
431
432 void resize(std::size_t count, TChar ch)
433 {
434 if (count <= size()) {
435 vec_.erase(cbegin() + count, cend());
436 COMMS_ASSERT(vec_[size()] == Ends);
437 COMMS_ASSERT(size() == count);
438 return;
439 }
440
441 vec_.insert(end(), count - size(), ch);
442 }
443
444 void swap(StaticStringBase& other)
445 {
446 vec_.swap(other.vec_);
447 }
448
449 std::size_t find(const TChar* str, std::size_t pos, std::size_t count) const
450 {
451 COMMS_ASSERT(pos <= size());
452 auto remCount = size() - pos;
453 if (remCount < count) {
454 return npos;
455 }
456
457 auto maxPos = size() - count;
458 for (auto idx = pos; idx <= maxPos; ++idx) {
459 auto thisStrBeg = &vec_[idx];
460 auto thisStrEnd = thisStrBeg + count;
461 if (std::equal(thisStrBeg, thisStrEnd, str)) {
462 return idx;
463 }
464 }
465 return npos;
466 }
467
468 std::size_t find(const TChar* str, std::size_t pos) const
469 {
470 COMMS_ASSERT(pos <= size());
471 auto maxStrCount = size() - pos;
472 auto maxStrEnd = str + maxStrCount;
473 auto iter = std::find(str, maxStrEnd, TChar(Ends));
474 if (iter == maxStrEnd) {
475 return npos;
476 }
477
478 auto strCount = static_cast<std::size_t>(std::distance(str, iter));
479 return find(str, pos, strCount);
480 }
481
482 std::size_t find(TChar ch, std::size_t pos) const
483 {
484 COMMS_ASSERT(pos <= size());
485 auto begIter = cbegin() + pos;
486 auto iter = std::find(begIter, cend(), ch);
487 if (iter == cend()) {
488 return npos;
489 }
490
491 return static_cast<std::size_t>(std::distance(cbegin(), iter));
492 }
493
494 std::size_t rfind(const TChar* str, std::size_t pos, std::size_t count) const
495 {
496 if ((empty()) || (size() < count)) {
497 return npos;
498 }
499
500 pos = std::min(pos, size() - 1);
501 auto startIdx = static_cast<int>(std::min(pos, size() - count));
502 for (auto idx = startIdx; 0 <= idx; --idx) {
503 auto thisStrBeg = &vec_[static_cast<std::size_t>(idx)];
504 auto thisStrEnd = thisStrBeg + count;
505 if (std::equal(thisStrBeg, thisStrEnd, str)) {
506 return static_cast<std::size_t>(idx);
507 }
508 }
509 return npos;
510 }
511
512 std::size_t rfind(const TChar* str, std::size_t pos) const
513 {
514 return rfind(str, pos, strlen(str));
515 }
516
517 std::size_t rfind(TChar ch, std::size_t pos) const
518 {
519 if (empty()) {
520 return npos;
521 }
522
523 pos = std::min(pos, size() - 1);
524 auto begIter = std::reverse_iterator<const TChar*>(cbegin() + pos + 1);
525 auto endIter = std::reverse_iterator<const TChar*>(cbegin());
526 COMMS_ASSERT(static_cast<std::size_t>(std::distance(begIter, endIter)) == (pos + 1));
527 auto iter = std::find(begIter, endIter, ch);
528 if (iter == endIter) {
529 return npos;
530 }
531
532 return static_cast<std::size_t>(std::distance(iter, endIter)) - 1U;
533 }
534
535 std::size_t find_first_of(const TChar* str, std::size_t pos, std::size_t count) const
536 {
537 if (empty()) {
538 return npos;
539 }
540
541 pos = std::min(pos, size() - 1);
542 auto endStr = str + count;
543 for (auto iter = cbegin() + pos; iter != cend(); ++iter) {
544 auto foundIter = std::find(str, endStr, *iter);
545 if (foundIter != endStr) {
546 return static_cast<std::size_t>(std::distance(cbegin(), iter));
547 }
548 }
549
550 return npos;
551 }
552
553 std::size_t find_first_of(const TChar* str, std::size_t pos) const
554 {
555 return find_first_of(str, pos, strlen(str));
556 }
557
558 std::size_t find_first_not_of(const TChar* str, std::size_t pos, std::size_t count) const
559 {
560 if (empty()) {
561 return npos;
562 }
563
564 pos = std::min(pos, size() - 1);
565 auto endStr = str + count;
566 for (auto iter = cbegin() + pos; iter != cend(); ++iter) {
567 auto found = std::none_of(str, endStr,
568 [iter](TChar ch) -> bool
569 {
570 return *iter == ch;
571 });
572
573 if (found) {
574 return static_cast<std::size_t>(std::distance(cbegin(), iter));
575 }
576 }
577
578 return npos;
579 }
580
581 std::size_t find_first_not_of(const TChar* str, std::size_t pos) const
582 {
583 return find_first_not_of(str, pos, strlen(str));
584 }
585
586 std::size_t find_first_not_of(TChar ch, std::size_t pos) const
587 {
588 if (empty()) {
589 return npos;
590 }
591
592 pos = std::min(pos, size() - 1);
593 auto iter = std::find_if(cbegin() + pos, cend(),
594 [ch](TChar nextCh) -> bool
595 {
596 return ch != nextCh;
597 });
598
599 if (iter == cend()) {
600 return npos;
601 }
602
603 return static_cast<std::size_t>(std::distance(cbegin(), iter));
604 }
605
606 std::size_t find_last_of(const TChar* str, std::size_t pos, std::size_t count) const
607 {
608 if (empty()) {
609 return npos;
610 }
611
612 pos = std::min(pos, size() - 1);
613 auto endStr = str + count;
614
615 auto begIter = std::reverse_iterator<const TChar*>(cbegin() + pos + 1);
616 auto endIter = std::reverse_iterator<const TChar*>(cbegin());
617 for (auto iter = begIter; iter != endIter; ++iter) {
618 auto foundIter = std::find(str, endStr, *iter);
619 if (foundIter != endStr) {
620 return static_cast<std::size_t>(std::distance(iter, endIter)) - 1U;
621 }
622 }
623
624 return npos;
625 }
626
627 std::size_t find_last_of(const TChar* str, std::size_t pos) const
628 {
629 return find_last_of(str, pos, strlen(str));
630 }
631
632 std::size_t find_last_not_of(const TChar* str, std::size_t pos, std::size_t count) const
633 {
634 if (empty()) {
635 return npos;
636 }
637
638 pos = std::min(pos, size() - 1);
639 auto endStr = str + count;
640 auto begIter = std::reverse_iterator<const TChar*>(cbegin() + pos + 1);
641 auto endIter = std::reverse_iterator<const TChar*>(cbegin());
642 for (auto iter = begIter; iter != endIter; ++iter) {
643 auto found = std::none_of(str, endStr,
644 [iter](TChar ch) -> bool
645 {
646 return *iter == ch;
647 });
648
649 if (found) {
650 return static_cast<std::size_t>(std::distance(iter, endIter)) - 1U;
651 }
652 }
653
654 return npos;
655 }
656
657 std::size_t find_last_not_of(const TChar* str, std::size_t pos) const
658 {
659 return find_last_not_of(str, pos, strlen(str));
660 }
661
662 std::size_t find_last_not_of(TChar ch, std::size_t pos) const
663 {
664 if (empty()) {
665 return npos;
666 }
667
668 pos = std::min(pos, size() - 1);
669 auto begIter = std::reverse_iterator<const TChar*>(cbegin() + pos + 1);
670 auto endIter = std::reverse_iterator<const TChar*>(cbegin());
671 auto iter = std::find_if(begIter, endIter,
672 [ch](TChar nextCh) -> bool
673 {
674 return ch != nextCh;
675 });
676
677 if (iter == endIter) {
678 return npos;
679 }
680
681 return static_cast<std::size_t>(std::distance(iter, endIter)) - 1U;
682 }
683
684 bool operator<(const TChar* str) const
685 {
686 for (auto idx = 0U; idx < size(); ++idx) {
687 if (*str == Ends) {
688 return false;
689 }
690
691 auto ch = vec_[idx];
692
693 if (ch < *str) {
694 return true;
695 }
696
697 if (ch != *str) {
698 break;
699 }
700
701 ++str;
702 }
703
704 return *str > Ends;
705 }
706
707 bool operator>(const TChar* str) const
708 {
709 for (auto idx = 0U; idx < size(); ++idx) {
710 if (*str == Ends) {
711 return true;
712 }
713
714 auto ch = vec_[idx];
715 if (*str < ch) {
716 return true;
717 }
718
719 if (ch != *str) {
720 break;
721 }
722
723 ++str;
724 }
725 return false;
726 }
727
728 bool operator==(const TChar* str) const
729 {
730 for (auto idx = 0U; idx < size(); ++idx) {
731 if (*str == Ends) {
732 return false;
733 }
734
735 auto ch = vec_[idx];
736 if (*str != ch) {
737 return false;
738 }
739
740 ++str;
741 }
742
743 return (*str == Ends);
744 }
745
746private:
747 void endString()
748 {
749 vec_.push_back(TChar(Ends));
750 }
751
752 std::size_t strlen(const TChar* str) const
753 {
754 auto* strTmp = str;
755 while (*strTmp != Ends) {
756 ++strTmp;
757
758 }
759 return static_cast<std::size_t>(std::distance(str, strTmp));
760 }
761
762 static const TChar Ends = static_cast<TChar>('\0');
763 StaticVectorBase<TChar> vec_;
764};
765
766template <typename TChar, std::size_t TSize>
767struct StaticStringStorageBase
768{
769 using StorageType = std::array<TChar, TSize>;
770 StorageType data_;
771};
772
773
774} // namespace details
775
785template <std::size_t TSize, typename TChar = char>
787 public details::StaticStringStorageBase<TChar, TSize + 1>,
788 public details::StaticStringBase<TChar>
789{
790 using StorageBase = details::StaticStringStorageBase<TChar, TSize + 1>;
791 using Base = details::StaticStringBase<TChar>;
792
793public:
795 using value_type = TChar;
797 using size_type = std::size_t;
799 using difference_type = typename StorageBase::StorageType::difference_type;
807 using const_pointer = const value_type*;
813 using reverse_iterator = std::reverse_iterator<iterator>;
815 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
816
818 static const decltype(Base::npos) npos = Base::npos;
819
823 : Base(StorageBase::data_.data(), StorageBase::data_.size())
824 {
825 }
826
830 : Base(StorageBase::data_.data(), StorageBase::data_.size())
831 {
832 assign(count, ch);
833 }
834
838 template <std::size_t TOtherSize>
841 size_type pos,
842 size_type count = npos)
843 : Base(StorageBase::data_.data(), StorageBase::data_.size())
844 {
845 assign(other, pos, count);
846 }
847
851 : Base(StorageBase::data_.data(), StorageBase::data_.size())
852 {
853 assign(str, count);
854 }
855
859 : Base(StorageBase::data_.data(), StorageBase::data_.size())
860 {
861 assign(str);
862 }
863
866 template <typename TIter>
867 StaticString(TIter first, TIter last)
868 : Base(StorageBase::data_.data(), StorageBase::data_.size())
869 {
870 assign(first, last);
871 }
872
876 : Base(StorageBase::data_.data(), StorageBase::data_.size())
877 {
878 assign(other);
879 }
880
883 template <std::size_t TOtherSize>
885 : Base(StorageBase::data_.data(), StorageBase::data_.size())
886 {
887 assign(other);
888 }
889
892 StaticString(std::initializer_list<value_type> init)
893 : Base(StorageBase::data_.data(), StorageBase::data_.size())
894 {
895 assign(init.begin(), init.end());
896 }
897
901 {
902 return assign(other);
903 }
904
907 template <std::size_t TOtherSize>
909 {
910 return assign(other);
911 }
912
916 {
917 return assign(str);
918 }
919
923 {
924 return assign(1, ch);
925 }
926
929 StaticString& operator=(std::initializer_list<value_type> init)
930 {
931 return assign(init);
932 }
933
937 {
938 Base::assign(count, ch);
939 return *this;
940 }
941
944 template <typename TOtherSize>
946 {
947 if (&other != this) {
948 Base::assign(other);
949 }
950 return *this;
951 }
952
955 template <std::size_t TOtherSize>
957 {
958 Base::assign(other);
959 return *this;
960 }
961
964 template <std::size_t TOtherSize>
967 size_type pos,
968 size_type count = npos)
969 {
970 Base::assign(other, pos, count);
971 return *this;
972 }
973
977 {
978 Base::assign(str, count);
979 return *this;
980 }
981
985 {
986 Base::assign(str);
987 return *this;
988 }
989
992 template <typename TIter>
993 StaticString& assign(TIter first, TIter last)
994 {
995 Base::assign(first, last);
996 return *this;
997 }
998
1001 StaticString& assign(std::initializer_list<value_type> init)
1002 {
1003 return assign(init.begin(), init.end());
1004 }
1005
1011 {
1012 return Base::at(pos);
1013 }
1014
1020 {
1021 return Base::at(pos);
1022 }
1023
1027 {
1028 return Base::operator[](pos);
1029 }
1030
1034 {
1035 return Base::operator[](pos);
1036 }
1037
1042 {
1043 return Base::front();
1044 }
1045
1050 {
1051 return Base::front();
1052 }
1053
1058 {
1059 return Base::back();
1060 }
1061
1066 {
1067 return Base::back();
1068 }
1069
1073 {
1074 return Base::data();
1075 }
1076
1080 {
1081 return data();
1082 }
1083
1087 {
1088 return Base::begin();
1089 }
1090
1094 {
1095 return cbegin();
1096 }
1097
1101 {
1102 return Base::cbegin();
1103 }
1104
1108 {
1109 return Base::end();
1110 }
1111
1115 {
1116 return cend();
1117 }
1118
1122 {
1123 return Base::cend();
1124 }
1125
1129 {
1130 return reverse_iterator(end());
1131 }
1132
1136 {
1137 return crbegin();
1138 }
1139
1143 {
1144 return reverse_iterator(cend());
1145 }
1146
1150 {
1151 return reverse_iterator(begin());
1152 }
1153
1157 {
1158 return crend();
1159 }
1160
1164 {
1165 return reverse_iterator(cbegin());
1166 }
1167
1170 bool empty() const
1171 {
1172 return Base::empty();
1173 }
1174
1178 {
1179 return Base::size();
1180 }
1181
1185 {
1186 return size();
1187 }
1188
1193 {
1194 return capacity();
1195 }
1196
1201 {
1202 }
1203
1208 {
1209 return Base::capacity();
1210 }
1211
1216 {
1217 }
1218
1221 void clear()
1222 {
1223 Base::clear();
1224 }
1225
1229 {
1230 Base::insert(idx, count, ch);
1231 return *this;
1232 }
1233
1237 {
1238 Base::insert(idx, str);
1239 return *this;
1240 }
1241
1245 {
1246 Base::insert(idx, str, count);
1247 return *this;
1248 }
1249
1252 template <std::size_t TAnySize>
1254 {
1255 Base::insert(idx, str);
1256 return *this;
1257 }
1258
1261 template <std::size_t TAnySize>
1263 size_type idx,
1265 size_type str_idx,
1266 size_type count = npos)
1267 {
1268 Base::insert(idx, str, str_idx, count);
1269 return *this;
1270 }
1271
1275 {
1276 return Base::insert(pos, ch);
1277 }
1278
1282 {
1283 return Base::insert(pos, count, ch);
1284 }
1285
1288 template <typename TIter>
1289 iterator insert(const_iterator pos, TIter first, TIter last)
1290 {
1291 return Base::insert(pos, first, last);
1292 }
1293
1296 iterator insert(const_iterator pos, std::initializer_list<value_type> init)
1297 {
1298 return insert(pos, init.begin(), init.end());
1299 }
1300
1303 StaticString& erase(std::size_t idx, std::size_t count = npos)
1304 {
1305 Base::erase(idx, count);
1306 return *this;
1307 }
1308
1312 {
1313 return Base::erase(pos);
1314 }
1315
1319 {
1320 return Base::erase(first, last);
1321 }
1322
1326 {
1327 Base::push_back(ch);
1328 }
1329
1334 {
1335 Base::pop_back();
1336 }
1337
1341 {
1342 return insert(size(), count, ch);
1343 }
1344
1347 template <std::size_t TAnySize>
1349 {
1350 return insert(size(), other);
1351 }
1352
1355 template <std::size_t TAnySize>
1357 const StaticString<TAnySize, TChar>& other,
1358 size_type pos,
1359 size_type count = npos)
1360 {
1361 return insert(size(), other, pos, count);
1362 }
1363
1366 StaticString& append(const TChar* str, size_type count)
1367 {
1368 return insert(size(), str, count);
1369 }
1370
1373 StaticString& append(const TChar* str)
1374 {
1375 return insert(size(), str);
1376 }
1377
1380 template <typename TIter>
1381 StaticString& append(TIter first, TIter last)
1382 {
1383 insert(end(), first, last);
1384 return *this;
1385 }
1386
1389 StaticString& append(std::initializer_list<value_type> init)
1390 {
1391 insert(end(), init.begin(), init.end());
1392 return *this;
1393 }
1394
1397 template <std::size_t TAnySize>
1399 {
1400 return append(other);
1401 }
1402
1406 {
1407 return append(1U, ch);
1408 }
1409
1413 {
1414 return append(str);
1415 }
1416
1419 StaticString& operator+=(std::initializer_list<value_type> init)
1420 {
1421 return append(init);
1422 }
1423
1426 template <std::size_t TAnySize>
1428 {
1429 return compare(0, size(), other);
1430 }
1431
1434 template <std::size_t TAnySize>
1436 size_type pos,
1437 size_type count,
1438 const StaticString<TAnySize, TChar>& other) const
1439 {
1440 return compare(pos, count, other, 0, other.size());
1441 }
1442
1445 template <std::size_t TAnySize>
1447 size_type pos1,
1448 size_type count1,
1449 const StaticString<TAnySize, TChar>& other,
1450 size_type pos2,
1451 size_type count2 = npos) const
1452 {
1453 return Base::compare(pos1, count1, other, pos2, count2);
1454 }
1455
1458 int compare(const_pointer str) const
1459 {
1460 return compare(0, size(), str);
1461 }
1462
1465 int compare(size_type pos, size_type count, const_pointer str) const
1466 {
1467 return Base::compare(pos, count, str);
1468 }
1469
1472 int compare(size_type pos, size_type count1, const_pointer str, size_type count2) const
1473 {
1474 return Base::compare(pos, count1, str, count2);
1475 }
1476
1479 template <std::size_t TAnySize>
1481 size_type pos,
1482 size_type count,
1483 const StaticString<TAnySize, TChar>& other)
1484 {
1485 COMMS_ASSERT(pos <= size());
1486 auto begIter = begin() + pos;
1487 auto remCount = static_cast<std::size_t>(std::distance(begIter, end()));
1488 auto endIter = begIter + std::min(count, remCount);
1489 return replace(begIter, endIter, other.begin(), other.end());
1490 }
1491
1494 template <std::size_t TAnySize>
1496 const_iterator first,
1497 const_iterator last,
1498 const StaticString<TAnySize, TChar>& other)
1499 {
1500 return replace(first, last, other.begin(), other.end());
1501 }
1502
1505 template <std::size_t TAnySize>
1507 size_type pos,
1508 size_type count,
1509 const StaticString<TAnySize, TChar>& other,
1510 size_type pos2,
1511 size_type count2 = npos)
1512 {
1513 COMMS_ASSERT(pos <= size());
1514 auto begIter = begin() + pos;
1515 auto remCount = static_cast<std::size_t>(std::distance(begIter, end()));
1516 auto endIter = begIter + std::min(count, remCount);
1517
1518 COMMS_ASSERT(pos2 <= other.size());
1519 auto begIter2 = other.begin() + pos2;
1520 auto remCount2 = static_cast<std::size_t>(std::distance(begIter2, other.end()));
1521 auto endIter2 = begIter2 + std::min(count2, remCount2);
1522
1523 return replace(begIter, endIter, begIter2, endIter2);
1524 }
1525
1528 template <typename TIter>
1530 const_iterator first,
1531 const_iterator last,
1532 TIter first2,
1533 TIter last2)
1534 {
1535 Base::replace(first, last, first2, last2);
1536 return *this;
1537 }
1538
1542 size_type pos,
1543 size_type count,
1544 const_pointer str,
1545 size_type count2)
1546 {
1547 COMMS_ASSERT(pos <= size());
1548 auto begIter = cbegin() + pos;
1549 auto endIter = begIter + std::min(count, size() - pos);
1550 return replace(begIter, endIter, str, str + count2);
1551 }
1552
1556 const_iterator first,
1557 const_iterator last,
1558 const_pointer str,
1559 size_type count2)
1560 {
1561 return replace(first, last, str, str + count2);
1562 }
1563
1567 size_type pos,
1568 size_type count,
1569 const_pointer str)
1570 {
1571 COMMS_ASSERT(pos <= size());
1572 auto begIter = cbegin() + pos;
1573 auto endIter = begIter + std::min(count, size() - pos);
1574 return replace(begIter, endIter, str);
1575 }
1576
1580 const_iterator first,
1581 const_iterator last,
1582 const_pointer str)
1583 {
1584 Base::replace(first, last, str);
1585 return *this;
1586 }
1587
1591 size_type pos,
1592 size_type count,
1593 size_type count2,
1594 value_type ch)
1595 {
1596 COMMS_ASSERT(pos <= size());
1597 auto begIter = cbegin() + pos;
1598 auto endIter = begIter + std::min(count, size() - pos);
1599 return replace(begIter, endIter, count2, ch);
1600 }
1601
1605 const_iterator first,
1606 const_iterator last,
1607 size_type count2,
1608 value_type ch)
1609 {
1610 Base::replace(first, last, count2, ch);
1611 return *this;
1612 }
1613
1617 const_iterator first,
1618 const_iterator last,
1619 std::initializer_list<value_type> init)
1620 {
1621 return replace(first, last, init.begin(), init.end());
1622 }
1623
1627 {
1628 COMMS_ASSERT(pos <= size());
1629 auto begIter = cbegin() + pos;
1630 auto endIter = begIter + std::min(count, size() - pos);
1631 return StaticString(cbegin() + pos, endIter);
1632 }
1633
1636 size_type copy(pointer dest, size_type count, size_type pos = 0) const
1637 {
1638 return Base::copy(dest, count, pos);
1639 }
1640
1643 void resize(size_type count)
1644 {
1645 Base::resize(count);
1646 }
1647
1651 {
1652 Base::resize(count, ch);
1653 }
1654
1657 template <std::size_t TAnySize>
1659 {
1660 Base::swap(other);
1661 }
1662
1665 template <std::size_t TAnySize>
1667 {
1668 COMMS_ASSERT(pos <= size());
1669 return find(str.cbegin(), pos, str.size());
1670 }
1671
1675 {
1676 return Base::find(str, pos, count);
1677 }
1678
1682 {
1683 return Base::find(str, pos);
1684 }
1685
1689 {
1690 return Base::find(ch, pos);
1691 }
1692
1695 template <std::size_t TAnySize>
1697 {
1698 return rfind(str.cbegin(), pos, str.size());
1699 }
1700
1704 {
1705 return Base::rfind(str, pos, count);
1706 }
1707
1711 {
1712 return Base::rfind(str, pos);
1713 }
1714
1718 {
1719 return Base::rfind(ch, pos);
1720 }
1721
1724 template <std::size_t TAnySize>
1726 {
1727 COMMS_ASSERT(pos <= size());
1728 return find_first_of(str.cbegin(), pos, str.size());
1729 }
1730
1734 {
1735 return Base::find_first_of(str, pos, count);
1736 }
1737
1741 {
1742 return Base::find_first_of(str, pos);
1743 }
1744
1748 {
1749 return find(ch, pos);
1750 }
1751
1754 template <std::size_t TAnySize>
1756 {
1757 COMMS_ASSERT(pos <= size());
1758 return find_first_not_of(str.cbegin(), pos, str.size());
1759 }
1760
1764 {
1765 return Base::find_first_not_of(str, pos, count);
1766 }
1767
1771 {
1772 return Base::find_first_not_of(str, pos);
1773 }
1774
1778 {
1779 return Base::find_first_not_of(ch, pos);
1780 }
1781
1784 template <std::size_t TAnySize>
1786 {
1787 return find_last_of(str.cbegin(), pos, str.size());
1788 }
1789
1793 {
1794 return Base::find_last_of(str, pos, count);
1795 }
1796
1800 {
1801 return Base::find_last_of(str, pos);
1802 }
1803
1807 {
1808 return rfind(ch, pos);
1809 }
1810
1813 template <std::size_t TAnySize>
1815 {
1816 return find_last_not_of(str.cbegin(), pos, str.size());
1817 }
1818
1822 {
1823 return Base::find_last_not_of(str, pos, count);
1824 }
1825
1829 {
1830 return Base::find_last_not_of(str, pos);
1831 }
1832
1836 {
1837 return Base::find_last_not_of(ch, pos);
1838 }
1839
1841 bool operator<(const_pointer str) const
1842 {
1843 return Base::operator<(str);
1844 }
1845
1847 bool operator>(const_pointer str) const
1848 {
1849 return Base::operator>(str);
1850 }
1851
1854 {
1855 return Base::operator==(str);
1856 }
1857};
1858
1862template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1864{
1865 return std::lexicographical_compare(str1.begin(), str1.end(), str2.begin(), str2.end());
1866}
1867
1871template <std::size_t TSize1, typename TChar>
1872bool operator<(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1873{
1874 return (str2 > str1);
1875}
1876
1880template <std::size_t TSize1, typename TChar>
1881bool operator<(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1882{
1883 return str1.operator<(str2);
1884}
1885
1889template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1891{
1892 return !(str2 < str1);
1893}
1894
1898template <std::size_t TSize1, typename TChar>
1899bool operator<=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1900{
1901 return !(str2 < str1);
1902}
1903
1907template <std::size_t TSize1, typename TChar>
1908bool operator<=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1909{
1910 return !(str1 > str2);
1911}
1912
1916template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1918{
1919 return (str2 < str1);
1920}
1921
1925template <std::size_t TSize1, typename TChar>
1926bool operator>(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1927{
1928 return (str2 < str1);
1929}
1930
1934template <std::size_t TSize1, typename TChar>
1935bool operator>(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1936{
1937 return str1.operator<(str2);
1938}
1939
1943template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1945{
1946 return !(str1 < str2);
1947}
1948
1952template <std::size_t TSize1, typename TChar>
1953bool operator>=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1954{
1955 return !(str1 < str2);
1956}
1957
1961template <std::size_t TSize1, typename TChar>
1962bool operator>=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1963{
1964 return !(str1 < str2);
1965}
1966
1970template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1972{
1973 return
1974 (str1.size() == str2.size()) &&
1975 std::equal(str1.begin(), str1.end(), str2.begin());
1976}
1977
1981template <std::size_t TSize1, typename TChar>
1982bool operator==(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1983{
1984 return str2.operator==(str1);
1985}
1986
1990template <std::size_t TSize1, typename TChar>
1991bool operator==(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1992{
1993 return str1.operator==(str2);
1994}
1995
1999template <std::size_t TSize1, std::size_t TSize2, typename TChar>
2001{
2002 return !(str1 == str2);
2003}
2004
2008template <std::size_t TSize1, typename TChar>
2009bool operator!=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
2010{
2011 return !(str2 == str1);
2012}
2013
2017template <std::size_t TSize1, typename TChar>
2018bool operator!=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
2019{
2020 return !(str1 == str2);
2021}
2022
2023namespace details
2024{
2025
2026
2027template <typename T>
2028struct IsStaticString
2029{
2030 static const bool Value = false;
2031};
2032
2033template <std::size_t TSize>
2034struct IsStaticString<comms::util::StaticString<TSize> >
2035{
2036 static const bool Value = true;
2037};
2038
2039} // namespace details
2040
2044template <typename T>
2045static constexpr bool isStaticString()
2046{
2047 return details::IsStaticString<T>::Value;
2048}
2049
2050} // namespace util
2051
2052} // namespace comms
2053
2054namespace std
2055{
2056
2060template <std::size_t TSize1, std::size_t TSize2, typename TChar>
2065
2066} // namespace std
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
Contains various compiler related definitions.
Contains comms::util::StaticVector class.
Replacement to std::string when no dynamic memory allocation is allowed.
Definition StaticString.h:789
size_type rfind(value_type ch, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1717
int compare(size_type pos, size_type count, const StaticString< TAnySize, TChar > &other) const
Compares two strings.
Definition StaticString.h:1435
const_iterator end() const
Returns an iterator to the end.
Definition StaticString.h:1114
const_iterator begin() const
Returns an iterator to the beginning.
Definition StaticString.h:1093
bool operator!=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Inequality compare between the strings.
Definition StaticString.h:2000
const_reference at(size_type pos) const
Access specified character with bounds checking.
Definition StaticString.h:1019
size_type find_last_of(const_pointer str, size_type pos, size_type count) const
Find last occurrence of characters.
Definition StaticString.h:1792
const_pointer const_iterator
Type of the const iterator.
Definition StaticString.h:811
const_reference back() const
Accesses the last character.
Definition StaticString.h:1065
const_iterator cend() const
Returns an iterator to the end.
Definition StaticString.h:1121
void swap(comms::util::StaticString< TSize1, TChar > &str1, comms::util::StaticString< TSize2, TChar > &str2)
Specializes the std::swap algorithm.
Definition StaticString.h:2061
StaticString & replace(size_type pos, size_type count, const_pointer str)
Replaces specified portion of a string.
Definition StaticString.h:1566
reference at(size_type pos)
Access specified character with bounds checking.
Definition StaticString.h:1010
size_type size() const
returns the number of characters.
Definition StaticString.h:1177
StaticString & operator+=(std::initializer_list< value_type > init)
Appends characters to the end.
Definition StaticString.h:1419
size_type copy(pointer dest, size_type count, size_type pos=0) const
Copies characters.
Definition StaticString.h:1636
size_type find_first_not_of(const_pointer str, size_type pos, size_type count) const
Find first absence of characters.
Definition StaticString.h:1763
StaticString & assign(TIter first, TIter last)
Assign characters to a string.
Definition StaticString.h:993
bool operator<=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1899
bool operator>(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1917
StaticString & append(std::initializer_list< value_type > init)
Appends characters to the end.
Definition StaticString.h:1389
size_type rfind(const_pointer str, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1710
StaticString(TIter first, TIter last)
Constructor variant.
Definition StaticString.h:867
void clear()
Clears the contents.
Definition StaticString.h:1221
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition StaticString.h:1156
const_pointer data() const
Returns a pointer to the first character of a string.
Definition StaticString.h:1072
std::size_t size_type
Type used for size information.
Definition StaticString.h:797
static constexpr bool isStaticString()
Compile time check whether the provided type is a variant of comms::util::StaticString.
Definition StaticString.h:2045
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition StaticString.h:1100
size_type rfind(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1696
bool operator<=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1890
const_reference operator[](size_type pos) const
Access specified character without bounds checking.
Definition StaticString.h:1033
StaticString & operator+=(value_type ch)
Appends characters to the end.
Definition StaticString.h:1405
StaticString & replace(const_iterator first, const_iterator last, size_type count2, value_type ch)
Replaces specified portion of a string.
Definition StaticString.h:1604
StaticString & replace(const_iterator first, const_iterator last, const_pointer str, size_type count2)
Replaces specified portion of a string.
Definition StaticString.h:1555
size_type find_last_not_of(value_type ch, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1835
size_type find_last_of(const_pointer str, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1799
StaticString & assign(const StaticString< TOtherSize, TChar > &other)
Assign characters to a string.
Definition StaticString.h:956
const value_type * const_pointer
Const pointer to single character.
Definition StaticString.h:807
StaticString & append(const TChar *str, size_type count)
Appends characters to the end.
Definition StaticString.h:1366
static const decltype(Base::npos) npos
Same as std::string::npos.
Definition StaticString.h:818
bool operator<(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1841
size_type find_last_not_of(const_pointer str, size_type pos, size_type count) const
Find last absence of characters.
Definition StaticString.h:1821
bool operator>=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1953
StaticString(const StaticString< TOtherSize, TChar > &other, size_type pos, size_type count=npos)
Constructor variant.
Definition StaticString.h:839
StaticString & replace(size_type pos, size_type count, const StaticString< TAnySize, TChar > &other, size_type pos2, size_type count2=npos)
Replaces specified portion of a string.
Definition StaticString.h:1506
void swap(StaticString< TAnySize, TChar > &other)
Swaps the contents of two strings.
Definition StaticString.h:1658
size_type find(const_pointer str, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1681
StaticString & replace(const_iterator first, const_iterator last, const_pointer str)
Replaces specified portion of a string.
Definition StaticString.h:1579
StaticString & replace(size_type pos, size_type count, size_type count2, value_type ch)
Replaces specified portion of a string.
Definition StaticString.h:1590
size_type find_first_of(const_pointer str, size_type pos, size_type count) const
Find first occurrence of characters.
Definition StaticString.h:1733
StaticString & insert(size_type idx, const StaticString< TAnySize, TChar > &str)
Inserts characters.
Definition StaticString.h:1253
iterator insert(const_iterator pos, std::initializer_list< value_type > init)
Inserts characters.
Definition StaticString.h:1296
size_type length() const
returns the number of characters.
Definition StaticString.h:1184
bool operator>(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1847
bool operator==(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1853
size_type find_first_of(const_pointer str, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1740
const_pointer c_str() const
Returns a non-modifiable standard C character array version of the string.
Definition StaticString.h:1079
StaticString substr(size_type pos=0, size_type count=npos) const
Returns a substring.
Definition StaticString.h:1626
bool operator<(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1872
StaticString & assign(std::initializer_list< value_type > init)
Assign characters to a string.
Definition StaticString.h:1001
void push_back(value_type ch)
Appends a character to the end.
Definition StaticString.h:1325
StaticString & assign(const StaticString< TOtherSize, TChar > &other, size_type pos, size_type count=npos)
Assign characters to a string.
Definition StaticString.h:965
const_reference front() const
Accesses the first character.
Definition StaticString.h:1049
size_type find_first_of(value_type ch, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1747
StaticString & insert(size_type idx, size_type count, value_type ch)
Inserts characters.
Definition StaticString.h:1228
StaticString(const_pointer str, size_type count)
Constructor variant.
Definition StaticString.h:850
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition StaticString.h:1135
bool operator<(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1863
StaticString & append(const StaticString< TAnySize, TChar > &other)
Appends characters to the end.
Definition StaticString.h:1348
StaticString & append(const TChar *str)
Appends characters to the end.
Definition StaticString.h:1373
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition StaticString.h:1142
size_type find_last_of(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1785
int compare(size_type pos1, size_type count1, const StaticString< TAnySize, TChar > &other, size_type pos2, size_type count2=npos) const
Compares two strings.
Definition StaticString.h:1446
StaticString & insert(size_type idx, const_pointer str, size_type count)
Inserts characters.
Definition StaticString.h:1244
size_type find_last_of(value_type ch, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1806
size_type find(const_pointer str, size_type pos, size_type count) const
Find characters in the string.
Definition StaticString.h:1674
bool operator>(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1926
StaticString & erase(std::size_t idx, std::size_t count=npos)
Removes characters.
Definition StaticString.h:1303
StaticString & insert(size_type idx, const StaticString< TAnySize, TChar > &str, size_type str_idx, size_type count=npos)
Inserts characters.
Definition StaticString.h:1262
StaticString & operator=(const_pointer str)
Assignment operator.
Definition StaticString.h:915
StaticString & assign(const_pointer str)
Assign characters to a string.
Definition StaticString.h:984
size_type find(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1666
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition StaticString.h:1149
int compare(const_pointer str) const
Compares two strings.
Definition StaticString.h:1458
size_type find_first_not_of(value_type ch, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1777
bool operator>(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1935
StaticString & assign(size_type count, value_type ch)
Assign characters to a string.
Definition StaticString.h:936
size_type find_last_not_of(const_pointer str, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1828
StaticString & replace(const_iterator first, const_iterator last, std::initializer_list< value_type > init)
Replaces specified portion of a string.
Definition StaticString.h:1616
StaticString(std::initializer_list< value_type > init)
Constructor variant.
Definition StaticString.h:892
bool empty() const
Checks whether the string is empty.
Definition StaticString.h:1170
StaticString & assign(const StaticString &other)
Assign characters to a string.
Definition StaticString.h:945
bool operator!=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Inequality compare between the strings.
Definition StaticString.h:2009
value_type & reference
Reference to single character.
Definition StaticString.h:801
StaticString()
Default constructor.
Definition StaticString.h:822
StaticString & append(const StaticString< TAnySize, TChar > &other, size_type pos, size_type count=npos)
Appends characters to the end.
Definition StaticString.h:1356
StaticString & replace(const_iterator first, const_iterator last, const StaticString< TAnySize, TChar > &other)
Replaces specified portion of a string.
Definition StaticString.h:1495
StaticString & operator=(std::initializer_list< value_type > init)
Assignment operator.
Definition StaticString.h:929
StaticString & insert(size_type idx, const_pointer str)
Inserts characters.
Definition StaticString.h:1236
StaticString & operator=(const StaticString< TOtherSize, TChar > &other)
Copy assignment from string of different capacity.
Definition StaticString.h:908
iterator insert(const_iterator pos, size_type count, value_type ch)
Inserts characters.
Definition StaticString.h:1281
StaticString & operator=(value_type ch)
Assignment operator.
Definition StaticString.h:922
reference operator[](size_type pos)
Access specified character without bounds checking.
Definition StaticString.h:1026
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition StaticString.h:1128
size_type find(value_type ch, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1688
void reserve(size_type)
Reserves storage.
Definition StaticString.h:1200
StaticString & replace(size_type pos, size_type count, const_pointer str, size_type count2)
Replaces specified portion of a string.
Definition StaticString.h:1541
const_reverse_iterator crend() const
Returns a reverse iterator to the end.
Definition StaticString.h:1163
bool operator>=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1944
StaticString & assign(const_pointer str, size_type count)
Assign characters to a string.
Definition StaticString.h:976
std::reverse_iterator< iterator > reverse_iterator
Type of the reverse iterator.
Definition StaticString.h:813
TChar value_type
Type of single character.
Definition StaticString.h:795
bool operator==(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1971
StaticString(size_type count, value_type ch)
Constructor variant.
Definition StaticString.h:829
int compare(size_type pos, size_type count1, const_pointer str, size_type count2) const
Compares two strings.
Definition StaticString.h:1472
iterator insert(const_iterator pos, value_type ch)
Inserts characters.
Definition StaticString.h:1274
void shrink_to_fit()
Reduces memory usage by freeing unused memory.
Definition StaticString.h:1215
reference front()
Accesses the first character.
Definition StaticString.h:1041
StaticString(const StaticString &other)
Copy constructor.
Definition StaticString.h:875
bool operator<(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1881
bool operator==(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Equality compare between the strings.
Definition StaticString.h:1982
std::reverse_iterator< const_iterator > const_reverse_iterator
Type of the const reverse iterator.
Definition StaticString.h:815
StaticString & append(TIter first, TIter last)
Appends characters to the end.
Definition StaticString.h:1381
size_type rfind(const_pointer str, size_type pos, size_type count) const
Find the last occurrence of the substring.
Definition StaticString.h:1703
StaticString & append(size_type count, value_type ch)
Appends characters to the end.
Definition StaticString.h:1340
StaticString & operator+=(const StaticString< TAnySize, TChar > &other)
Appends characters to the end.
Definition StaticString.h:1398
typename StorageBase::StorageType::difference_type difference_type
Type used in pointer arithmetics.
Definition StaticString.h:799
StaticString & replace(size_type pos, size_type count, const StaticString< TAnySize, TChar > &other)
Replaces specified portion of a string.
Definition StaticString.h:1480
size_type find_first_not_of(const_pointer str, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1770
bool operator==(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Equality compare between the strings.
Definition StaticString.h:1991
bool operator<=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1908
void resize(size_type count, value_type ch)
Changes the number of characters stored.
Definition StaticString.h:1650
StaticString & replace(const_iterator first, const_iterator last, TIter first2, TIter last2)
Replaces specified portion of a string.
Definition StaticString.h:1529
bool operator>=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1962
StaticString & operator+=(const_pointer str)
Appends characters to the end.
Definition StaticString.h:1412
iterator end()
Returns an iterator to the end.
Definition StaticString.h:1107
void pop_back()
Removes the last character.
Definition StaticString.h:1333
pointer iterator
Type of the iterator.
Definition StaticString.h:809
iterator insert(const_iterator pos, TIter first, TIter last)
Inserts characters.
Definition StaticString.h:1289
const value_type & const_reference
Const reference to single character.
Definition StaticString.h:803
iterator erase(const_iterator first, const_iterator last)
Removes characters.
Definition StaticString.h:1318
StaticString(const_pointer str)
Constructor variant.
Definition StaticString.h:858
bool operator!=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Inequality compare between the strings.
Definition StaticString.h:2018
size_type find_last_not_of(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1814
iterator begin()
Returns an iterator to the beginning.
Definition StaticString.h:1086
StaticString(const StaticString< TOtherSize, TChar > &other)
Copy constructor variant.
Definition StaticString.h:884
int compare(const StaticString< TAnySize, TChar > &other) const
Compares two strings.
Definition StaticString.h:1427
int compare(size_type pos, size_type count, const_pointer str) const
Compares two strings.
Definition StaticString.h:1465
size_type max_size() const
Returns the maximum number of characters.
Definition StaticString.h:1192
size_type find_first_not_of(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1755
value_type * pointer
Pointer to single character.
Definition StaticString.h:805
iterator erase(const_iterator pos)
Removes characters.
Definition StaticString.h:1311
reference back()
Accesses the last character.
Definition StaticString.h:1057
void resize(size_type count)
Changes the number of characters stored.
Definition StaticString.h:1643
StaticString & operator=(const StaticString &other)
Copy assignment.
Definition StaticString.h:900
size_type find_first_of(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1725
size_type capacity() const
returns the number of characters that can be held in currently allocated storage.
Definition StaticString.h:1207
void assign(T &obj, TIter from, TIter to)
Assigns a new value to provided object.
Definition assign.h:39
Main namespace for all classes / functions of COMMS library.
STL namespace.