Arduino DLNA Server
Loading...
Searching...
No Matches
StrView.h
Go to the documentation of this file.
1#pragma once
2
3#include <IPAddress.h>
4#include <assert.h>
5#include <stdio.h>
6#include <string.h>
7
8namespace tiny_dlna {
9
18class StrView {
19 public:
20 StrView() = default;
21
23 StrView(const char* chars) {
24 if (chars != nullptr) {
25 int len = strlen(chars);
26 set((char*)chars, len, len, true);
27 } else {
28 this->is_const = true;
29 clear();
30 }
31 }
32
34 StrView(char chars[], int maxlen, int len = 0) {
35 set(chars, maxlen, len, false);
36 }
37
38 StrView(const StrView&) = default;
39 StrView(StrView&&) = default;
40 StrView& operator=(const StrView&) = default;
41 StrView& operator=(StrView&&) = default;
42
44 virtual void set(const char* alt) {
45 if (alt == nullptr) {
46 this->len = 0;
47 } else {
48 int new_len = strlen(alt);
49 grow(new_len);
50 this->len = new_len;
51 if (this->isConst()) {
53 this->maxlen = this->len;
54 this->chars = (char*)alt;
55 } else {
56 if (this->len > 0) {
58 strncpy(this->chars, alt, len);
59 this->chars[len] = 0;
60 }
61 }
62 }
63 }
64
66 virtual void set(const StrView& alt) {
67 grow(alt.len);
68 this->len = alt.len;
69
70 if (this->isConst()) {
72 this->chars = alt.chars;
73 } else {
74 if (this->chars == nullptr && len == 0) {
75 return;
76 }
78 strncpy(this->chars, alt.chars, this->maxlen);
79 this->chars[len] = 0;
80 }
81 }
82
83 virtual void set(const char c) {
84 clear();
85 add(c);
86 }
87
88 virtual void set(int value) {
89 clear();
90 add(value);
91 }
92
93 virtual void set(double value, int precision = 2, int withd = 0) {
94 clear();
95 add(value);
96 }
97
98 virtual void swap(StrView& str) {
99 char* cpy_chars = chars;
100 bool cpy_is_const = is_const;
101 int cpy_len = len;
102 int cpy_maxlen = maxlen;
103
104 chars = str.chars;
105 is_const = str.is_const;
106 len = str.len;
107 maxlen = str.maxlen;
108
109 str.chars = cpy_chars;
110 str.is_const = cpy_is_const;
111 str.len = cpy_len;
112 str.maxlen = cpy_maxlen;
113 }
114
116 virtual void set(char chars[], int maxlen, int len = 0,
117 bool isConst = false) {
118 this->chars = chars;
119 this->maxlen = maxlen;
120 this->len = len;
121 this->is_const = isConst;
122 if (len == 0 && !isConst) {
123 this->chars[0] = 0;
124 }
125 }
126
128 virtual void add(int value) {
129 if (!this->isConst()) {
130 grow(len + 11);
131 snprintf((char*)c_str() + len, 11, "%d", value);
132 len = strlen(chars);
133 }
134 }
135
137 virtual void add(double value, int precision = 2, int withd = 0) {
138 if (!this->isConst()) {
139 grow(this->length() + 20);
140 floatToString(this->chars + len, value, precision, withd);
141 len = strlen(chars);
142 }
143 }
144
146 virtual void add(const char* append) {
147 if (!isConst() && append != nullptr) {
148 int append_len = strlen(append);
149 grow(this->length() + append_len + 1);
150 int n = (len + append_len) < maxlen - 1 ? append_len : maxlen - len - 1;
151 strncat(chars, append, n);
152 chars[len + n] = 0;
153 len = strlen(chars);
154 }
155 }
156 virtual void add(const uint8_t* append, int len) {
157 if (!isConst() && append != nullptr) {
158 int append_len = len;
159 int old_len = length();
160 grow(old_len + append_len);
161 memcpy(chars + old_len, append, len);
162 }
163 }
164
166 virtual void add(const char c) {
167 if (!isConst()) {
168 grow(len + 1);
169 chars[len] = c;
170 chars[++len] = 0;
171 } else {
172 assert(false);
173 }
174 }
175
177 virtual bool equals(const char* str) {
178 if (str == nullptr) return false;
179 return strcmp(this->chars, str) == 0;
180 }
181
183 virtual bool startsWith(const char* str) {
184 if (str == nullptr) return false;
185 if (chars == nullptr) return false;
186 int len = strlen(str);
187 return strncmp(this->chars, str, len) == 0;
188 }
189
191 virtual bool endsWith(const char* str) {
192 if (str == nullptr) return false;
193 if (this->chars == nullptr) return false;
194 int endlen = strlen(str);
195 return strncmp(this->chars + (len - endlen), str, endlen) == 0;
196 }
197
199 virtual bool endsWithIgnoreCase(const char* str) {
200 if (str == nullptr) return false;
201 int endlen = strlen(str);
202 return strncmp_i(this->chars + (len - endlen), str, endlen) == 0;
203 }
204
207 virtual bool matches(const char* pattern) {
210 int wildcard = 0;
211 const char* line = this->chars;
212
213 const char* last_pattern_start = 0;
214 const char* last_line_start = 0;
215 do {
216 if (*pattern == *line) {
217 if (wildcard == 1) last_line_start = line + 1;
218
219 line++;
220 pattern++;
221 wildcard = 0;
222 } else if (*pattern == '?') {
223 if (*(line) == '\0')
224 return 0;
225 if (wildcard == 1) last_line_start = line + 1;
226 line++;
227 pattern++;
228 wildcard = 0;
229 } else if (*pattern == '*') {
230 if (*(pattern + 1) == '\0') {
231 return 1;
232 }
233
234 last_pattern_start = pattern;
235 // last_line_start = line + 1;
236 wildcard = 1;
237
238 pattern++;
239 } else if (wildcard) {
240 if (*line == *pattern) {
241 wildcard = 0;
242 line++;
243 pattern++;
244 last_line_start = line + 1;
245 } else {
246 line++;
247 }
248 } else {
249 if ((*pattern) == '\0' && (*line) == '\0')
250 return 1;
251 else {
252 if (last_pattern_start != 0)
253 {
254 pattern = last_pattern_start;
255 line = last_line_start;
256 last_line_start = 0;
257 } else {
258 return false;
259 }
260 }
261 }
262
263 } while (*line);
264
265 if (*pattern == '\0') {
266 return true;
267 } else {
268 return false;
269 }
270 }
271
274 virtual int indexOf(const char c, int start = 0) {
275 for (int j = start; j < len; j++) {
276 if (c == chars[j]) {
277 return j;
278 }
279 }
280 return -1;
281 }
282
284 virtual bool contains(const char* str) { return indexOf(str) != -1; }
285
288 virtual int indexOf(const char* cont, int start = 0) {
289 if (chars == nullptr || cont == nullptr) return -1;
290 int contLen = strlen(cont);
291 for (int j = start; j < len; j++) {
292 char* pt = chars + j;
293 if (strncmp(pt, cont, contLen) == 0) {
294 return j;
295 }
296 }
297 return -1;
298 }
299
301 virtual int lastIndexOf(const char* cont) {
302 if (cont == nullptr) return -1;
303 int contLen = strlen(cont);
304 for (int j = (len - contLen); j >= 0; j--) {
305 if (strncmp(cont, chars + j, contLen) == 0) {
306 return j;
307 }
308 }
309 return -1;
310 }
311
313 virtual void operator=(const char* str) { set(str); }
314
316 virtual void operator=(char* str) { set(str); }
317
319 virtual void operator=(char c) { set(c); }
320
322 virtual void operator=(double val) { set(val); }
323
325 virtual void operator=(int value) { set(value); }
326
328 virtual void operator<<(int n) {
329 if (isConst()) {
330 this->chars += n;
331 this->len -= n;
332 } else {
333 if (this->chars == nullptr) return;
334 memmove(this->chars, this->chars + n, len + 1);
335 }
336 }
337
338 virtual char operator[](int index) { return chars[index]; }
339
341 virtual void operator+=(const char* str) { add(str); }
342
344 virtual void operator+=(int value) { add(value); }
345
347 virtual void operator+=(double value) { add(value); }
348
350 virtual void operator+=(const char value) { add(value); }
351
353 virtual bool operator==(const StrView& alt) const {
354 if (this->len != alt.len) return false;
355 return strncmp(this->chars, alt.chars, this->len) == 0;
356 }
357
359 virtual bool operator==(const char* alt) const {
360 if (alt == nullptr) return len == 0;
361 if (strlen(alt) != this->len) return false;
362 return strncmp(this->chars, alt, this->len) == 0;
363 }
364
366 virtual bool operator!=(const StrView& alt) const {
367 return strncmp(this->chars, alt.chars, this->len) != 0;
368 }
369
371 virtual bool operator!=(const char* alt) const {
372 return strncmp(this->chars, alt, this->len) != 0;
373 }
374
376 virtual const char* c_str() { return chars == nullptr ? "" : chars; }
377
380 virtual int length() { return len; }
381
383 virtual bool isEmpty() { return len == 0; }
384
385 virtual bool isNewLine() {
386 if (len >= 1 && chars[0] == '\n') return true;
387 if (len >= 2 && chars[0] == '\r' && chars[1] == '\n') return true;
388 return false;
389 }
390
392 virtual int maxLength() { return maxlen; }
393
395 virtual bool replace(const char* toReplace, const int replaced) {
396 char number[50];
397 snprintf(number, 50, "%d", replaced);
398 return replace(toReplace, number);
399 }
400
401 virtual bool replace(const char* toReplace, const float replaced) {
402 char number[50];
403 snprintf(number, 50, "%f", replaced);
404 return replace(toReplace, number);
405 }
406
408 virtual bool replace(const char* toReplace, const char* replaced,
409 int startPos = 0) {
410 bool result = false;
411 if (toReplace == nullptr || replaced == nullptr) {
412 return result;
413 }
414 if (!isConst()) {
415 int pos = indexOf(toReplace, startPos);
416 int old_len = length();
417 int insert_len = 0;
418 if (pos >= 0) {
419 int len_replaced = strlen(replaced);
420 int len_to_replace = strlen(toReplace);
421 insert_len = len_replaced - len_to_replace;
422 grow(this->length() + insert_len);
423 // save remainder and create gap
424 memmove(this->chars + pos + len_replaced,
425 this->chars + pos + len_to_replace,
426 old_len - pos - len_to_replace + 1);
427 // move new string into gap
428 memmove(this->chars + pos, replaced, len_replaced);
429 result = true;
430 len += insert_len;
431 }
432 }
433 return result;
434 }
435
437 virtual bool replaceAll(const char* toReplace, const char* replaced) {
438 if (isEmpty()) {
439 return false;
440 }
441 int found = 0;
442 int pos = 0;
443 while (true) {
444 pos = indexOf(toReplace, pos);
445 if (pos >= 0) {
446 found++;
447 } else {
448 return found;
449 }
450 replace(toReplace, replaced, pos);
451 // search from next pos
452 pos++;
453 }
454 }
455
457 virtual void remove(const char* toRemove) {
458 if (!isConst() && chars != nullptr) {
459 int removeLen = strlen(toRemove);
460 int pos = indexOf(toRemove);
461 if (pos >= 0) {
462 memmove((void*)(chars + pos), (void*)(chars + pos + removeLen),
463 len - (pos + removeLen) + 1);
464 len -= removeLen;
465 }
466 }
467 }
468
470 virtual void removeAll(const char* toRemove) {
471 if (!isConst() && chars != nullptr) {
472 int removeLen = strlen(toRemove);
473 while (true) {
474 int pos = indexOf(toRemove);
475 if (pos == -1) {
476 break;
477 }
478 memmove((void*)(chars + pos), (void*)(chars + pos + removeLen),
479 len - (pos + removeLen) + 1);
480 len -= removeLen;
481 }
482 }
483 }
484
486 virtual void setLength(int len, bool addZero = true) {
487 if (!isConst() && addZero) {
488 this->savedChar = chars[len];
489 this->savedLen = len;
490 this->len = len;
491 chars[len] = 0;
492 }
493 }
494
496 virtual void setLengthUndo() {
497 if (savedLen >= 0) {
499 this->len = savedLen;
500 savedLen = -1;
501 }
502 }
503
505 virtual void substrView(StrView& from, int start, int end) {
506 if (end > start) {
507 int len = end - start;
508 grow(len);
509 if (this->chars != nullptr) {
510 len = len < this->maxlen ? len : this->maxlen;
511 strncpy(this->chars, from.chars + start, len);
512 this->len = len;
513 this->chars[len] = 0;
514 }
515 }
516 }
517
519 virtual void substrView(const char* from, int start, int end) {
520 if (end > start) {
521 int len = end - start;
522 grow(len);
523 if (this->chars != nullptr) {
524 strncpy(this->chars, from + start, len);
525 this->chars[len] = 0;
526 this->len = len;
527 }
528 }
529 }
530
532 virtual void trim() {
533 rtrim();
534 ltrim();
535 }
536
538 virtual int count(char c, int startPos) {
539 for (int j = startPos; j < len; j++) {
540 if (chars[j] != c) {
541 return j;
542 }
543 }
544 return 0;
545 }
546
548 virtual void ltrim() {
549 int n = count(' ', 0);
550 *this << n;
551 }
552
554 virtual void rtrim() {
555 if (!isConst()) {
556 while (this->endsWith(" ")) {
557 len--;
558 chars[len] = 0;
559 }
560 }
561 }
562
564 virtual void clear() {
565 if (chars != nullptr && !isConst()) {
566 chars[0] = 0;
567 }
568 len = 0;
569 }
570
571 virtual void clearAll() {
572 if (chars != nullptr && !isConst()) {
573 for (int j = 0; j < maxlen; j++) chars[j] = 0;
574 }
575 len = 0;
576 }
577
579 virtual bool isOnHeap() { return false; }
580
582 virtual bool isConst() { return is_const; }
583
585 virtual void insert(int pos, const char* str) {
586 if (!isConst()) {
587 int insert_len = strlen(str);
588 grow(this->length() + insert_len);
589 int move_len = this->len - pos + 1;
590 memmove(chars + pos + insert_len, chars + pos, move_len);
591 strncpy(chars + pos, str, insert_len);
592 }
593 }
594
596 virtual bool equalsIgnoreCase(const char* alt) {
597 if ((size_t)len != strlen(alt)) {
598 return false;
599 }
600 for (int j = 0; j < len; j++) {
601 if (tolower(chars[j]) != tolower(alt[j])) return false;
602 }
603 return true;
604 }
605
607 int toInt() {
608 int result = 0;
609 if (!isEmpty()) {
610 result = atoi(chars);
611 }
612 return result;
613 }
614
616 long toLong() {
617 long result = 0;
618 if (!isEmpty()) {
619 result = atol(chars);
620 }
621 return result;
622 }
623
625 double toDouble() {
626 double result = 0;
627 char* eptr;
628 if (!isEmpty()) {
629 result = strtod(chars, &eptr);
630 }
631 return result;
632 }
633
635 float toFloat() {
636 float result = 0;
637 char* eptr;
638 if (!isEmpty()) {
639 result = strtod(chars, &eptr);
640 }
641 return result;
642 }
643
645 void toLowerCase() {
646 if (chars != nullptr) {
647 for (int j = 0; j < len; j++) {
648 chars[j] = tolower(chars[j]);
649 }
650 }
651 }
652
654 void toUpperCase() {
655 if (chars != nullptr) {
656 for (int j = 0; j < len; j++) {
657 chars[j] = toupper(chars[j]);
658 }
659 }
660 }
661
663 static const char* toBinary(void const* const ptr, size_t const size) {
664 static char result[160];
665 unsigned char* b = (unsigned char*)ptr;
666 unsigned char byte;
667 int i, j, idx = 0;
668
669 for (i = size - 1; i >= 0; i--) {
670 for (j = 7; j >= 0; j--) {
671 byte = (b[i] >> j) & 1;
672 result[idx++] = byte ? '1' : '0';
673 }
674 }
675 result[idx] = 0;
676 return result;
677 }
678
680 for (int j = 0; j < len; j++) {
681 if (isdigit(chars[j])) {
682 return true;
683 }
684 }
685 return false;
686 }
687
689 bool isInteger() {
690 bool result = containsNumber();
691 int minus_count = 0;
692 for (int j = 0; j < len; j++) {
693 char c = chars[j];
694 if (!isdigit(c)) {
695 switch (c) {
696 case '-':
697 minus_count++;
698 if (minus_count > 1) {
699 result = false;
700 }
701 break;
702 default:
703 result = false;
704 break;
705 }
706 }
707 }
708 return result;
709 }
710
713 int result = 0;
714 int pos = indexOf(".");
715 if (pos >= 0) {
716 for (int j = pos + 1; j < len; j++) {
717 if (isdigit(chars[j])) {
718 pos++;
719 } else {
720 break;
721 }
722 }
723 }
724 return result;
725 }
726
727 // Returns true if the string is a number
728 bool isNumber() {
729 bool result = containsNumber();
730 int dot_count = 0;
731 int minus_count = 0;
732 for (int j = 0; j < len; j++) {
733 char c = chars[j];
734 if (!isdigit(c)) {
735 switch (c) {
736 case '-':
737 minus_count++;
738 if (minus_count > 1) {
739 result = false;
740 }
741 break;
742 case '.':
743 dot_count++;
744 if (dot_count > 1) {
745 result = false;
746 }
747 break;
748 default:
749 result = false;
750 break;
751 }
752 }
753 }
754 return result;
755 }
756
757 const char* buildPath(const char* start, const char* p1 = nullptr,
758 const char* p2 = nullptr) {
759 set(start);
760 if (p1 != nullptr) add(p1);
761 if (p2 != nullptr) add(p2);
762 return chars;
763 }
764
765 protected:
766 char* chars = nullptr;
767 bool is_const = true;
768 int len = 0;
769 int maxlen = 0;
770 int savedLen = -1;
772
774 virtual bool grow(int newMaxLen) { return false; }
775
776 static char* itoa(int n, char s[]) {
777 int i, sign;
778 if ((sign = n) < 0) /* record sign */
779 n = -n; /* make n positive */
780 i = 0;
781 do { /* generate digits in reverse order */
782 s[i++] = n % 10 + '0'; /* get next digit */
783 } while ((n /= 10) > 0); /* delete it */
784 if (sign < 0) s[i++] = '-';
785 s[i] = '\0';
786 reverse(s);
787 return s;
788 }
789
790 static void reverse(char s[]) {
791 int i, j;
792 char c;
793
794 for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
795 c = s[i];
796 s[i] = s[j];
797 s[j] = c;
798 }
799 }
800
801 static char* floatToString(char* outstr, double val, int precision,
802 int widthp) {
803 char temp[16];
804 int i;
805
807 double roundingFactor = 0.5;
808 unsigned long mult = 1;
809 for (i = 0; i < precision; i++) {
810 roundingFactor /= 10.0;
811 mult *= 10;
812 }
813
814 temp[0] = '\0';
815 outstr[0] = '\0';
816
817 if (val < 0.0) {
818 strcpy(outstr, "-\0");
819 val = -val;
820 }
821
822 val += roundingFactor;
823
824 strcat(outstr, itoa(int(val), temp)); // prints the int part
825 if (precision > 0) {
826 strcat(outstr, ".\0");
827 unsigned long frac;
828 unsigned long mult = 1;
829 int padding = precision - 1;
830 while (precision--) mult *= 10;
831
832 if (val >= 0)
833 frac = (val - int(val)) * mult;
834 else
835 frac = (int(val) - val) * mult;
836 unsigned long frac1 = frac;
837
838 while (frac1 /= 10) padding--;
839
840 while (padding--) strcat(outstr, "0\0");
841
842 strcat(outstr, itoa(frac, temp));
843 }
844
846 if ((widthp != 0) && ((size_t)widthp >= strlen(outstr))) {
847 int J = 0;
848 J = widthp - strlen(outstr);
849
850 for (i = 0; i < J; i++) {
851 temp[i] = ' ';
852 }
853
854 temp[i++] = '\0';
855 strcat(temp, outstr);
856 strcpy(outstr, temp);
857 }
858
859 return outstr;
860 }
861
862 static int strncmp_i(const char* s1, const char* s2, int n) {
863 if (n == 0) return (0);
864 do {
865 if (tolower(*s1) != tolower(*s2++))
866 return (*(unsigned char*)s1 - *(unsigned char*)--s2);
867 if (*s1++ == 0) break;
868 } while (--n != 0);
869 return (0);
870 }
871};
872
873} // namespace tiny_dlna
A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not a...
Definition: StrView.h:18
virtual void add(int value)
adds a int value
Definition: StrView.h:128
virtual void substrView(StrView &from, int start, int end)
copies a substring into the current string
Definition: StrView.h:505
virtual void operator=(double val)
we can assign a double
Definition: StrView.h:322
virtual bool equalsIgnoreCase(const char *alt)
Compares the string ignoring the case.
Definition: StrView.h:596
virtual void add(const uint8_t *append, int len)
Definition: StrView.h:156
char * chars
Definition: StrView.h:766
virtual void set(const StrView &alt)
assigs from another StrView value
Definition: StrView.h:66
bool containsNumber()
Definition: StrView.h:679
virtual bool replaceAll(const char *toReplace, const char *replaced)
Replaces all instances of toReplace with replaced.
Definition: StrView.h:437
virtual int indexOf(const char *cont, int start=0)
Definition: StrView.h:288
virtual void operator<<(int n)
shift characters to the right -> we just move the pointer
Definition: StrView.h:328
long toLong()
Converts the string to an long.
Definition: StrView.h:616
virtual int maxLength()
provides the maximum length of the string
Definition: StrView.h:392
float toFloat()
Converts the string to a double.
Definition: StrView.h:635
virtual bool isEmpty()
checks if the string is empty
Definition: StrView.h:383
double toDouble()
Converts the string to a double.
Definition: StrView.h:625
virtual bool replace(const char *toReplace, const float replaced)
Definition: StrView.h:401
virtual void clearAll()
Definition: StrView.h:571
virtual void operator+=(double value)
adds a double at the end of the string
Definition: StrView.h:347
virtual void removeAll(const char *toRemove)
removes the indicated substring from the string
Definition: StrView.h:470
static char * itoa(int n, char s[])
Definition: StrView.h:776
virtual void operator+=(const char value)
adds a character
Definition: StrView.h:350
virtual void substrView(const char *from, int start, int end)
copies a substring into the current string
Definition: StrView.h:519
virtual void operator=(int value)
we can assign an int
Definition: StrView.h:325
StrView & operator=(const StrView &)=default
virtual const char * c_str()
provides the string value as const char*
Definition: StrView.h:376
const char * buildPath(const char *start, const char *p1=nullptr, const char *p2=nullptr)
Definition: StrView.h:757
virtual void operator=(const char *str)
we can assign a const char*
Definition: StrView.h:313
bool isNumber()
Definition: StrView.h:728
virtual void add(const char c)
adds a character
Definition: StrView.h:166
virtual void setLengthUndo()
undo the last setLength call
Definition: StrView.h:496
virtual void insert(int pos, const char *str)
inserts a substring into the string
Definition: StrView.h:585
virtual int indexOf(const char c, int start=0)
Definition: StrView.h:274
virtual bool endsWithIgnoreCase(const char *str)
checks if the string ends with the indicated substring
Definition: StrView.h:199
int savedLen
Definition: StrView.h:770
int numberOfDecimals()
Determines the number of decimals in the number string.
Definition: StrView.h:712
int toInt()
Converts the string to an int.
Definition: StrView.h:607
virtual bool operator==(const StrView &alt) const
checks if the indicated string is equal to the current string
Definition: StrView.h:353
virtual bool startsWith(const char *str)
checks if the string starts with the indicated substring
Definition: StrView.h:183
virtual bool matches(const char *pattern)
Definition: StrView.h:207
virtual bool operator!=(const StrView &alt) const
checks if the indicated string is different from the current string
Definition: StrView.h:366
virtual bool operator==(const char *alt) const
checks if the indicated string is equal to the current string
Definition: StrView.h:359
virtual int length()
Definition: StrView.h:380
char savedChar
Definition: StrView.h:771
StrView(const StrView &)=default
virtual void setLength(int len, bool addZero=true)
limits the length of the string (by adding a delimiting 0)
Definition: StrView.h:486
int len
Definition: StrView.h:768
virtual bool endsWith(const char *str)
checks if the string ends with the indicated substring
Definition: StrView.h:191
StrView(char chars[], int maxlen, int len=0)
Creates a StrView with the indicated buffer.
Definition: StrView.h:34
virtual void swap(StrView &str)
Definition: StrView.h:98
virtual void operator=(char *str)
we can assign a char*
Definition: StrView.h:316
virtual bool operator!=(const char *alt) const
checks if the indicated string is different from the current string
Definition: StrView.h:371
StrView(const char *chars)
Creates a StrView for string constant.
Definition: StrView.h:23
virtual bool replace(const char *toReplace, const int replaced)
Replaces the first instance of toReplace with replaced.
Definition: StrView.h:395
virtual int count(char c, int startPos)
count number of indicated characters as position
Definition: StrView.h:538
StrView(StrView &&)=default
virtual void trim()
remove leading and traling spaces
Definition: StrView.h:532
virtual bool grow(int newMaxLen)
only supported in subclasses
Definition: StrView.h:774
virtual void add(const char *append)
adds a string
Definition: StrView.h:146
int maxlen
Definition: StrView.h:769
static const char * toBinary(void const *const ptr, size_t const size)
provides a binary string represntation
Definition: StrView.h:663
virtual void operator+=(int value)
adds a int at the end of the string
Definition: StrView.h:344
virtual void set(const char *alt)
assigs a value
Definition: StrView.h:44
bool isInteger()
Returns true if the string is an integer.
Definition: StrView.h:689
void toLowerCase()
Converts the string to lowercase letters.
Definition: StrView.h:645
StrView & operator=(StrView &&)=default
static int strncmp_i(const char *s1, const char *s2, int n)
Definition: StrView.h:862
virtual void set(const char c)
Definition: StrView.h:83
static void reverse(char s[])
Definition: StrView.h:790
virtual void operator=(char c)
we can assign a char
Definition: StrView.h:319
virtual bool replace(const char *toReplace, const char *replaced, int startPos=0)
Replaces the first instance of toReplace with replaced.
Definition: StrView.h:408
virtual char operator[](int index)
Definition: StrView.h:338
virtual void set(int value)
Definition: StrView.h:88
virtual void set(double value, int precision=2, int withd=0)
Definition: StrView.h:93
virtual bool equals(const char *str)
checks if the string equals indicated parameter string
Definition: StrView.h:177
virtual void clear()
clears the string by setting the terminating 0 at the beginning
Definition: StrView.h:564
virtual void set(char chars[], int maxlen, int len=0, bool isConst=false)
assigns a memory buffer
Definition: StrView.h:116
virtual void ltrim()
remove leading spaces
Definition: StrView.h:548
virtual void remove(const char *toRemove)
removes the indicated substring from the string
Definition: StrView.h:457
virtual void add(double value, int precision=2, int withd=0)
adds a double value
Definition: StrView.h:137
virtual void rtrim()
remove trailing spaces
Definition: StrView.h:554
virtual bool isOnHeap()
checks if the string is on the heap
Definition: StrView.h:579
static char * floatToString(char *outstr, double val, int precision, int widthp)
Definition: StrView.h:801
virtual int lastIndexOf(const char *cont)
provides the position of the last occurrence of the indicated substring
Definition: StrView.h:301
virtual bool contains(const char *str)
checks if the string contains a substring
Definition: StrView.h:284
virtual void operator+=(const char *str)
adds a substring at the end of the string
Definition: StrView.h:341
void toUpperCase()
Converts the string to uppercase letters.
Definition: StrView.h:654
virtual bool isConst()
checks if the string is a constant that must not be changed
Definition: StrView.h:582
bool is_const
Definition: StrView.h:767
virtual bool isNewLine()
Definition: StrView.h:385
Definition: Allocator.h:13