12template <
class CharType =
char>
39 constexpr operator const CharType*()
const noexcept {
return buffer_; }
40 constexpr const CharType*
Cstr() const noexcept {
return buffer_; }
41 constexpr const CharType*
Data() const noexcept {
return buffer_; }
44 constexpr auto Size() const noexcept {
return size_; }
53 constexpr auto Empty() const noexcept {
return size_ == 0; }
61 constexpr void Reset(
const CharType* str)
61 constexpr void Reset(
const CharType* str) {
…}
67 constexpr void Reset(
const CharType* str, std::size_t length)
67 constexpr void Reset(
const CharType* str, std::size_t length) {
…}
73 constexpr void ResetAt(
const CharType* str, std::size_t writePosition)
75 if(writePosition >
size_)
77 const auto strLen =
strlen(str);
80 const auto numCharsToWrite = std::min(newSize - writePosition, strLen);
82 ResetAt_(str, numCharsToWrite, writePosition);
73 constexpr void ResetAt(
const CharType* str, std::size_t writePosition) {
…}
85 constexpr void Append(
const CharType singleChar)
85 constexpr void Append(
const CharType singleChar) {
…}
95 constexpr void Append(
const CharType* str)
95 constexpr void Append(
const CharType* str) {
…}
101 constexpr void Append(
const CharType* str, std::size_t length)
101 constexpr void Append(
const CharType* str, std::size_t length) {
…}
107 template <
typename IntType>
108 constexpr void AppendInt(IntType value,
bool alwaysIncludeSign =
false)
112 if(alwaysIncludeSign)
123 else if(alwaysIncludeSign)
126 const auto firstDigit =
Size();
129 const auto rem = value % 10;
133 const auto lastDigit =
Size() - 1;
108 constexpr void AppendInt(IntType value,
bool alwaysIncludeSign =
false) {
…}
138 int maxNumDigits = 2,
139 bool omitTrailingZeros =
false,
140 bool alwaysIncludeSign =
false)
144 if(alwaysIncludeSign)
147 if((!omitTrailingZeros) && (maxNumDigits > 0))
150 for(
int i = 0; i < maxNumDigits; i++)
161 else if(alwaysIncludeSign)
165 constexpr int tableSize = 10;
167 constexpr float powTable[tableSize] = {
179 constexpr float roundOffsTable[tableSize] = {
191 if(maxNumDigits <= tableSize)
193 factor = powTable[maxNumDigits];
194 value += roundOffsTable[maxNumDigits];
198 float roundOffs = 0.5f;
199 for(
int i = 0; i < maxNumDigits; i++)
207 int beforeDecPt = int(value);
208 int afterDecPt = int(value * factor);
210 const auto firstDigit =
Size();
212 for(
int i = 0; i < maxNumDigits; i++)
214 const auto rem = afterDecPt % 10;
215 afterDecPt = afterDecPt / 10;
216 if((rem == 0) && (omitTrailingZeros))
221 if(
Size() != firstDigit)
228 while(beforeDecPt != 0)
230 const auto rem = beforeDecPt % 10;
231 beforeDecPt = beforeDecPt / 10;
235 const auto lastDigit =
Size() - 1;
239 constexpr bool StartsWith(
const CharType* pattern)
const noexcept
239 constexpr bool StartsWith(
const CharType* pattern)
const noexcept {
…}
266 constexpr bool EndsWith(
const CharType* pattern)
const noexcept
269 const auto patternLength =
strlen(pattern);
270 const CharType* patternPtr = pattern + patternLength - 1;
271 while(patternPtr > pattern)
273 if(*ptr != *patternPtr)
278 return *ptr == *patternPtr;
266 constexpr bool EndsWith(
const CharType* pattern)
const noexcept {
…}
284 const auto patternLength =
strlen(pattern);
285 const CharType* patternPtr = pattern + patternLength - 1;
286 while(patternPtr > pattern)
313 while(firstIdx < lastIdx)
315 CharType tmp =
buffer_[lastIdx];
339 return !(*
this == rhs);
345 while(*ptr && *other && (*ptr == *other))
350 return *ptr < *other;
355 return (*
this == other) || (*
this < other);
361 while(*ptr && *other && (*ptr == *other))
366 return *ptr > *other;
371 return (*
this == other) || (*
this > other);
384 static constexpr std::size_t
strlen(
const CharType*
string)
386 std::size_t result = 0;
387 while(*
string++ !=
'\0')
384 static constexpr std::size_t
strlen(
const CharType*
string) {
…}
392 constexpr void Reset_(
const CharType* str, std::size_t length)
392 constexpr void Reset_(
const CharType* str, std::size_t length) {
…}
399 ResetAt_(
const CharType* str, std::size_t strLen, std::size_t writePosition)
402 if(writePosition + strLen >
size_)
403 buffer_[writePosition + strLen] =
'\0';
399 ResetAt_(
const CharType* str, std::size_t strLen, std::size_t writePosition) {
…}
406 constexpr void Append_(
const CharType* str, std::size_t to_copy)
406 constexpr void Append_(
const CharType* str, std::size_t to_copy) {
…}
413 static constexpr void
414 Copy_(
const CharType* src,
const CharType* srcEnd, CharType* dest)
414 Copy_(
const CharType* src,
const CharType* srcEnd, CharType* dest) {
…}
424 static constexpr void Swap_(CharType* a, CharType* b,
size_t length)
426 for(
size_t i = 0; i < length; i++)
424 static constexpr void Swap_(CharType* a, CharType* b,
size_t length) {
…}
442 case 'a':
return 'A';
443 case 'b':
return 'B';
444 case 'c':
return 'C';
445 case 'd':
return 'D';
446 case 'e':
return 'E';
447 case 'f':
return 'F';
448 case 'g':
return 'G';
449 case 'h':
return 'H';
450 case 'i':
return 'I';
451 case 'j':
return 'J';
452 case 'k':
return 'K';
453 case 'l':
return 'L';
454 case 'm':
return 'M';
455 case 'n':
return 'N';
456 case 'o':
return 'O';
457 case 'p':
return 'P';
458 case 'q':
return 'Q';
459 case 'r':
return 'R';
460 case 's':
return 'S';
461 case 't':
return 'T';
462 case 'u':
return 'U';
463 case 'v':
return 'V';
464 case 'w':
return 'W';
465 case 'x':
return 'X';
466 case 'y':
return 'Y';
467 case 'z':
return 'Z';
471 std::size_t
clamp(std::size_t val, std::size_t min, std::size_t max)
473 return (val < min) ? min : ((val > max) ? max : val);
471 std::size_t
clamp(std::size_t val, std::size_t min, std::size_t max) {
…}
488template <std::
size_t capacity,
class CharType =
char>
500 this->
size_ = std::min(str.Size(), capacity);
501 this->
Copy_(str.Data(), str.Data() + this->size_, buffer_);
504 template <
size_t otherSize>
508 this->
size_ = std::min(str.Size(), capacity);
509 this->
Copy_(str.Data(), str.Data() + this->size_, buffer_);
515 this->
size_ = std::min(this->
strlen(str), capacity);
519 constexpr FixedCapStr(
const CharType* str, std::size_t length) noexcept
522 this->
size_ = std::min(length, capacity);
519 constexpr FixedCapStr(
const CharType* str, std::size_t length) noexcept {
…}
533 CharType buffer_[capacity + 1]{};
536template <
class CharType, std::
size_t capacity>
Definition FixedCapStr.h:14
constexpr bool StartsWithIgnoringCase(const CharType *pattern) const noexcept
Definition FixedCapStr.h:253
constexpr CharType * Data() noexcept
Definition FixedCapStr.h:42
constexpr bool operator>(const CharType *other) const
Definition FixedCapStr.h:358
constexpr bool operator==(const CharType *rhs) const
Definition FixedCapStr.h:323
constexpr void Append(const CharType *str)
Definition FixedCapStr.h:95
constexpr void AppendFloat(float value, int maxNumDigits=2, bool omitTrailingZeros=false, bool alwaysIncludeSign=false)
Definition FixedCapStr.h:137
static constexpr std::size_t strlen(const CharType *string)
Definition FixedCapStr.h:384
constexpr void RemovePrefix(std::size_t length)
Definition FixedCapStr.h:296
constexpr void Reset_(const CharType *str, std::size_t length)
Definition FixedCapStr.h:392
constexpr FixedCapStrBase(CharType *buffer, size_t capacity)
Definition FixedCapStr.h:16
constexpr void ResetAt(const CharType *str, std::size_t writePosition)
Definition FixedCapStr.h:73
constexpr void Reset(const CharType *str, std::size_t length)
Definition FixedCapStr.h:67
constexpr FixedCapStrBase(const FixedCapStrBase &other)=delete
constexpr const CharType * Data() const noexcept
Definition FixedCapStr.h:41
constexpr FixedCapStrBase & operator=(const FixedCapStrBase &str)
Definition FixedCapStr.h:23
CharType * buffer_
Definition FixedCapStr.h:478
const size_t capacity_
Definition FixedCapStr.h:477
constexpr void Append_(const CharType *str, std::size_t to_copy)
Definition FixedCapStr.h:406
constexpr auto Capacity() const noexcept
Definition FixedCapStr.h:51
constexpr bool operator<=(const CharType *other) const
Definition FixedCapStr.h:353
constexpr bool EndsWith(const CharType *pattern) const noexcept
Definition FixedCapStr.h:266
constexpr void AppendInt(IntType value, bool alwaysIncludeSign=false)
Definition FixedCapStr.h:108
static constexpr void Copy_(const CharType *src, const CharType *srcEnd, CharType *dest)
Definition FixedCapStr.h:414
constexpr auto Empty() const noexcept
Definition FixedCapStr.h:53
constexpr bool EndsWithIgnoringCase(const CharType *pattern) const noexcept
Definition FixedCapStr.h:281
constexpr void Reset(const CharType *str)
Definition FixedCapStr.h:61
constexpr auto Size() const noexcept
Definition FixedCapStr.h:44
constexpr bool operator>=(const CharType *other) const
Definition FixedCapStr.h:369
std::size_t clamp(std::size_t val, std::size_t min, std::size_t max)
Definition FixedCapStr.h:471
static constexpr void Swap_(CharType *a, CharType *b, size_t length)
Definition FixedCapStr.h:424
constexpr void RemoveSuffix(std::size_t length) noexcept
Definition FixedCapStr.h:303
constexpr void Append(const CharType singleChar)
Definition FixedCapStr.h:85
constexpr const CharType * Cstr() const noexcept
Definition FixedCapStr.h:40
constexpr void Swap(FixedCapStrBase &rhs) noexcept
Definition FixedCapStr.h:374
constexpr void Append(const CharType *str, std::size_t length)
Definition FixedCapStr.h:101
static constexpr char ToUpper_(char c) noexcept
Definition FixedCapStr.h:437
constexpr bool operator<(const CharType *other) const
Definition FixedCapStr.h:342
constexpr bool StartsWith(const CharType *pattern) const noexcept
Definition FixedCapStr.h:239
constexpr void Clear() noexcept
Definition FixedCapStr.h:55
constexpr FixedCapStrBase & operator=(const CharType *str)
Definition FixedCapStr.h:31
constexpr bool operator!=(const CharType *rhs) const
Definition FixedCapStr.h:337
constexpr void ResetAt_(const CharType *str, std::size_t strLen, std::size_t writePosition)
Definition FixedCapStr.h:399
constexpr void ReverseSection(std::size_t firstIdx, std::size_t lastIdx)
Definition FixedCapStr.h:309
constexpr auto UpdateSize() noexcept
Definition FixedCapStr.h:45
std::size_t size_
Definition FixedCapStr.h:476
Definition FixedCapStr.h:490
constexpr FixedCapStr & operator=(const FixedCapStr &str) noexcept
Definition FixedCapStr.h:526
constexpr FixedCapStr(const FixedCapStr &str) noexcept
Definition FixedCapStr.h:497
constexpr FixedCapStr(const CharType *str) noexcept
Definition FixedCapStr.h:512
constexpr FixedCapStr(const FixedCapStr< otherSize > &str) noexcept
Definition FixedCapStr.h:505
constexpr FixedCapStr(const CharType *str, std::size_t length) noexcept
Definition FixedCapStr.h:519
constexpr FixedCapStr() noexcept
Definition FixedCapStr.h:492
Hardware defines and helpers for daisy field platform.
Definition index.h:2
constexpr void Swap(const FixedCapStr< capacity, CharType > &lhs, const FixedCapStr< capacity, CharType > &rhs) noexcept
Definition FixedCapStr.h:537