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