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 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: MPL-2.0
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
12
13#pragma once
14
15#include "comms/Assert.h"
18
19#include <algorithm>
20#include <array>
21#include <cstddef>
22#include <initializer_list>
23#include <iterator>
24
25namespace comms
26{
27
28namespace util
29{
30
31namespace details
32{
33
34template <typename TChar>
35class StaticStringBase
36{
37 using VecType = StaticVectorBase<TChar>;
38 using CellType = typename VecType::CellType;
39protected:
40
41 static const auto npos = static_cast<std::size_t>(-1);
42
43 StaticStringBase(TChar* buf, std::size_t cap)
44 : m_vec(reinterpret_cast<CellType*>(buf), cap)
45 {
46 endString();
47 }
48
49 void assign(std::size_t count, TChar ch)
50 {
51 COMMS_ASSERT(count <= capacity());
52 auto countLimit = std::min(count, capacity());
53 m_vec.clear();
54 std::fill_n(std::back_inserter(m_vec), countLimit, ch);
55 endString();
56 }
57
58 void assign(const StaticStringBase& other)
59 {
60 assign(other, 0, other.size());
61 }
62
63 void assign(const StaticStringBase& other, std::size_t pos, std::size_t count)
64 {
65 COMMS_ASSERT(&other != this);
66 auto updatedCount = std::min(other.size() - pos, count);
67 auto countLimit = std::min(updatedCount, capacity());
68 m_vec.clear();
69 std::copy_n(other.cbegin() + pos, countLimit, std::back_inserter(m_vec));
70 endString();
71 }
72
73 void assign(const TChar* str, std::size_t count)
74 {
75 m_vec.clear();
76 auto countLimit = std::min(count, capacity());
77 while ((m_vec.size() < countLimit) && (*str != Ends)) {
78 m_vec.push_back(*str);
79 ++str;
80 }
81 endString();
82 }
83
84 void assign(const TChar* str)
85 {
86 assign(str, capacity());
87 }
88
89 template <typename TIter>
90 void assign(TIter first, TIter last)
91 {
92 m_vec.assign(first, last);
93 endString();
94 }
95
96 TChar& at(std::size_t pos)
97 {
98 COMMS_ASSERT(pos < size());
99 return operator[](pos);
100 }
101
102 const TChar& at(std::size_t pos) const
103 {
104 COMMS_ASSERT(pos < size());
105 return operator[](pos);
106 }
107
108 TChar& operator[](std::size_t pos)
109 {
110 return m_vec[pos];
111 }
112
113 const TChar& operator[](std::size_t pos) const
114 {
115 return m_vec[pos];
116 }
117
118 TChar& front()
119 {
120 COMMS_ASSERT(!empty());
121 return m_vec.front();
122 }
123
124 const TChar& front() const
125 {
126 COMMS_ASSERT(!empty());
127 return m_vec.front();
128 }
129
130 TChar& back()
131 {
132 COMMS_ASSERT(!empty());
133 return m_vec[size() - 1];
134 }
135
136 const TChar& back() const
137 {
138 COMMS_ASSERT(!empty());
139 return m_vec[size() - 1];
140 }
141
142 const TChar* data() const
143 {
144 COMMS_ASSERT(!m_vec.empty());
145 return m_vec.data();
146 }
147
148 TChar* begin()
149 {
150 return m_vec.begin();
151 }
152
153 const TChar* cbegin() const
154 {
155 return m_vec.cbegin();
156 }
157
158 TChar* end()
159 {
160 return begin() + size();
161 }
162
163 const TChar* cend() const
164 {
165 return cbegin() + size();
166 }
167
168 bool empty() const
169 {
170 return size() == 0;
171 }
172
173 std::size_t size() const
174 {
175 COMMS_ASSERT(!m_vec.empty());
176 return m_vec.size() - 1;
177 }
178
179 std::size_t capacity() const
180 {
181 return m_vec.capacity() - 1;
182 }
183
184 void clear()
185 {
186 m_vec.clear();
187 endString();
188 }
189
190 void insert(std::size_t idx, std::size_t count, TChar ch)
191 {
192 COMMS_ASSERT(idx <= size());
193 m_vec.insert(m_vec.begin() + idx, count, ch);
194 }
195
196 void insert(std::size_t idx, const TChar* str)
197 {
198 COMMS_ASSERT(idx <= size());
199 m_vec.insert(m_vec.begin() + idx, str, str + strlen(str));
200 }
201
202 void insert(std::size_t idx, const TChar* str, std::size_t count)
203 {
204 COMMS_ASSERT(idx <= size());
205 auto endStr = str + count;
206 m_vec.insert(m_vec.begin() + idx, str, endStr);
207 }
208
209 void insert(std::size_t idx, const StaticStringBase& other)
210 {
211 COMMS_ASSERT(idx <= size());
212 m_vec.insert(m_vec.begin() + idx, other.cbegin(), other.cend());
213 }
214
215 void insert(std::size_t idx, const StaticStringBase& str, std::size_t str_idx, std::size_t count)
216 {
217 COMMS_ASSERT(idx <= size());
218 COMMS_ASSERT(str_idx < str.size());
219 auto begIter = str.cbegin() + str_idx;
220 auto endIter = begIter + std::min((str.size() - str_idx), count);
221 m_vec.insert(m_vec.begin() + idx, begIter, endIter);
222 }
223
224 TChar* insert(const TChar* pos, TChar ch)
225 {
226 return m_vec.insert(pos, ch);
227 }
228
229 TChar* insert(const TChar* pos, std::size_t count, TChar ch)
230 {
231 return m_vec.insert(pos, count, ch);
232 }
233
234 template <typename TIter>
235 TChar* insert(const TChar* pos, TIter first, TIter last)
236 {
237 return m_vec.insert(pos, first, last);
238 }
239
240 void erase(std::size_t idx, std::size_t count)
241 {
242 COMMS_ASSERT(idx < size());
243 auto begIter = begin() + idx;
244 auto endIter = begIter + std::min(count, size() - idx);
245 m_vec.erase(begIter, endIter);
246 COMMS_ASSERT(!m_vec.empty()); // Must contain '\0'
247 }
248
249 TChar* erase(const TChar* pos)
250 {
251 return m_vec.erase(pos, pos + 1);
252 }
253
254 TChar* erase(const TChar* first, const TChar* last)
255 {
256 return m_vec.erase(first, last);
257 }
258
259 void push_back(TChar ch)
260 {
261 static constexpr bool The_string_is_full = false;
262 static_cast<void>(The_string_is_full);
263 COMMS_ASSERT((size() < capacity()) || The_string_is_full);
264 m_vec.insert(end(), ch);
265 }
266
267 void pop_back()
268 {
269 static constexpr bool The_string_is_empty = false;
270 static_cast<void>(The_string_is_empty);
271 COMMS_ASSERT((!empty()) || The_string_is_empty);
272 m_vec.erase(end() - 1, end());
273 }
274
275 int compare(
276 std::size_t pos1,
277 std::size_t count1,
278 const StaticStringBase& other,
279 std::size_t pos2,
280 std::size_t count2) const
281 {
282 COMMS_ASSERT(pos1 <= size());
283 COMMS_ASSERT(pos2 <= other.size());
284 count1 = std::min(count1, size() - pos1);
285 count2 = std::min(count2, other.size() - pos2);
286 auto minCount = std::min(count1, count2);
287 for (auto idx = 0U; idx < minCount; ++idx) {
288 auto thisCh = (*this)[pos1 + idx];
289 auto otherCh = other[pos2 + idx];
290 auto diff = static_cast<int>(thisCh) - static_cast<int>(otherCh);
291 if (diff != 0) {
292 return diff;
293 }
294 }
295
296 return static_cast<int>(count1) - static_cast<int>(count2);
297 }
298
299 int compare(std::size_t pos, std::size_t count, const TChar* str) const
300 {
301 COMMS_ASSERT(pos <= size());
302 count = std::min(count, size() - pos);
303 for (auto idx = 0U; idx < count; ++idx) {
304 auto ch = (*this)[pos + idx];
305 auto diff = static_cast<int>(ch) - static_cast<int>(*str);
306 if (diff != 0) {
307 return diff;
308 }
309
310 if (*str == Ends) {
311 return 1;
312 }
313 ++str;
314 }
315
316 if (*str != Ends) {
317 return 0 - static_cast<int>(*str);
318 }
319
320 return 0;
321 }
322
323 int compare(
324 std::size_t pos1,
325 std::size_t count1,
326 const char* str,
327 std::size_t count2) const
328 {
329 COMMS_ASSERT(pos1 <= size());
330 count1 = std::min(count1, size() - pos1);
331 auto minCount = std::min(count1, count2);
332 for (auto idx = 0U; idx < minCount; ++idx) {
333 auto thisCh = (*this)[pos1 + idx];
334 auto diff = static_cast<int>(thisCh) - static_cast<int>(*str);
335 if (diff != 0) {
336 return diff;
337 }
338
339 ++str;
340 }
341
342 return static_cast<int>(count1) - static_cast<int>(count2);
343 }
344
345 template <typename TIter>
346 void replace(
347 const TChar* first,
348 const TChar* last,
349 TIter first2,
350 TIter last2)
351 {
352 COMMS_ASSERT(first <= end());
353 COMMS_ASSERT(last <= end());
354 COMMS_ASSERT(first <= last);
355 auto begIter = begin() + std::distance(cbegin(), first);
356 auto endIter = begin() + std::distance(cbegin(), last);
357 for (auto iter = begIter; iter != endIter; ++iter) {
358 if (last2 <= first2) {
359 m_vec.erase(iter, endIter);
360 return;
361 }
362
363 COMMS_GNU_WARNING_PUSH
364#if COMMS_IS_GCC_11_OR_ABOVE
365 COMMS_GNU_WARNING_DISABLE("-Wstringop-overflow")
366#endif // #if COMMS_IS_GCC_12
367 *iter = static_cast<TChar>(*first2); // Wrong warning reported by gcc-12
368 COMMS_GNU_WARNING_POP
369 ++first2;
370 }
371
372 m_vec.insert(last, first2, last2);
373 }
374
375 void replace(
376 const TChar* first,
377 const TChar* last,
378 const TChar* str)
379 {
380 COMMS_ASSERT(first <= end());
381 COMMS_ASSERT(last <= end());
382 COMMS_ASSERT(first <= last);
383 auto begIter = begin() + std::distance(cbegin(), first);
384 auto endIter = begin() + std::distance(cbegin(), last);
385 for (auto iter = begIter; iter != endIter; ++iter) {
386 if (*str == Ends) {
387 m_vec.erase(iter, endIter);
388 return;
389 }
390
391 *iter = *str;
392 ++str;
393 }
394
395 auto remCapacity = capacity() - size();
396 auto endStr = str + remCapacity;
397 auto lastStrIter = std::find(str, endStr, TChar(Ends));
398 m_vec.insert(last, str, lastStrIter);
399 }
400
401 void replace(
402 const TChar* first,
403 const TChar* last,
404 std::size_t count2,
405 TChar ch)
406 {
407 COMMS_ASSERT(first <= end());
408 COMMS_ASSERT(last <= end());
409 COMMS_ASSERT(first <= last);
410 auto dist = static_cast<std::size_t>(std::distance(first, last));
411 auto fillDist = std::min(dist, count2);
412 auto fillIter = begin() + std::distance(cbegin(), first);
413 std::fill_n(fillIter, fillDist, ch);
414 if (count2 <= dist) {
415 m_vec.erase(first + fillDist, last);
416 return;
417 }
418
419 m_vec.insert(last, count2 - fillDist, ch);
420 }
421
422 std::size_t copy(TChar* dest, std::size_t count, std::size_t pos) const
423 {
424 COMMS_ASSERT(pos <= size());
425 count = std::min(count, size() - pos);
426 std::copy_n(cbegin() + pos, count, dest);
427 return count;
428 }
429
430 void resize(std::size_t count)
431 {
432 resize(count, Ends);
433 }
434
435 void resize(std::size_t count, TChar ch)
436 {
437 if (count <= size()) {
438 m_vec.erase(cbegin() + count, cend());
439 COMMS_ASSERT(m_vec[size()] == Ends);
440 COMMS_ASSERT(size() == count);
441 return;
442 }
443
444 m_vec.insert(end(), count - size(), ch);
445 }
446
447 void swap(StaticStringBase& other)
448 {
449 m_vec.swap(other.m_vec);
450 }
451
452 std::size_t find(const TChar* str, std::size_t pos, std::size_t count) const
453 {
454 COMMS_ASSERT(pos <= size());
455 auto remCount = size() - pos;
456 if (remCount < count) {
457 return npos;
458 }
459
460 auto maxPos = size() - count;
461 for (auto idx = pos; idx <= maxPos; ++idx) {
462 auto thisStrBeg = &m_vec[idx];
463 auto thisStrEnd = thisStrBeg + count;
464 if (std::equal(thisStrBeg, thisStrEnd, str)) {
465 return idx;
466 }
467 }
468 return npos;
469 }
470
471 std::size_t find(const TChar* str, std::size_t pos) const
472 {
473 COMMS_ASSERT(pos <= size());
474 auto maxStrCount = size() - pos;
475 auto maxStrEnd = str + maxStrCount;
476 auto iter = std::find(str, maxStrEnd, TChar(Ends));
477 if (iter == maxStrEnd) {
478 return npos;
479 }
480
481 auto strCount = static_cast<std::size_t>(std::distance(str, iter));
482 return find(str, pos, strCount);
483 }
484
485 std::size_t find(TChar ch, std::size_t pos) const
486 {
487 COMMS_ASSERT(pos <= size());
488 auto begIter = cbegin() + pos;
489 auto iter = std::find(begIter, cend(), ch);
490 if (iter == cend()) {
491 return npos;
492 }
493
494 return static_cast<std::size_t>(std::distance(cbegin(), iter));
495 }
496
497 std::size_t rfind(const TChar* str, std::size_t pos, std::size_t count) const
498 {
499 if ((empty()) || (size() < count)) {
500 return npos;
501 }
502
503 pos = std::min(pos, size() - 1);
504 auto startIdx = static_cast<int>(std::min(pos, size() - count));
505 for (auto idx = startIdx; 0 <= idx; --idx) {
506 auto thisStrBeg = &m_vec[static_cast<std::size_t>(idx)];
507 auto thisStrEnd = thisStrBeg + count;
508 if (std::equal(thisStrBeg, thisStrEnd, str)) {
509 return static_cast<std::size_t>(idx);
510 }
511 }
512 return npos;
513 }
514
515 std::size_t rfind(const TChar* str, std::size_t pos) const
516 {
517 return rfind(str, pos, strlen(str));
518 }
519
520 std::size_t rfind(TChar ch, std::size_t pos) const
521 {
522 if (empty()) {
523 return npos;
524 }
525
526 pos = std::min(pos, size() - 1);
527 auto begIter = std::reverse_iterator<const TChar*>(cbegin() + pos + 1);
528 auto endIter = std::reverse_iterator<const TChar*>(cbegin());
529 COMMS_ASSERT(static_cast<std::size_t>(std::distance(begIter, endIter)) == (pos + 1));
530 auto iter = std::find(begIter, endIter, ch);
531 if (iter == endIter) {
532 return npos;
533 }
534
535 return static_cast<std::size_t>(std::distance(iter, endIter)) - 1U;
536 }
537
538 std::size_t find_first_of(const TChar* str, std::size_t pos, std::size_t count) const
539 {
540 if (empty()) {
541 return npos;
542 }
543
544 pos = std::min(pos, size() - 1);
545 auto endStr = str + count;
546 for (auto iter = cbegin() + pos; iter != cend(); ++iter) {
547 auto foundIter = std::find(str, endStr, *iter);
548 if (foundIter != endStr) {
549 return static_cast<std::size_t>(std::distance(cbegin(), iter));
550 }
551 }
552
553 return npos;
554 }
555
556 std::size_t find_first_of(const TChar* str, std::size_t pos) const
557 {
558 return find_first_of(str, pos, strlen(str));
559 }
560
561 std::size_t find_first_not_of(const TChar* str, std::size_t pos, std::size_t count) const
562 {
563 if (empty()) {
564 return npos;
565 }
566
567 pos = std::min(pos, size() - 1);
568 auto endStr = str + count;
569 for (auto iter = cbegin() + pos; iter != cend(); ++iter) {
570 auto found = std::none_of(str, endStr,
571 [iter](TChar ch) -> bool
572 {
573 return *iter == ch;
574 });
575
576 if (found) {
577 return static_cast<std::size_t>(std::distance(cbegin(), iter));
578 }
579 }
580
581 return npos;
582 }
583
584 std::size_t find_first_not_of(const TChar* str, std::size_t pos) const
585 {
586 return find_first_not_of(str, pos, strlen(str));
587 }
588
589 std::size_t find_first_not_of(TChar ch, std::size_t pos) const
590 {
591 if (empty()) {
592 return npos;
593 }
594
595 pos = std::min(pos, size() - 1);
596 auto iter = std::find_if(cbegin() + pos, cend(),
597 [ch](TChar nextCh) -> bool
598 {
599 return ch != nextCh;
600 });
601
602 if (iter == cend()) {
603 return npos;
604 }
605
606 return static_cast<std::size_t>(std::distance(cbegin(), iter));
607 }
608
609 std::size_t find_last_of(const TChar* str, std::size_t pos, std::size_t count) const
610 {
611 if (empty()) {
612 return npos;
613 }
614
615 pos = std::min(pos, size() - 1);
616 auto endStr = str + count;
617
618 auto begIter = std::reverse_iterator<const TChar*>(cbegin() + pos + 1);
619 auto endIter = std::reverse_iterator<const TChar*>(cbegin());
620 for (auto iter = begIter; iter != endIter; ++iter) {
621 auto foundIter = std::find(str, endStr, *iter);
622 if (foundIter != endStr) {
623 return static_cast<std::size_t>(std::distance(iter, endIter)) - 1U;
624 }
625 }
626
627 return npos;
628 }
629
630 std::size_t find_last_of(const TChar* str, std::size_t pos) const
631 {
632 return find_last_of(str, pos, strlen(str));
633 }
634
635 std::size_t find_last_not_of(const TChar* str, std::size_t pos, std::size_t count) const
636 {
637 if (empty()) {
638 return npos;
639 }
640
641 pos = std::min(pos, size() - 1);
642 auto endStr = str + count;
643 auto begIter = std::reverse_iterator<const TChar*>(cbegin() + pos + 1);
644 auto endIter = std::reverse_iterator<const TChar*>(cbegin());
645 for (auto iter = begIter; iter != endIter; ++iter) {
646 auto found = std::none_of(str, endStr,
647 [iter](TChar ch) -> bool
648 {
649 return *iter == ch;
650 });
651
652 if (found) {
653 return static_cast<std::size_t>(std::distance(iter, endIter)) - 1U;
654 }
655 }
656
657 return npos;
658 }
659
660 std::size_t find_last_not_of(const TChar* str, std::size_t pos) const
661 {
662 return find_last_not_of(str, pos, strlen(str));
663 }
664
665 std::size_t find_last_not_of(TChar ch, std::size_t pos) const
666 {
667 if (empty()) {
668 return npos;
669 }
670
671 pos = std::min(pos, size() - 1);
672 auto begIter = std::reverse_iterator<const TChar*>(cbegin() + pos + 1);
673 auto endIter = std::reverse_iterator<const TChar*>(cbegin());
674 auto iter = std::find_if(begIter, endIter,
675 [ch](TChar nextCh) -> bool
676 {
677 return ch != nextCh;
678 });
679
680 if (iter == endIter) {
681 return npos;
682 }
683
684 return static_cast<std::size_t>(std::distance(iter, endIter)) - 1U;
685 }
686
687 bool operator<(const TChar* str) const
688 {
689 for (auto idx = 0U; idx < size(); ++idx) {
690 if (*str == Ends) {
691 return false;
692 }
693
694 auto ch = m_vec[idx];
695
696 if (ch < *str) {
697 return true;
698 }
699
700 if (ch != *str) {
701 break;
702 }
703
704 ++str;
705 }
706
707 return *str > Ends;
708 }
709
710 bool operator>(const TChar* str) const
711 {
712 for (auto idx = 0U; idx < size(); ++idx) {
713 if (*str == Ends) {
714 return true;
715 }
716
717 auto ch = m_vec[idx];
718 if (*str < ch) {
719 return true;
720 }
721
722 if (ch != *str) {
723 break;
724 }
725
726 ++str;
727 }
728 return false;
729 }
730
731 bool operator==(const TChar* str) const
732 {
733 for (auto idx = 0U; idx < size(); ++idx) {
734 if (*str == Ends) {
735 return false;
736 }
737
738 auto ch = m_vec[idx];
739 if (*str != ch) {
740 return false;
741 }
742
743 ++str;
744 }
745
746 return (*str == Ends);
747 }
748
749private:
750 void endString()
751 {
752 m_vec.push_back(TChar(Ends));
753 }
754
755 std::size_t strlen(const TChar* str) const
756 {
757 auto* strTmp = str;
758 while (*strTmp != Ends) {
759 ++strTmp;
760
761 }
762 return static_cast<std::size_t>(std::distance(str, strTmp));
763 }
764
765 static const TChar Ends = static_cast<TChar>('\0');
766 StaticVectorBase<TChar> m_vec;
767};
768
769template <typename TChar, std::size_t TSize>
770struct StaticStringStorageBase
771{
772 using StorageType = std::array<TChar, TSize>;
773 StorageType m_data;
774};
775
776} // namespace details
777
787template <std::size_t TSize, typename TChar = char>
789 public details::StaticStringStorageBase<TChar, TSize + 1>,
790 public details::StaticStringBase<TChar>
791{
792 using StorageBase = details::StaticStringStorageBase<TChar, TSize + 1>;
793 using Base = details::StaticStringBase<TChar>;
794
795public:
797 using value_type = TChar;
799 using size_type = std::size_t;
801 using difference_type = typename StorageBase::StorageType::difference_type;
809 using const_pointer = const value_type*;
815 using reverse_iterator = std::reverse_iterator<iterator>;
817 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
818
820 static const decltype(Base::npos) npos = Base::npos;
821
825 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
826 {
827 }
828
832 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
833 {
834 assign(count, ch);
835 }
836
840 template <std::size_t TOtherSize>
843 size_type pos,
844 size_type count = npos)
845 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
846 {
847 assign(other, pos, count);
848 }
849
853 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
854 {
855 assign(str, count);
856 }
857
861 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
862 {
863 assign(str);
864 }
865
868 template <typename TIter>
869 StaticString(TIter first, TIter last)
870 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
871 {
872 assign(first, last);
873 }
874
878 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
879 {
880 assign(other);
881 }
882
885 template <std::size_t TOtherSize>
887 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
888 {
889 assign(other);
890 }
891
894 StaticString(std::initializer_list<value_type> init)
895 : Base(StorageBase::m_data.data(), StorageBase::m_data.size())
896 {
897 assign(init.begin(), init.end());
898 }
899
903 {
904 return assign(other);
905 }
906
909 template <std::size_t TOtherSize>
911 {
912 return assign(other);
913 }
914
918 {
919 return assign(str);
920 }
921
925 {
926 return assign(1, ch);
927 }
928
931 StaticString& operator=(std::initializer_list<value_type> init)
932 {
933 return assign(init);
934 }
935
939 {
940 Base::assign(count, ch);
941 return *this;
942 }
943
946 template <typename TOtherSize>
948 {
949 if (&other != this) {
950 Base::assign(other);
951 }
952 return *this;
953 }
954
957 template <std::size_t TOtherSize>
959 {
960 Base::assign(other);
961 return *this;
962 }
963
966 template <std::size_t TOtherSize>
969 size_type pos,
970 size_type count = npos)
971 {
972 Base::assign(other, pos, count);
973 return *this;
974 }
975
979 {
980 Base::assign(str, count);
981 return *this;
982 }
983
987 {
988 Base::assign(str);
989 return *this;
990 }
991
994 template <typename TIter>
995 StaticString& assign(TIter first, TIter last)
996 {
997 Base::assign(first, last);
998 return *this;
999 }
1000
1003 StaticString& assign(std::initializer_list<value_type> init)
1004 {
1005 return assign(init.begin(), init.end());
1006 }
1007
1013 {
1014 return Base::at(pos);
1015 }
1016
1022 {
1023 return Base::at(pos);
1024 }
1025
1029 {
1030 return Base::operator[](pos);
1031 }
1032
1036 {
1037 return Base::operator[](pos);
1038 }
1039
1044 {
1045 return Base::front();
1046 }
1047
1052 {
1053 return Base::front();
1054 }
1055
1060 {
1061 return Base::back();
1062 }
1063
1068 {
1069 return Base::back();
1070 }
1071
1075 {
1076 return Base::data();
1077 }
1078
1082 {
1083 return data();
1084 }
1085
1089 {
1090 return Base::begin();
1091 }
1092
1096 {
1097 return cbegin();
1098 }
1099
1103 {
1104 return Base::cbegin();
1105 }
1106
1110 {
1111 return Base::end();
1112 }
1113
1117 {
1118 return cend();
1119 }
1120
1124 {
1125 return Base::cend();
1126 }
1127
1131 {
1132 return reverse_iterator(end());
1133 }
1134
1138 {
1139 return crbegin();
1140 }
1141
1145 {
1146 return reverse_iterator(cend());
1147 }
1148
1152 {
1153 return reverse_iterator(begin());
1154 }
1155
1159 {
1160 return crend();
1161 }
1162
1166 {
1167 return reverse_iterator(cbegin());
1168 }
1169
1172 bool empty() const
1173 {
1174 return Base::empty();
1175 }
1176
1180 {
1181 return Base::size();
1182 }
1183
1187 {
1188 return size();
1189 }
1190
1195 {
1196 return capacity();
1197 }
1198
1203 {
1204 }
1205
1210 {
1211 return Base::capacity();
1212 }
1213
1218 {
1219 }
1220
1223 void clear()
1224 {
1225 Base::clear();
1226 }
1227
1231 {
1232 Base::insert(idx, count, ch);
1233 return *this;
1234 }
1235
1239 {
1240 Base::insert(idx, str);
1241 return *this;
1242 }
1243
1247 {
1248 Base::insert(idx, str, count);
1249 return *this;
1250 }
1251
1254 template <std::size_t TAnySize>
1256 {
1257 Base::insert(idx, str);
1258 return *this;
1259 }
1260
1263 template <std::size_t TAnySize>
1265 size_type idx,
1267 size_type str_idx,
1268 size_type count = npos)
1269 {
1270 Base::insert(idx, str, str_idx, count);
1271 return *this;
1272 }
1273
1277 {
1278 return Base::insert(pos, ch);
1279 }
1280
1284 {
1285 return Base::insert(pos, count, ch);
1286 }
1287
1290 template <typename TIter>
1291 iterator insert(const_iterator pos, TIter first, TIter last)
1292 {
1293 return Base::insert(pos, first, last);
1294 }
1295
1298 iterator insert(const_iterator pos, std::initializer_list<value_type> init)
1299 {
1300 return insert(pos, init.begin(), init.end());
1301 }
1302
1305 StaticString& erase(std::size_t idx, std::size_t count = npos)
1306 {
1307 Base::erase(idx, count);
1308 return *this;
1309 }
1310
1314 {
1315 return Base::erase(pos);
1316 }
1317
1321 {
1322 return Base::erase(first, last);
1323 }
1324
1328 {
1329 Base::push_back(ch);
1330 }
1331
1336 {
1337 Base::pop_back();
1338 }
1339
1343 {
1344 return insert(size(), count, ch);
1345 }
1346
1349 template <std::size_t TAnySize>
1351 {
1352 return insert(size(), other);
1353 }
1354
1357 template <std::size_t TAnySize>
1359 const StaticString<TAnySize, TChar>& other,
1360 size_type pos,
1361 size_type count = npos)
1362 {
1363 return insert(size(), other, pos, count);
1364 }
1365
1368 StaticString& append(const TChar* str, size_type count)
1369 {
1370 return insert(size(), str, count);
1371 }
1372
1375 StaticString& append(const TChar* str)
1376 {
1377 return insert(size(), str);
1378 }
1379
1382 template <typename TIter>
1383 StaticString& append(TIter first, TIter last)
1384 {
1385 insert(end(), first, last);
1386 return *this;
1387 }
1388
1391 StaticString& append(std::initializer_list<value_type> init)
1392 {
1393 insert(end(), init.begin(), init.end());
1394 return *this;
1395 }
1396
1399 template <std::size_t TAnySize>
1401 {
1402 return append(other);
1403 }
1404
1408 {
1409 return append(1U, ch);
1410 }
1411
1415 {
1416 return append(str);
1417 }
1418
1421 StaticString& operator+=(std::initializer_list<value_type> init)
1422 {
1423 return append(init);
1424 }
1425
1428 template <std::size_t TAnySize>
1430 {
1431 return compare(0, size(), other);
1432 }
1433
1436 template <std::size_t TAnySize>
1438 size_type pos,
1439 size_type count,
1440 const StaticString<TAnySize, TChar>& other) const
1441 {
1442 return compare(pos, count, other, 0, other.size());
1443 }
1444
1447 template <std::size_t TAnySize>
1449 size_type pos1,
1450 size_type count1,
1451 const StaticString<TAnySize, TChar>& other,
1452 size_type pos2,
1453 size_type count2 = npos) const
1454 {
1455 return Base::compare(pos1, count1, other, pos2, count2);
1456 }
1457
1460 int compare(const_pointer str) const
1461 {
1462 return compare(0, size(), str);
1463 }
1464
1467 int compare(size_type pos, size_type count, const_pointer str) const
1468 {
1469 return Base::compare(pos, count, str);
1470 }
1471
1474 int compare(size_type pos, size_type count1, const_pointer str, size_type count2) const
1475 {
1476 return Base::compare(pos, count1, str, count2);
1477 }
1478
1481 template <std::size_t TAnySize>
1483 size_type pos,
1484 size_type count,
1485 const StaticString<TAnySize, TChar>& other)
1486 {
1487 COMMS_ASSERT(pos <= size());
1488 auto begIter = begin() + pos;
1489 auto remCount = static_cast<std::size_t>(std::distance(begIter, end()));
1490 auto endIter = begIter + std::min(count, remCount);
1491 return replace(begIter, endIter, other.begin(), other.end());
1492 }
1493
1496 template <std::size_t TAnySize>
1498 const_iterator first,
1499 const_iterator last,
1500 const StaticString<TAnySize, TChar>& other)
1501 {
1502 return replace(first, last, other.begin(), other.end());
1503 }
1504
1507 template <std::size_t TAnySize>
1509 size_type pos,
1510 size_type count,
1511 const StaticString<TAnySize, TChar>& other,
1512 size_type pos2,
1513 size_type count2 = npos)
1514 {
1515 COMMS_ASSERT(pos <= size());
1516 auto begIter = begin() + pos;
1517 auto remCount = static_cast<std::size_t>(std::distance(begIter, end()));
1518 auto endIter = begIter + std::min(count, remCount);
1519
1520 COMMS_ASSERT(pos2 <= other.size());
1521 auto begIter2 = other.begin() + pos2;
1522 auto remCount2 = static_cast<std::size_t>(std::distance(begIter2, other.end()));
1523 auto endIter2 = begIter2 + std::min(count2, remCount2);
1524
1525 return replace(begIter, endIter, begIter2, endIter2);
1526 }
1527
1530 template <typename TIter>
1532 const_iterator first,
1533 const_iterator last,
1534 TIter first2,
1535 TIter last2)
1536 {
1537 Base::replace(first, last, first2, last2);
1538 return *this;
1539 }
1540
1544 size_type pos,
1545 size_type count,
1546 const_pointer str,
1547 size_type count2)
1548 {
1549 COMMS_ASSERT(pos <= size());
1550 auto begIter = cbegin() + pos;
1551 auto endIter = begIter + std::min(count, size() - pos);
1552 return replace(begIter, endIter, str, str + count2);
1553 }
1554
1558 const_iterator first,
1559 const_iterator last,
1560 const_pointer str,
1561 size_type count2)
1562 {
1563 return replace(first, last, str, str + count2);
1564 }
1565
1569 size_type pos,
1570 size_type count,
1571 const_pointer str)
1572 {
1573 COMMS_ASSERT(pos <= size());
1574 auto begIter = cbegin() + pos;
1575 auto endIter = begIter + std::min(count, size() - pos);
1576 return replace(begIter, endIter, str);
1577 }
1578
1582 const_iterator first,
1583 const_iterator last,
1584 const_pointer str)
1585 {
1586 Base::replace(first, last, str);
1587 return *this;
1588 }
1589
1593 size_type pos,
1594 size_type count,
1595 size_type count2,
1596 value_type ch)
1597 {
1598 COMMS_ASSERT(pos <= size());
1599 auto begIter = cbegin() + pos;
1600 auto endIter = begIter + std::min(count, size() - pos);
1601 return replace(begIter, endIter, count2, ch);
1602 }
1603
1607 const_iterator first,
1608 const_iterator last,
1609 size_type count2,
1610 value_type ch)
1611 {
1612 Base::replace(first, last, count2, ch);
1613 return *this;
1614 }
1615
1619 const_iterator first,
1620 const_iterator last,
1621 std::initializer_list<value_type> init)
1622 {
1623 return replace(first, last, init.begin(), init.end());
1624 }
1625
1629 {
1630 COMMS_ASSERT(pos <= size());
1631 auto begIter = cbegin() + pos;
1632 auto endIter = begIter + std::min(count, size() - pos);
1633 return StaticString(cbegin() + pos, endIter);
1634 }
1635
1638 size_type copy(pointer dest, size_type count, size_type pos = 0) const
1639 {
1640 return Base::copy(dest, count, pos);
1641 }
1642
1645 void resize(size_type count)
1646 {
1647 Base::resize(count);
1648 }
1649
1653 {
1654 Base::resize(count, ch);
1655 }
1656
1659 template <std::size_t TAnySize>
1661 {
1662 Base::swap(other);
1663 }
1664
1667 template <std::size_t TAnySize>
1669 {
1670 COMMS_ASSERT(pos <= size());
1671 return find(str.cbegin(), pos, str.size());
1672 }
1673
1677 {
1678 return Base::find(str, pos, count);
1679 }
1680
1684 {
1685 return Base::find(str, pos);
1686 }
1687
1691 {
1692 return Base::find(ch, pos);
1693 }
1694
1697 template <std::size_t TAnySize>
1699 {
1700 return rfind(str.cbegin(), pos, str.size());
1701 }
1702
1706 {
1707 return Base::rfind(str, pos, count);
1708 }
1709
1713 {
1714 return Base::rfind(str, pos);
1715 }
1716
1720 {
1721 return Base::rfind(ch, pos);
1722 }
1723
1726 template <std::size_t TAnySize>
1728 {
1729 COMMS_ASSERT(pos <= size());
1730 return find_first_of(str.cbegin(), pos, str.size());
1731 }
1732
1736 {
1737 return Base::find_first_of(str, pos, count);
1738 }
1739
1743 {
1744 return Base::find_first_of(str, pos);
1745 }
1746
1750 {
1751 return find(ch, pos);
1752 }
1753
1756 template <std::size_t TAnySize>
1758 {
1759 COMMS_ASSERT(pos <= size());
1760 return find_first_not_of(str.cbegin(), pos, str.size());
1761 }
1762
1766 {
1767 return Base::find_first_not_of(str, pos, count);
1768 }
1769
1773 {
1774 return Base::find_first_not_of(str, pos);
1775 }
1776
1780 {
1781 return Base::find_first_not_of(ch, pos);
1782 }
1783
1786 template <std::size_t TAnySize>
1788 {
1789 return find_last_of(str.cbegin(), pos, str.size());
1790 }
1791
1795 {
1796 return Base::find_last_of(str, pos, count);
1797 }
1798
1802 {
1803 return Base::find_last_of(str, pos);
1804 }
1805
1809 {
1810 return rfind(ch, pos);
1811 }
1812
1815 template <std::size_t TAnySize>
1817 {
1818 return find_last_not_of(str.cbegin(), pos, str.size());
1819 }
1820
1824 {
1825 return Base::find_last_not_of(str, pos, count);
1826 }
1827
1831 {
1832 return Base::find_last_not_of(str, pos);
1833 }
1834
1838 {
1839 return Base::find_last_not_of(ch, pos);
1840 }
1841
1843 bool operator<(const_pointer str) const
1844 {
1845 return Base::operator<(str);
1846 }
1847
1849 bool operator>(const_pointer str) const
1850 {
1851 return Base::operator>(str);
1852 }
1853
1856 {
1857 return Base::operator==(str);
1858 }
1859};
1860
1864template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1866{
1867 return std::lexicographical_compare(str1.begin(), str1.end(), str2.begin(), str2.end());
1868}
1869
1873template <std::size_t TSize1, typename TChar>
1874bool operator<(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1875{
1876 return (str2 > str1);
1877}
1878
1882template <std::size_t TSize1, typename TChar>
1883bool operator<(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1884{
1885 return str1.operator<(str2);
1886}
1887
1891template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1893{
1894 return !(str2 < str1);
1895}
1896
1900template <std::size_t TSize1, typename TChar>
1901bool operator<=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1902{
1903 return !(str2 < str1);
1904}
1905
1909template <std::size_t TSize1, typename TChar>
1910bool operator<=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1911{
1912 return !(str1 > str2);
1913}
1914
1918template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1920{
1921 return (str2 < str1);
1922}
1923
1927template <std::size_t TSize1, typename TChar>
1928bool operator>(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1929{
1930 return (str2 < str1);
1931}
1932
1936template <std::size_t TSize1, typename TChar>
1937bool operator>(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1938{
1939 return str1.operator<(str2);
1940}
1941
1945template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1947{
1948 return !(str1 < str2);
1949}
1950
1954template <std::size_t TSize1, typename TChar>
1955bool operator>=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1956{
1957 return !(str1 < str2);
1958}
1959
1963template <std::size_t TSize1, typename TChar>
1964bool operator>=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1965{
1966 return !(str1 < str2);
1967}
1968
1972template <std::size_t TSize1, std::size_t TSize2, typename TChar>
1974{
1975 return
1976 (str1.size() == str2.size()) &&
1977 std::equal(str1.begin(), str1.end(), str2.begin());
1978}
1979
1983template <std::size_t TSize1, typename TChar>
1984bool operator==(const TChar* str1, const StaticString<TSize1, TChar>& str2)
1985{
1986 return str2.operator==(str1);
1987}
1988
1992template <std::size_t TSize1, typename TChar>
1993bool operator==(const StaticString<TSize1, TChar>& str1, const TChar* str2)
1994{
1995 return str1.operator==(str2);
1996}
1997
2001template <std::size_t TSize1, std::size_t TSize2, typename TChar>
2003{
2004 return !(str1 == str2);
2005}
2006
2010template <std::size_t TSize1, typename TChar>
2011bool operator!=(const TChar* str1, const StaticString<TSize1, TChar>& str2)
2012{
2013 return !(str2 == str1);
2014}
2015
2019template <std::size_t TSize1, typename TChar>
2020bool operator!=(const StaticString<TSize1, TChar>& str1, const TChar* str2)
2021{
2022 return !(str1 == str2);
2023}
2024
2025namespace details
2026{
2027
2028template <typename T>
2029struct IsStaticString
2030{
2031 static const bool Value = false;
2032};
2033
2034template <std::size_t TSize>
2035struct IsStaticString<comms::util::StaticString<TSize> >
2036{
2037 static const bool Value = true;
2038};
2039
2040} // namespace details
2041
2045template <typename T>
2046static constexpr bool isStaticString()
2047{
2048 return details::IsStaticString<T>::Value;
2049}
2050
2051} // namespace util
2052
2053} // namespace comms
2054
2055namespace std
2056{
2057
2061template <std::size_t TSize1, std::size_t TSize2, typename TChar>
2066
2067} // 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:791
size_type rfind(value_type ch, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1719
int compare(size_type pos, size_type count, const StaticString< TAnySize, TChar > &other) const
Compares two strings.
Definition StaticString.h:1437
const_iterator end() const
Returns an iterator to the end.
Definition StaticString.h:1116
const_iterator begin() const
Returns an iterator to the beginning.
Definition StaticString.h:1095
bool operator!=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Inequality compare between the strings.
Definition StaticString.h:2002
const_reference at(size_type pos) const
Access specified character with bounds checking.
Definition StaticString.h:1021
size_type find_last_of(const_pointer str, size_type pos, size_type count) const
Find last occurrence of characters.
Definition StaticString.h:1794
const_pointer const_iterator
Type of the const iterator.
Definition StaticString.h:813
const_reference back() const
Accesses the last character.
Definition StaticString.h:1067
const_iterator cend() const
Returns an iterator to the end.
Definition StaticString.h:1123
void swap(comms::util::StaticString< TSize1, TChar > &str1, comms::util::StaticString< TSize2, TChar > &str2)
Specializes the std::swap algorithm.
Definition StaticString.h:2062
StaticString & replace(size_type pos, size_type count, const_pointer str)
Replaces specified portion of a string.
Definition StaticString.h:1568
reference at(size_type pos)
Access specified character with bounds checking.
Definition StaticString.h:1012
size_type size() const
returns the number of characters.
Definition StaticString.h:1179
StaticString & operator+=(std::initializer_list< value_type > init)
Appends characters to the end.
Definition StaticString.h:1421
size_type copy(pointer dest, size_type count, size_type pos=0) const
Copies characters.
Definition StaticString.h:1638
size_type find_first_not_of(const_pointer str, size_type pos, size_type count) const
Find first absence of characters.
Definition StaticString.h:1765
StaticString & assign(TIter first, TIter last)
Assign characters to a string.
Definition StaticString.h:995
bool operator<=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1901
bool operator>(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1919
StaticString & append(std::initializer_list< value_type > init)
Appends characters to the end.
Definition StaticString.h:1391
size_type rfind(const_pointer str, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1712
StaticString(TIter first, TIter last)
Constructor variant.
Definition StaticString.h:869
void clear()
Clears the contents.
Definition StaticString.h:1223
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition StaticString.h:1158
const_pointer data() const
Returns a pointer to the first character of a string.
Definition StaticString.h:1074
std::size_t size_type
Type used for size information.
Definition StaticString.h:799
static constexpr bool isStaticString()
Compile time check whether the provided type is a variant of comms::util::StaticString.
Definition StaticString.h:2046
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition StaticString.h:1102
size_type rfind(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find the last occurrence of the substring.
Definition StaticString.h:1698
bool operator<=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1892
const_reference operator[](size_type pos) const
Access specified character without bounds checking.
Definition StaticString.h:1035
StaticString & operator+=(value_type ch)
Appends characters to the end.
Definition StaticString.h:1407
StaticString & replace(const_iterator first, const_iterator last, size_type count2, value_type ch)
Replaces specified portion of a string.
Definition StaticString.h:1606
StaticString & replace(const_iterator first, const_iterator last, const_pointer str, size_type count2)
Replaces specified portion of a string.
Definition StaticString.h:1557
size_type find_last_not_of(value_type ch, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1837
size_type find_last_of(const_pointer str, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1801
StaticString & assign(const StaticString< TOtherSize, TChar > &other)
Assign characters to a string.
Definition StaticString.h:958
const value_type * const_pointer
Const pointer to single character.
Definition StaticString.h:809
StaticString & append(const TChar *str, size_type count)
Appends characters to the end.
Definition StaticString.h:1368
static const decltype(Base::npos) npos
Same as std::string::npos.
Definition StaticString.h:820
bool operator<(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1843
size_type find_last_not_of(const_pointer str, size_type pos, size_type count) const
Find last absence of characters.
Definition StaticString.h:1823
bool operator>=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1955
StaticString(const StaticString< TOtherSize, TChar > &other, size_type pos, size_type count=npos)
Constructor variant.
Definition StaticString.h:841
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:1508
void swap(StaticString< TAnySize, TChar > &other)
Swaps the contents of two strings.
Definition StaticString.h:1660
size_type find(const_pointer str, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1683
StaticString & replace(const_iterator first, const_iterator last, const_pointer str)
Replaces specified portion of a string.
Definition StaticString.h:1581
StaticString & replace(size_type pos, size_type count, size_type count2, value_type ch)
Replaces specified portion of a string.
Definition StaticString.h:1592
size_type find_first_of(const_pointer str, size_type pos, size_type count) const
Find first occurrence of characters.
Definition StaticString.h:1735
StaticString & insert(size_type idx, const StaticString< TAnySize, TChar > &str)
Inserts characters.
Definition StaticString.h:1255
iterator insert(const_iterator pos, std::initializer_list< value_type > init)
Inserts characters.
Definition StaticString.h:1298
size_type length() const
returns the number of characters.
Definition StaticString.h:1186
bool operator>(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1849
bool operator==(const_pointer str) const
Lexicographical compare to other string.
Definition StaticString.h:1855
size_type find_first_of(const_pointer str, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1742
const_pointer c_str() const
Returns a non-modifiable standard C character array version of the string.
Definition StaticString.h:1081
StaticString substr(size_type pos=0, size_type count=npos) const
Returns a substring.
Definition StaticString.h:1628
bool operator<(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1874
StaticString & assign(std::initializer_list< value_type > init)
Assign characters to a string.
Definition StaticString.h:1003
void push_back(value_type ch)
Appends a character to the end.
Definition StaticString.h:1327
StaticString & assign(const StaticString< TOtherSize, TChar > &other, size_type pos, size_type count=npos)
Assign characters to a string.
Definition StaticString.h:967
const_reference front() const
Accesses the first character.
Definition StaticString.h:1051
size_type find_first_of(value_type ch, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1749
StaticString & insert(size_type idx, size_type count, value_type ch)
Inserts characters.
Definition StaticString.h:1230
StaticString(const_pointer str, size_type count)
Constructor variant.
Definition StaticString.h:852
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition StaticString.h:1137
bool operator<(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1865
StaticString & append(const StaticString< TAnySize, TChar > &other)
Appends characters to the end.
Definition StaticString.h:1350
StaticString & append(const TChar *str)
Appends characters to the end.
Definition StaticString.h:1375
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition StaticString.h:1144
size_type find_last_of(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1787
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:1448
StaticString & insert(size_type idx, const_pointer str, size_type count)
Inserts characters.
Definition StaticString.h:1246
size_type find_last_of(value_type ch, size_type pos=npos) const
Find last occurrence of characters.
Definition StaticString.h:1808
size_type find(const_pointer str, size_type pos, size_type count) const
Find characters in the string.
Definition StaticString.h:1676
bool operator>(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1928
StaticString & erase(std::size_t idx, std::size_t count=npos)
Removes characters.
Definition StaticString.h:1305
StaticString & insert(size_type idx, const StaticString< TAnySize, TChar > &str, size_type str_idx, size_type count=npos)
Inserts characters.
Definition StaticString.h:1264
StaticString & operator=(const_pointer str)
Assignment operator.
Definition StaticString.h:917
StaticString & assign(const_pointer str)
Assign characters to a string.
Definition StaticString.h:986
size_type find(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1668
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition StaticString.h:1151
int compare(const_pointer str) const
Compares two strings.
Definition StaticString.h:1460
size_type find_first_not_of(value_type ch, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1779
bool operator>(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1937
StaticString & assign(size_type count, value_type ch)
Assign characters to a string.
Definition StaticString.h:938
size_type find_last_not_of(const_pointer str, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1830
StaticString & replace(const_iterator first, const_iterator last, std::initializer_list< value_type > init)
Replaces specified portion of a string.
Definition StaticString.h:1618
StaticString(std::initializer_list< value_type > init)
Constructor variant.
Definition StaticString.h:894
bool empty() const
Checks whether the string is empty.
Definition StaticString.h:1172
StaticString & assign(const StaticString &other)
Assign characters to a string.
Definition StaticString.h:947
bool operator!=(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Inequality compare between the strings.
Definition StaticString.h:2011
value_type & reference
Reference to single character.
Definition StaticString.h:803
StaticString()
Default constructor.
Definition StaticString.h:824
StaticString & append(const StaticString< TAnySize, TChar > &other, size_type pos, size_type count=npos)
Appends characters to the end.
Definition StaticString.h:1358
StaticString & replace(const_iterator first, const_iterator last, const StaticString< TAnySize, TChar > &other)
Replaces specified portion of a string.
Definition StaticString.h:1497
StaticString & operator=(std::initializer_list< value_type > init)
Assignment operator.
Definition StaticString.h:931
StaticString & insert(size_type idx, const_pointer str)
Inserts characters.
Definition StaticString.h:1238
StaticString & operator=(const StaticString< TOtherSize, TChar > &other)
Copy assignment from string of different capacity.
Definition StaticString.h:910
iterator insert(const_iterator pos, size_type count, value_type ch)
Inserts characters.
Definition StaticString.h:1283
StaticString & operator=(value_type ch)
Assignment operator.
Definition StaticString.h:924
reference operator[](size_type pos)
Access specified character without bounds checking.
Definition StaticString.h:1028
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition StaticString.h:1130
size_type find(value_type ch, size_type pos=0) const
Find characters in the string.
Definition StaticString.h:1690
void reserve(size_type)
Reserves storage.
Definition StaticString.h:1202
StaticString & replace(size_type pos, size_type count, const_pointer str, size_type count2)
Replaces specified portion of a string.
Definition StaticString.h:1543
const_reverse_iterator crend() const
Returns a reverse iterator to the end.
Definition StaticString.h:1165
bool operator>=(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1946
StaticString & assign(const_pointer str, size_type count)
Assign characters to a string.
Definition StaticString.h:978
std::reverse_iterator< iterator > reverse_iterator
Type of the reverse iterator.
Definition StaticString.h:815
TChar value_type
Type of single character.
Definition StaticString.h:797
bool operator==(const StaticString< TSize1, TChar > &str1, const StaticString< TSize2, TChar > &str2)
Lexicographical compare between the strings.
Definition StaticString.h:1973
StaticString(size_type count, value_type ch)
Constructor variant.
Definition StaticString.h:831
int compare(size_type pos, size_type count1, const_pointer str, size_type count2) const
Compares two strings.
Definition StaticString.h:1474
iterator insert(const_iterator pos, value_type ch)
Inserts characters.
Definition StaticString.h:1276
void shrink_to_fit()
Reduces memory usage by freeing unused memory.
Definition StaticString.h:1217
reference front()
Accesses the first character.
Definition StaticString.h:1043
StaticString(const StaticString &other)
Copy constructor.
Definition StaticString.h:877
bool operator<(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1883
bool operator==(const TChar *str1, const StaticString< TSize1, TChar > &str2)
Equality compare between the strings.
Definition StaticString.h:1984
std::reverse_iterator< const_iterator > const_reverse_iterator
Type of the const reverse iterator.
Definition StaticString.h:817
StaticString & append(TIter first, TIter last)
Appends characters to the end.
Definition StaticString.h:1383
size_type rfind(const_pointer str, size_type pos, size_type count) const
Find the last occurrence of the substring.
Definition StaticString.h:1705
StaticString & append(size_type count, value_type ch)
Appends characters to the end.
Definition StaticString.h:1342
StaticString & operator+=(const StaticString< TAnySize, TChar > &other)
Appends characters to the end.
Definition StaticString.h:1400
typename StorageBase::StorageType::difference_type difference_type
Type used in pointer arithmetics.
Definition StaticString.h:801
StaticString & replace(size_type pos, size_type count, const StaticString< TAnySize, TChar > &other)
Replaces specified portion of a string.
Definition StaticString.h:1482
size_type find_first_not_of(const_pointer str, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1772
bool operator==(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Equality compare between the strings.
Definition StaticString.h:1993
bool operator<=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1910
void resize(size_type count, value_type ch)
Changes the number of characters stored.
Definition StaticString.h:1652
StaticString & replace(const_iterator first, const_iterator last, TIter first2, TIter last2)
Replaces specified portion of a string.
Definition StaticString.h:1531
bool operator>=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Lexicographical compare between the strings.
Definition StaticString.h:1964
StaticString & operator+=(const_pointer str)
Appends characters to the end.
Definition StaticString.h:1414
iterator end()
Returns an iterator to the end.
Definition StaticString.h:1109
void pop_back()
Removes the last character.
Definition StaticString.h:1335
pointer iterator
Type of the iterator.
Definition StaticString.h:811
iterator insert(const_iterator pos, TIter first, TIter last)
Inserts characters.
Definition StaticString.h:1291
const value_type & const_reference
Const reference to single character.
Definition StaticString.h:805
iterator erase(const_iterator first, const_iterator last)
Removes characters.
Definition StaticString.h:1320
StaticString(const_pointer str)
Constructor variant.
Definition StaticString.h:860
bool operator!=(const StaticString< TSize1, TChar > &str1, const TChar *str2)
Inequality compare between the strings.
Definition StaticString.h:2020
size_type find_last_not_of(const StaticString< TAnySize, TChar > &str, size_type pos=npos) const
Find last absence of characters.
Definition StaticString.h:1816
iterator begin()
Returns an iterator to the beginning.
Definition StaticString.h:1088
StaticString(const StaticString< TOtherSize, TChar > &other)
Copy constructor variant.
Definition StaticString.h:886
int compare(const StaticString< TAnySize, TChar > &other) const
Compares two strings.
Definition StaticString.h:1429
int compare(size_type pos, size_type count, const_pointer str) const
Compares two strings.
Definition StaticString.h:1467
size_type max_size() const
Returns the maximum number of characters.
Definition StaticString.h:1194
size_type find_first_not_of(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find first absence of characters.
Definition StaticString.h:1757
value_type * pointer
Pointer to single character.
Definition StaticString.h:807
iterator erase(const_iterator pos)
Removes characters.
Definition StaticString.h:1313
reference back()
Accesses the last character.
Definition StaticString.h:1059
void resize(size_type count)
Changes the number of characters stored.
Definition StaticString.h:1645
StaticString & operator=(const StaticString &other)
Copy assignment.
Definition StaticString.h:902
size_type find_first_of(const StaticString< TAnySize, TChar > &str, size_type pos=0) const
Find first occurrence of characters.
Definition StaticString.h:1727
size_type capacity() const
returns the number of characters that can be held in currently allocated storage.
Definition StaticString.h:1209
void assign(T &obj, TIter from, TIter to)
Assigns a new value to provided object.
Definition assign.h:41
Main namespace for all classes / functions of COMMS library.
STL namespace.