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 - 2025 (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 "comms/Assert.h"
16
17#include <algorithm>
18#include <initializer_list>
19#include <iterator>
20#include <string>
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 : m_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 m_vec.clear();
51 std::fill_n(std::back_inserter(m_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 m_vec.clear();
66 std::copy_n(other.cbegin() + pos, countLimit, std::back_inserter(m_vec));
67 endString();
68 }
69
70 void assign(const TChar* str, std::size_t count)
71 {
72 m_vec.clear();
73 auto countLimit = std::min(count, capacity());
74 while ((m_vec.size() < countLimit) && (*str != Ends)) {
75 m_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 m_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 m_vec[pos];
108 }
109
110 const TChar& operator[](std::size_t pos) const
111 {
112 return m_vec[pos];
113 }
114
115 TChar& front()
116 {
117 COMMS_ASSERT(!empty());
118 return m_vec.front();
119 }
120
121 const TChar& front() const
122 {
123 COMMS_ASSERT(!empty());
124 return m_vec.front();
125 }
126
127 TChar& back()
128 {
129 COMMS_ASSERT(!empty());
130 return m_vec[size() - 1];
131 }
132
133 const TChar& back() const
134 {
135 COMMS_ASSERT(!empty());
136 return m_vec[size() - 1];
137 }
138
139 const TChar* data() const
140 {
141 COMMS_ASSERT(!m_vec.empty());
142 return m_vec.data();
143 }
144
145 TChar* begin()
146 {
147 return m_vec.begin();
148 }
149
150 const TChar* cbegin() const
151 {
152 return m_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(!m_vec.empty());
173 return m_vec.size() - 1;
174 }
175
176 std::size_t capacity() const
177 {
178 return m_vec.capacity() - 1;
179 }
180
181 void clear()
182 {
183 m_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 m_vec.insert(m_vec.begin() + idx, count, ch);
191 }
192
193 void insert(std::size_t idx, const TChar* str)
194 {
195 COMMS_ASSERT(idx <= size());
196 m_vec.insert(m_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 m_vec.insert(m_vec.begin() + idx, str, endStr);
204 }
205
206 void insert(std::size_t idx, const StaticStringBase& other)
207 {
208 COMMS_ASSERT(idx <= size());
209 m_vec.insert(m_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 m_vec.insert(m_vec.begin() + idx, begIter, endIter);
219 }
220
221 TChar* insert(const TChar* pos, TChar ch)
222 {
223 return m_vec.insert(pos, ch);
224 }
225
226 TChar* insert(const TChar* pos, std::size_t count, TChar ch)
227 {
228 return m_vec.insert(pos, count, ch);
229 }
230
231 template <typename TIter>
232 TChar* insert(const TChar* pos, TIter first, TIter last)
233 {
234 return m_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 m_vec.erase(begIter, endIter);
243 COMMS_ASSERT(!m_vec.empty()); // Must contain '\0'
244 }
245
246 TChar* erase(const TChar* pos)
247 {
248 return m_vec.erase(pos, pos + 1);
249 }
250
251 TChar* erase(const TChar* first, const TChar* last)
252 {
253 return m_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 m_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 m_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 m_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 m_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 m_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 m_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 m_vec.erase(first + fillDist, last);
413 return;
414 }
415
416 m_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 m_vec.erase(cbegin() + count, cend());
436 COMMS_ASSERT(m_vec[size()] == Ends);
437 COMMS_ASSERT(size() == count);
438 return;
439 }
440
441 m_vec.insert(end(), count - size(), ch);
442 }
443
444 void swap(StaticStringBase& other)
445 {
446 m_vec.swap(other.m_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 = &m_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 = &m_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 = m_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 = m_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 = m_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 m_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> m_vec;
764};
765
766template <typename TChar, std::size_t TSize>
767struct StaticStringStorageBase
768{
769 using StorageType = std::array<TChar, TSize>;
770 StorageType m_data;
771};
772
773} // namespace details
774
784template <std::size_t TSize, typename TChar = char>
786 public details::StaticStringStorageBase<TChar, TSize + 1>,
787 public details::StaticStringBase<TChar>
788{
789 using StorageBase = details::StaticStringStorageBase<TChar, TSize + 1>;
790 using Base = details::StaticStringBase<TChar>;
791
792public:
794 using value_type = TChar;
796 using size_type = std::size_t;
798 using difference_type = typename StorageBase::StorageType::difference_type;
806 using const_pointer = const value_type*;
812 using reverse_iterator = std::reverse_iterator<iterator>;
814 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
815
817 static const decltype(Base::npos) npos = Base::npos;
818
822 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
823 {
824 }
825
829 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
830 {
831 assign(count, ch);
832 }
833
837 template <std::size_t TOtherSize>
840 size_type pos,
841 size_type count = npos)
842 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
843 {
844 assign(other, pos, count);
845 }
846
850 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
851 {
852 assign(str, count);
853 }
854
858 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
859 {
860 assign(str);
861 }
862
865 template <typename TIter>
866 StaticString(TIter first, TIter last)
867 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
868 {
869 assign(first, last);
870 }
871
875 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
876 {
877 assign(other);
878 }
879
882 template <std::size_t TOtherSize>
884 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
885 {
886 assign(other);
887 }
888
891 StaticString(std::initializer_list<value_type> init)
892 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
893 {
894 assign(init.begin(), init.end());
895 }
896
900 {
901 return assign(other);
902 }
903
906 template <std::size_t TOtherSize>
908 {
909 return assign(other);
910 }
911
915 {
916 return assign(str);
917 }
918
922 {
923 return assign(1, ch);
924 }
925
928 StaticString& operator=(std::initializer_list<value_type> init)
929 {
930 return assign(init);
931 }
932
936 {
937 Base::assign(count, ch);
938 return *this;
939 }
940
943 template <typename TOtherSize>
945 {
946 if (&other != this) {
947 Base::assign(other);
948 }
949 return *this;
950 }
951
954 template <std::size_t TOtherSize>
956 {
957 Base::assign(other);
958 return *this;
959 }
960
963 template <std::size_t TOtherSize>
966 size_type pos,
967 size_type count = npos)
968 {
969 Base::assign(other, pos, count);
970 return *this;
971 }
972
976 {
977 Base::assign(str, count);
978 return *this;
979 }
980
984 {
985 Base::assign(str);
986 return *this;
987 }
988
991 template <typename TIter>
992 StaticString& assign(TIter first, TIter last)
993 {
994 Base::assign(first, last);
995 return *this;
996 }
997
1000 StaticString& assign(std::initializer_list<value_type> init)
1001 {
1002 return assign(init.begin(), init.end());
1003 }
1004
1010 {
1011 return Base::at(pos);
1012 }
1013
1019 {
1020 return Base::at(pos);
1021 }
1022
1026 {
1027 return Base::operator[](pos);
1028 }
1029
1033 {
1034 return Base::operator[](pos);
1035 }
1036
1041 {
1042 return Base::front();
1043 }
1044
1049 {
1050 return Base::front();
1051 }
1052
1057 {
1058 return Base::back();
1059 }
1060
1065 {
1066 return Base::back();
1067 }
1068
1072 {
1073 return Base::data();
1074 }
1075
1079 {
1080 return data();
1081 }
1082
1086 {
1087 return Base::begin();
1088 }
1089
1093 {
1094 return cbegin();
1095 }
1096
1100 {
1101 return Base::cbegin();
1102 }
1103
1107 {
1108 return Base::end();
1109 }
1110
1114 {
1115 return cend();
1116 }
1117
1121 {
1122 return Base::cend();
1123 }
1124
1128 {
1129 return reverse_iterator(end());
1130 }
1131
1135 {
1136 return crbegin();
1137 }
1138
1142 {
1143 return reverse_iterator(cend());
1144 }
1145
1149 {
1150 return reverse_iterator(begin());
1151 }
1152
1156 {
1157 return crend();
1158 }
1159
1163 {
1164 return reverse_iterator(cbegin());
1165 }
1166
1169 bool empty() const
1170 {
1171 return Base::empty();
1172 }
1173
1177 {
1178 return Base::size();
1179 }
1180
1184 {
1185 return size();
1186 }
1187
1192 {
1193 return capacity();
1194 }
1195
1200 {
1201 }
1202
1207 {
1208 return Base::capacity();
1209 }
1210
1215 {
1216 }
1217
1220 void clear()
1221 {
1222 Base::clear();
1223 }
1224
1228 {
1229 Base::insert(idx, count, ch);
1230 return *this;
1231 }
1232
1236 {
1237 Base::insert(idx, str);
1238 return *this;
1239 }
1240
1244 {
1245 Base::insert(idx, str, count);
1246 return *this;
1247 }
1248
1251 template <std::size_t TAnySize>
1253 {
1254 Base::insert(idx, str);
1255 return *this;
1256 }
1257
1260 template <std::size_t TAnySize>
1262 size_type idx,
1264 size_type str_idx,
1265 size_type count = npos)
1266 {
1267 Base::insert(idx, str, str_idx, count);
1268 return *this;
1269 }
1270
1274 {
1275 return Base::insert(pos, ch);
1276 }
1277
1281 {
1282 return Base::insert(pos, count, ch);
1283 }
1284
1287 template <typename TIter>
1288 iterator insert(const_iterator pos, TIter first, TIter last)
1289 {
1290 return Base::insert(pos, first, last);
1291 }
1292
1295 iterator insert(const_iterator pos, std::initializer_list<value_type> init)
1296 {
1297 return insert(pos, init.begin(), init.end());
1298 }
1299
1302 StaticString& erase(std::size_t idx, std::size_t count = npos)
1303 {
1304 Base::erase(idx, count);
1305 return *this;
1306 }
1307
1311 {
1312 return Base::erase(pos);
1313 }
1314
1318 {
1319 return Base::erase(first, last);
1320 }
1321
1325 {
1326 Base::push_back(ch);
1327 }
1328
1333 {
1334 Base::pop_back();
1335 }
1336
1340 {
1341 return insert(size(), count, ch);
1342 }
1343
1346 template <std::size_t TAnySize>
1348 {
1349 return insert(size(), other);
1350 }
1351
1354 template <std::size_t TAnySize>
1356 const StaticString<TAnySize, TChar>& other,
1357 size_type pos,
1358 size_type count = npos)
1359 {
1360 return insert(size(), other, pos, count);
1361 }
1362
1365 StaticString& append(const TChar* str, size_type count)
1366 {
1367 return insert(size(), str, count);
1368 }
1369
1372 StaticString& append(const TChar* str)
1373 {
1374 return insert(size(), str);
1375 }
1376
1379 template <typename TIter>
1380 StaticString& append(TIter first, TIter last)
1381 {
1382 insert(end(), first, last);
1383 return *this;
1384 }
1385
1388 StaticString& append(std::initializer_list<value_type> init)
1389 {
1390 insert(end(), init.begin(), init.end());
1391 return *this;
1392 }
1393
1396 template <std::size_t TAnySize>
1398 {
1399 return append(other);
1400 }
1401
1405 {
1406 return append(1U, ch);
1407 }
1408
1412 {
1413 return append(str);
1414 }
1415
1418 StaticString& operator+=(std::initializer_list<value_type> init)
1419 {
1420 return append(init);
1421 }
1422
1425 template <std::size_t TAnySize>
1427 {
1428 return compare(0, size(), other);
1429 }
1430
1433 template <std::size_t TAnySize>
1435 size_type pos,
1436 size_type count,
1437 const StaticString<TAnySize, TChar>& other) const
1438 {
1439 return compare(pos, count, other, 0, other.size());
1440 }
1441
1444 template <std::size_t TAnySize>
1446 size_type pos1,
1447 size_type count1,
1448 const StaticString<TAnySize, TChar>& other,
1449 size_type pos2,
1450 size_type count2 = npos) const
1451 {
1452 return Base::compare(pos1, count1, other, pos2, count2);
1453 }
1454
1457 int compare(const_pointer str) const
1458 {
1459 return compare(0, size(), str);
1460 }
1461
1464 int compare(size_type pos, size_type count, const_pointer str) const
1465 {
1466 return Base::compare(pos, count, str);
1467 }
1468
1471 int compare(size_type pos, size_type count1, const_pointer str, size_type count2) const
1472 {
1473 return Base::compare(pos, count1, str, count2);
1474 }
1475
1478 template <std::size_t TAnySize>
1480 size_type pos,
1481 size_type count,
1482 const StaticString<TAnySize, TChar>& other)
1483 {
1484 COMMS_ASSERT(pos <= size());
1485 auto begIter = begin() + pos;
1486 auto remCount = static_cast<std::size_t>(std::distance(begIter, end()));
1487 auto endIter = begIter + std::min(count, remCount);
1488 return replace(begIter, endIter, other.begin(), other.end());
1489 }
1490
1493 template <std::size_t TAnySize>
1495 const_iterator first,
1496 const_iterator last,
1497 const StaticString<TAnySize, TChar>& other)
1498 {
1499 return replace(first, last, other.begin(), other.end());
1500 }
1501
1504 template <std::size_t TAnySize>
1506 size_type pos,
1507 size_type count,
1508 const StaticString<TAnySize, TChar>& other,
1509 size_type pos2,
1510 size_type count2 = npos)
1511 {
1512 COMMS_ASSERT(pos <= size());
1513 auto begIter = begin() + pos;
1514 auto remCount = static_cast<std::size_t>(std::distance(begIter, end()));
1515 auto endIter = begIter + std::min(count, remCount);
1516
1517 COMMS_ASSERT(pos2 <= other.size());
1518 auto begIter2 = other.begin() + pos2;
1519 auto remCount2 = static_cast<std::size_t>(std::distance(begIter2, other.end()));
1520 auto endIter2 = begIter2 + std::min(count2, remCount2);
1521
1522 return replace(begIter, endIter, begIter2, endIter2);
1523 }
1524
1527 template <typename TIter>
1529 const_iterator first,
1530 const_iterator last,
1531 TIter first2,
1532 TIter last2)
1533 {
1534 Base::replace(first, last, first2, last2);
1535 return *this;
1536 }
1537
1541 size_type pos,
1542 size_type count,
1543 const_pointer str,
1544 size_type count2)
1545 {
1546 COMMS_ASSERT(pos <= size());
1547 auto begIter = cbegin() + pos;
1548 auto endIter = begIter + std::min(count, size() - pos);
1549 return replace(begIter, endIter, str, str + count2);
1550 }
1551
1555 const_iterator first,
1556 const_iterator last,
1557 const_pointer str,
1558 size_type count2)
1559 {
1560 return replace(first, last, str, str + count2);
1561 }
1562
1566 size_type pos,
1567 size_type count,
1568 const_pointer str)
1569 {
1570 COMMS_ASSERT(pos <= size());
1571 auto begIter = cbegin() + pos;
1572 auto endIter = begIter + std::min(count, size() - pos);
1573 return replace(begIter, endIter, str);
1574 }
1575
1579 const_iterator first,
1580 const_iterator last,
1581 const_pointer str)
1582 {
1583 Base::replace(first, last, str);
1584 return *this;
1585 }
1586
1590 size_type pos,
1591 size_type count,
1592 size_type count2,
1593 value_type ch)
1594 {
1595 COMMS_ASSERT(pos <= size());
1596 auto begIter = cbegin() + pos;
1597 auto endIter = begIter + std::min(count, size() - pos);
1598 return replace(begIter, endIter, count2, ch);
1599 }
1600
1604 const_iterator first,
1605 const_iterator last,
1606 size_type count2,
1607 value_type ch)
1608 {
1609 Base::replace(first, last, count2, ch);
1610 return *this;
1611 }
1612
1616 const_iterator first,
1617 const_iterator last,
1618 std::initializer_list<value_type> init)
1619 {
1620 return replace(first, last, init.begin(), init.end());
1621 }
1622
1626 {
1627 COMMS_ASSERT(pos <= size());
1628 auto begIter = cbegin() + pos;
1629 auto endIter = begIter + std::min(count, size() - pos);
1630 return StaticString(cbegin() + pos, endIter);
1631 }
1632
1635 size_type copy(pointer dest, size_type count, size_type pos = 0) const
1636 {
1637 return Base::copy(dest, count, pos);
1638 }
1639
1642 void resize(size_type count)
1643 {
1644 Base::resize(count);
1645 }
1646
1650 {
1651 Base::resize(count, ch);
1652 }
1653
1656 template <std::size_t TAnySize>
1658 {
1659 Base::swap(other);
1660 }
1661
1664 template <std::size_t TAnySize>
1666 {
1667 COMMS_ASSERT(pos <= size());
1668 return find(str.cbegin(), pos, str.size());
1669 }
1670
1674 {
1675 return Base::find(str, pos, count);
1676 }
1677
1681 {
1682 return Base::find(str, pos);
1683 }
1684
1688 {
1689 return Base::find(ch, pos);
1690 }
1691
1694 template <std::size_t TAnySize>
1696 {
1697 return rfind(str.cbegin(), pos, str.size());
1698 }
1699
1703 {
1704 return Base::rfind(str, pos, count);
1705 }
1706
1710 {
1711 return Base::rfind(str, pos);
1712 }
1713
1717 {
1718 return Base::rfind(ch, pos);
1719 }
1720
1723 template <std::size_t TAnySize>
1725 {
1726 COMMS_ASSERT(pos <= size());
1727 return find_first_of(str.cbegin(), pos, str.size());
1728 }
1729
1733 {
1734 return Base::find_first_of(str, pos, count);
1735 }
1736
1740 {
1741 return Base::find_first_of(str, pos);
1742 }
1743
1747 {
1748 return find(ch, pos);
1749 }
1750
1753 template <std::size_t TAnySize>
1755 {
1756 COMMS_ASSERT(pos <= size());
1757 return find_first_not_of(str.cbegin(), pos, str.size());
1758 }
1759
1763 {
1764 return Base::find_first_not_of(str, pos, count);
1765 }
1766
1770 {
1771 return Base::find_first_not_of(str, pos);
1772 }
1773
1777 {
1778 return Base::find_first_not_of(ch, pos);
1779 }
1780
1783 template <std::size_t TAnySize>
1785 {
1786 return find_last_of(str.cbegin(), pos, str.size());
1787 }
1788
1792 {
1793 return Base::find_last_of(str, pos, count);
1794 }
1795
1799 {
1800 return Base::find_last_of(str, pos);
1801 }
1802
1806 {
1807 return rfind(ch, pos);
1808 }
1809
1812 template <std::size_t TAnySize>
1814 {
1815 return find_last_not_of(str.cbegin(), pos, str.size());
1816 }
1817
1821 {
1822 return Base::find_last_not_of(str, pos, count);
1823 }
1824
1828 {
1829 return Base::find_last_not_of(str, pos);
1830 }
1831
1835 {
1836 return Base::find_last_not_of(ch, pos);
1837 }
1838
1840 bool operator<(const_pointer str) const
1841 {
1842 return Base::operator<(str);
1843 }
1844
1846 bool operator>(const_pointer str) const
1847 {
1848 return Base::operator>(str);
1849 }
1850
1853 {
1854 return Base::operator==(str);
1855 }
1856};
1857
1861template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1863{
1864 return std::lexicographical_compare(str1.begin(), str1.end(), str2.begin(), str2.end());
1865}
1866
1870template <std::size_t TSize1, typename TChar>
1871bool operator<(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1872{
1873 return (str2 > str1);
1874}
1875
1879template <std::size_t TSize1, typename TChar>
1880bool operator<(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1881{
1882 return str1.operator<(str2);
1883}
1884
1888template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1890{
1891 return !(str2 < str1);
1892}
1893
1897template <std::size_t TSize1, typename TChar>
1898bool operator<=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1899{
1900 return !(str2 < str1);
1901}
1902
1906template <std::size_t TSize1, typename TChar>
1907bool operator<=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1908{
1909 return !(str1 > str2);
1910}
1911
1915template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1917{
1918 return (str2 < str1);
1919}
1920
1924template <std::size_t TSize1, typename TChar>
1925bool operator>(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1926{
1927 return (str2 < str1);
1928}
1929
1933template <std::size_t TSize1, typename TChar>
1934bool operator>(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1935{
1936 return str1.operator<(str2);
1937}
1938
1942template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1944{
1945 return !(str1 < str2);
1946}
1947
1951template <std::size_t TSize1, typename TChar>
1952bool operator>=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1953{
1954 return !(str1 < str2);
1955}
1956
1960template <std::size_t TSize1, typename TChar>
1961bool operator>=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1962{
1963 return !(str1 < str2);
1964}
1965
1969template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1971{
1972 return
1973 (str1.size() == str2.size()) &&
1974 std::equal(str1.begin(), str1.end(), str2.begin());
1975}
1976
1980template <std::size_t TSize1, typename TChar>
1981bool operator==(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1982{
1983 return str2.operator==(str1);
1984}
1985
1989template <std::size_t TSize1, typename TChar>
1990bool operator==(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1991{
1992 return str1.operator==(str2);
1993}
1994
1998template <std::size_t TSize1, std::size_t TSize2, typename TChar>
2000{
2001 return !(str1 == str2);
2002}
2003
2007template <std::size_t TSize1, typename TChar>
2008bool operator!=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
2009{
2010 return !(str2 == str1);
2011}
2012
2016template <std::size_t TSize1, typename TChar>
2017bool operator!=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
2018{
2019 return !(str1 == str2);
2020}
2021
2022namespace details
2023{
2024
2025template <typename T>
2026struct IsStaticString
2027{
2028 static const bool Value = false;
2029};
2030
2031template <std::size_t TSize>
2032struct IsStaticString<comms::util::StaticString<TSize> >
2033{
2034 static const bool Value = true;
2035};
2036
2037} // namespace details
2038
2042template <typename T>
2043static constexpr bool isStaticString()
2044{
2045 return details::IsStaticString<T>::Value;
2046}
2047
2048} // namespace util
2049
2050} // namespace comms
2051
2052namespace std
2053{
2054
2058template <std::size_t TSize1, std::size_t TSize2, typename TChar>
2063
2064} // namespace std
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:168
Contains various compiler related definitions.
Contains comms::util::StaticVector class.
Replacement to std::string when no dynamic memory allocation is allowed.
Definition StaticString.h:788
size_type rfind(value_type ch, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1716
int compare(size_type pos, size_type count, const StaticString< TAnySize, TChar > &other) const
Compares two strings.
Definition StaticString.h:1434
const_iterator end() const
Returns an iterator to the end.
Definition StaticString.h:1113
const_iterator begin() const
Returns an iterator to the beginning.
Definition StaticString.h:1092
bool operator!=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Inequality compare between the strings.
Definition StaticString.h:1999
const_reference at(size_type pos) const
Access specified character with bounds checking.
Definition StaticString.h:1018
size_type find_last_of(const_pointer str, size_type pos, size_type count) const
Find last occurrence of characters.
Definition StaticString.h:1791
const_pointer const_iterator
Type of the const iterator.
Definition StaticString.h:810
const_reference back() const
Accesses the last character.
Definition StaticString.h:1064
const_iterator cend() const
Returns an iterator to the end.
Definition StaticString.h:1120
void swap(comms::util::StaticString< TSize1, TChar > &str1, comms::util::StaticString< TSize2, TChar > &str2)
Specializes the std::swap algorithm.
Definition StaticString.h:2059
StaticString & replace(size_type pos, size_type count, const_pointer str)
Replaces specified portion of a string.
Definition StaticString.h:1565
reference at(size_type pos)
Access specified character with bounds checking.
Definition StaticString.h:1009
size_type size() const
returns the number of characters.
Definition StaticString.h:1176
StaticString & operator+=(std::initializer_list< value_type > init)
Appends characters to the end.
Definition StaticString.h:1418
size_type copy(pointer dest, size_type count, size_type pos=0) const
Copies characters.
Definition StaticString.h:1635
size_type find_first_not_of(const_pointer str, size_type pos, size_type count) const
Find first absence of characters.
Definition StaticString.h:1762
StaticString & assign(TIter first, TIter last)
Assign characters to a string.
Definition StaticString.h:992
bool operator<=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1898
bool operator>(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1916
StaticString & append(std::initializer_list< value_type > init)
Appends characters to the end.
Definition StaticString.h:1388
size_type rfind(const_pointer str, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1709
StaticString(TIter first, TIter last)
Constructor variant.
Definition StaticString.h:866
void clear()
Clears the contents.
Definition StaticString.h:1220
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition StaticString.h:1155
const_pointer data() const
Returns a pointer to the first character of a string.
Definition StaticString.h:1071
std::size_t size_type
Type used for size information.
Definition StaticString.h:796
static constexpr bool isStaticString()
Compile time check whether the provided type is a variant of comms::util::StaticString.
Definition StaticString.h:2043
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition StaticString.h:1099
size_type rfind(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1695
bool operator<=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1889
const_reference operator[](size_type pos) const
Access specified character without bounds checking.
Definition StaticString.h:1032
StaticString & operator+=(value_type ch)
Appends characters to the end.
Definition StaticString.h:1404
StaticString & replace(const_iterator first, const_iterator last, size_type count2, value_type ch)
Replaces specified portion of a string.
Definition StaticString.h:1603
StaticString & replace(const_iterator first, const_iterator last, const_pointer str, size_type count2)
Replaces specified portion of a string.
Definition StaticString.h:1554
size_type find_last_not_of(value_type ch, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1834
size_type find_last_of(const_pointer str, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1798
StaticString & assign(const StaticString< TOtherSize, TChar > &other)
Assign characters to a string.
Definition StaticString.h:955
const value_type * const_pointer
Const pointer to single character.
Definition StaticString.h:806
StaticString & append(const TChar *str, size_type count)
Appends characters to the end.
Definition StaticString.h:1365
static const decltype(Base::npos) npos
Same as std::string::npos.
Definition StaticString.h:817
bool operator<(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1840
size_type find_last_not_of(const_pointer str, size_type pos, size_type count) const
Find last absence of characters.
Definition StaticString.h:1820
bool operator>=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1952
StaticString(const StaticString< TOtherSize, TChar > &other, size_type pos, size_type count=npos)
Constructor variant.
Definition StaticString.h:838
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:1505
void swap(StaticString< TAnySize, TChar > &other)
Swaps the contents of two strings.
Definition StaticString.h:1657
size_type find(const_pointer str, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1680
StaticString & replace(const_iterator first, const_iterator last, const_pointer str)
Replaces specified portion of a string.
Definition StaticString.h:1578
StaticString & replace(size_type pos, size_type count, size_type count2, value_type ch)
Replaces specified portion of a string.
Definition StaticString.h:1589
size_type find_first_of(const_pointer str, size_type pos, size_type count) const
Find first occurrence of characters.
Definition StaticString.h:1732
StaticString & insert(size_type idx, const StaticString< TAnySize, TChar > &str)
Inserts characters.
Definition StaticString.h:1252
iterator insert(const_iterator pos, std::initializer_list< value_type > init)
Inserts characters.
Definition StaticString.h:1295
size_type length() const
returns the number of characters.
Definition StaticString.h:1183
bool operator>(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1846
bool operator==(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1852
size_type find_first_of(const_pointer str, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1739
const_pointer c_str() const
Returns a non-modifiable standard C character array version of the string.
Definition StaticString.h:1078
StaticString substr(size_type pos=0, size_type count=npos) const
Returns a substring.
Definition StaticString.h:1625
bool operator<(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1871
StaticString & assign(std::initializer_list< value_type > init)
Assign characters to a string.
Definition StaticString.h:1000
void push_back(value_type ch)
Appends a character to the end.
Definition StaticString.h:1324
StaticString & assign(const StaticString< TOtherSize, TChar > &other, size_type pos, size_type count=npos)
Assign characters to a string.
Definition StaticString.h:964
const_reference front() const
Accesses the first character.
Definition StaticString.h:1048
size_type find_first_of(value_type ch, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1746
StaticString & insert(size_type idx, size_type count, value_type ch)
Inserts characters.
Definition StaticString.h:1227
StaticString(const_pointer str, size_type count)
Constructor variant.
Definition StaticString.h:849
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition StaticString.h:1134
bool operator<(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1862
StaticString & append(const StaticString< TAnySize, TChar > &other)
Appends characters to the end.
Definition StaticString.h:1347
StaticString & append(const TChar *str)
Appends characters to the end.
Definition StaticString.h:1372
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition StaticString.h:1141
size_type find_last_of(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1784
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:1445
StaticString & insert(size_type idx, const_pointer str, size_type count)
Inserts characters.
Definition StaticString.h:1243
size_type find_last_of(value_type ch, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1805
size_type find(const_pointer str, size_type pos, size_type count) const
Find characters in the string.
Definition StaticString.h:1673
bool operator>(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1925
StaticString & erase(std::size_t idx, std::size_t count=npos)
Removes characters.
Definition StaticString.h:1302
StaticString & insert(size_type idx, const StaticString< TAnySize, TChar > &str, size_type str_idx, size_type count=npos)
Inserts characters.
Definition StaticString.h:1261
StaticString & operator=(const_pointer str)
Assignment operator.
Definition StaticString.h:914
StaticString & assign(const_pointer str)
Assign characters to a string.
Definition StaticString.h:983
size_type find(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1665
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition StaticString.h:1148
int compare(const_pointer str) const
Compares two strings.
Definition StaticString.h:1457
size_type find_first_not_of(value_type ch, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1776
bool operator>(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1934
StaticString & assign(size_type count, value_type ch)
Assign characters to a string.
Definition StaticString.h:935
size_type find_last_not_of(const_pointer str, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1827
StaticString & replace(const_iterator first, const_iterator last, std::initializer_list< value_type > init)
Replaces specified portion of a string.
Definition StaticString.h:1615
StaticString(std::initializer_list< value_type > init)
Constructor variant.
Definition StaticString.h:891
bool empty() const
Checks whether the string is empty.
Definition StaticString.h:1169
StaticString & assign(const StaticString &other)
Assign characters to a string.
Definition StaticString.h:944
bool operator!=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Inequality compare between the strings.
Definition StaticString.h:2008
value_type & reference
Reference to single character.
Definition StaticString.h:800
StaticString()
Default constructor.
Definition StaticString.h:821
StaticString & append(const StaticString< TAnySize, TChar > &other, size_type pos, size_type count=npos)
Appends characters to the end.
Definition StaticString.h:1355
StaticString & replace(const_iterator first, const_iterator last, const StaticString< TAnySize, TChar > &other)
Replaces specified portion of a string.
Definition StaticString.h:1494
StaticString & operator=(std::initializer_list< value_type > init)
Assignment operator.
Definition StaticString.h:928
StaticString & insert(size_type idx, const_pointer str)
Inserts characters.
Definition StaticString.h:1235
StaticString & operator=(const StaticString< TOtherSize, TChar > &other)
Copy assignment from string of different capacity.
Definition StaticString.h:907
iterator insert(const_iterator pos, size_type count, value_type ch)
Inserts characters.
Definition StaticString.h:1280
StaticString & operator=(value_type ch)
Assignment operator.
Definition StaticString.h:921
reference operator[](size_type pos)
Access specified character without bounds checking.
Definition StaticString.h:1025
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition StaticString.h:1127
size_type find(value_type ch, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1687
void reserve(size_type)
Reserves storage.
Definition StaticString.h:1199
StaticString & replace(size_type pos, size_type count, const_pointer str, size_type count2)
Replaces specified portion of a string.
Definition StaticString.h:1540
const_reverse_iterator crend() const
Returns a reverse iterator to the end.
Definition StaticString.h:1162
bool operator>=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1943
StaticString & assign(const_pointer str, size_type count)
Assign characters to a string.
Definition StaticString.h:975
std::reverse_iterator< iterator > reverse_iterator
Type of the reverse iterator.
Definition StaticString.h:812
TChar value_type
Type of single character.
Definition StaticString.h:794
bool operator==(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1970
StaticString(size_type count, value_type ch)
Constructor variant.
Definition StaticString.h:828
int compare(size_type pos, size_type count1, const_pointer str, size_type count2) const
Compares two strings.
Definition StaticString.h:1471
iterator insert(const_iterator pos, value_type ch)
Inserts characters.
Definition StaticString.h:1273
void shrink_to_fit()
Reduces memory usage by freeing unused memory.
Definition StaticString.h:1214
reference front()
Accesses the first character.
Definition StaticString.h:1040
StaticString(const StaticString &other)
Copy constructor.
Definition StaticString.h:874
bool operator<(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1880
bool operator==(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Equality compare between the strings.
Definition StaticString.h:1981
std::reverse_iterator< const_iterator > const_reverse_iterator
Type of the const reverse iterator.
Definition StaticString.h:814
StaticString & append(TIter first, TIter last)
Appends characters to the end.
Definition StaticString.h:1380
size_type rfind(const_pointer str, size_type pos, size_type count) const
Find the last occurrence of the substring.
Definition StaticString.h:1702
StaticString & append(size_type count, value_type ch)
Appends characters to the end.
Definition StaticString.h:1339
StaticString & operator+=(const StaticString< TAnySize, TChar > &other)
Appends characters to the end.
Definition StaticString.h:1397
typename StorageBase::StorageType::difference_type difference_type
Type used in pointer arithmetics.
Definition StaticString.h:798
StaticString & replace(size_type pos, size_type count, const StaticString< TAnySize, TChar > &other)
Replaces specified portion of a string.
Definition StaticString.h:1479
size_type find_first_not_of(const_pointer str, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1769
bool operator==(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Equality compare between the strings.
Definition StaticString.h:1990
bool operator<=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1907
void resize(size_type count, value_type ch)
Changes the number of characters stored.
Definition StaticString.h:1649
StaticString & replace(const_iterator first, const_iterator last, TIter first2, TIter last2)
Replaces specified portion of a string.
Definition StaticString.h:1528
bool operator>=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1961
StaticString & operator+=(const_pointer str)
Appends characters to the end.
Definition StaticString.h:1411
iterator end()
Returns an iterator to the end.
Definition StaticString.h:1106
void pop_back()
Removes the last character.
Definition StaticString.h:1332
pointer iterator
Type of the iterator.
Definition StaticString.h:808
iterator insert(const_iterator pos, TIter first, TIter last)
Inserts characters.
Definition StaticString.h:1288
const value_type & const_reference
Const reference to single character.
Definition StaticString.h:802
iterator erase(const_iterator first, const_iterator last)
Removes characters.
Definition StaticString.h:1317
StaticString(const_pointer str)
Constructor variant.
Definition StaticString.h:857
bool operator!=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Inequality compare between the strings.
Definition StaticString.h:2017
size_type find_last_not_of(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1813
iterator begin()
Returns an iterator to the beginning.
Definition StaticString.h:1085
StaticString(const StaticString< TOtherSize, TChar > &other)
Copy constructor variant.
Definition StaticString.h:883
int compare(const StaticString< TAnySize, TChar > &other) const
Compares two strings.
Definition StaticString.h:1426
int compare(size_type pos, size_type count, const_pointer str) const
Compares two strings.
Definition StaticString.h:1464
size_type max_size() const
Returns the maximum number of characters.
Definition StaticString.h:1191
size_type find_first_not_of(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1754
value_type * pointer
Pointer to single character.
Definition StaticString.h:804
iterator erase(const_iterator pos)
Removes characters.
Definition StaticString.h:1310
reference back()
Accesses the last character.
Definition StaticString.h:1056
void resize(size_type count)
Changes the number of characters stored.
Definition StaticString.h:1642
StaticString & operator=(const StaticString &other)
Copy assignment.
Definition StaticString.h:899
size_type find_first_of(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1724
size_type capacity() const
returns the number of characters that can be held in currently allocated storage.
Definition StaticString.h:1206
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.