arduino-audio-tools
Loading...
Searching...
No Matches
StrView.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdio.h>
4#include <stdarg.h>
5#include <string.h>
6#include <stdlib.h>
8
17namespace audio_tools {
18
29class StrView {
30 public:
31 StrView() = default;
32
34 StrView(const char* chars) {
35 if (chars != nullptr) {
36 int len = strlen(chars);
37 set((char*)chars, len, len, true);
38 } else {
39 this->is_const = true;
40 clear();
41 }
42 }
43
45 StrView(char chars[], int maxlen, int len = 0) { set(chars, maxlen, len, false); }
46
48 virtual void set(const char* alt) {
49 if (alt == nullptr) {
50 this->len = 0;
51 } else {
52 int new_len = strlen(alt);
53 grow(new_len + 1);
54 if (this->isConst()) {
56 this->len = new_len;
57 this->maxlen = this->len;
58 this->chars = (char*)alt;
59 } else {
62 int copy_len = new_len < this->maxlen ? new_len : this->maxlen - 1;
63 strncpy(this->chars, alt, copy_len);
64 this->chars[copy_len] = 0;
65 this->len = copy_len;
66 }
67 }
68 }
70 virtual void set(const StrView& alt) {
71 grow(alt.len + 1);
72
73 if (this->isConst()) {
75 this->len = alt.len;
76 this->chars = alt.chars;
77 } else {
80 int copy_len = alt.len < this->maxlen ? alt.len : this->maxlen - 1;
81 strncpy(this->chars, alt.chars, copy_len);
82 this->chars[copy_len] = 0;
83 this->len = copy_len;
84 }
85 }
86
87 virtual void set(const char c) {
88 clear();
89 add(c);
90 }
91
92 virtual void set(int value) {
93 clear();
94 add(value);
95 }
96
97 virtual void set(double value, int precision = 2, int withd = 0) {
98 clear();
99 add(value);
100 }
101
102 virtual void swap(StrView& str) {
103 char* cpy_chars = chars;
104 ;
105 bool cpy_is_const = is_const;
106 int cpy_len = len;
107 int cpy_maxlen = maxlen;
108
109 chars = str.chars;
110 is_const = str.is_const;
111 len = str.len;
112 maxlen = str.maxlen;
113
114 str.chars = cpy_chars;
115 str.is_const = cpy_is_const;
116 str.len = cpy_len;
117 str.maxlen = cpy_maxlen;
118 }
119
121 virtual void set(char chars[], int maxlen, int len = 0,
122 bool isConst = false) {
123 this->chars = chars;
124 this->maxlen = maxlen;
125 this->len = len;
126 this->is_const = isConst;
127 if (len == 0 && !isConst) {
128 this->chars[0] = 0;
129 }
130 }
131
133 virtual void add(int value) {
134 if (!this->isConst()) {
135 char buffer[12]; // -2147483648 + '\0'
136 snprintf(buffer, sizeof(buffer), "%d", value);
137 add(buffer);
138 }
139 }
140
142 virtual void add(double value, int precision = 2, int withd = 0) {
143 if (!this->isConst()) {
144 char buffer[128];
145 floatToString(buffer, value, precision, withd);
146 add(buffer);
147 }
148 }
149
151 virtual void add(const char* append) {
152 if (!isConst() && append != nullptr) {
153 int append_len = strlen(append);
154 grow(this->length() + append_len + 1);
155 int n = (len + append_len) < maxlen - 1 ? append_len : maxlen - len - 1;
156 strncat(chars, append, n);
157 chars[len + n] = 0;
158 len = strlen(chars);
159 }
160 }
161
166 virtual const char* printf(const char* fmt, ...) {
167 if (isConst() || fmt == nullptr) return c_str();
168 va_list args;
169 va_start(args, fmt);
170 va_list args_copy;
171 va_copy(args_copy, args);
172 int needed = vsnprintf(nullptr, 0, fmt, args_copy);
173 va_end(args_copy);
174 if (needed < 0) {
175 va_end(args);
176 return c_str();
177 }
178 grow(needed + 1);
179 if (chars != nullptr) {
180 vsnprintf(chars, maxlen + 1, fmt, args);
181 len = strlen(chars);
182 }
183 va_end(args);
184 return c_str();
185 }
186
188 virtual void add(const char c) {
189 if (!isConst() && len < maxlen - 1) {
190 grow(this->length() + 1);
191 chars[len] = c;
192 chars[++len] = 0;
193 }
194 }
195
197 virtual bool equals(const char* str) {
198 if (str == nullptr) return isEmpty();
199 return strcmp(this->chars, str) == 0;
200 }
201
203 virtual bool startsWith(const char* str) {
204 if (str == nullptr) return false;
205 int len = strlen(str);
206 return strncmp(this->chars, str, len) == 0;
207 }
208
210 virtual bool endsWith(const char* str) {
211 if (str == nullptr) return false;
212 int endlen = strlen(str);
213 if (endlen > len) return false;
214 return strncmp(this->chars + (len - endlen), str, endlen) == 0;
215 }
216
218 virtual bool endsWithIgnoreCase(const char* str) {
219 if (str == nullptr) return false;
220 int endlen = strlen(str);
221 if (endlen > len) return false;
222 return strncmp_i(this->chars + (len - endlen), str, endlen) == 0;
223 }
224
229 virtual bool matches(const char* pattern) {
230 if (pattern == nullptr) return false;
231 // a completely empty pattern is a single (trivial) alternative that
232 // only matches an empty line - handle it before the splitting loop
233 // below, which assumes at least one non-empty alternative.
234 if (*pattern == '\0') return matchesGlob(this->chars, "");
235 const char* alt_start = pattern;
236 for (;;) {
237 // skip leading separators/whitespace
238 while (*alt_start == ',' || *alt_start == ';' || *alt_start == '|' ||
239 *alt_start == ' ') {
240 alt_start++;
241 }
242 if (*alt_start == '\0') return false;
243
244 // find the end of this alternative
245 const char* alt_end = alt_start;
246 while (*alt_end != '\0' && *alt_end != ',' && *alt_end != ';' &&
247 *alt_end != '|') {
248 alt_end++;
249 }
250 // trim trailing whitespace
251 const char* trimmed_end = alt_end;
252 while (trimmed_end > alt_start && *(trimmed_end - 1) == ' ') {
253 trimmed_end--;
254 }
255
256 size_t alt_len = trimmed_end - alt_start;
257 if (alt_len > 0) {
258 char buffer[64];
259 if (alt_len >= sizeof(buffer)) alt_len = sizeof(buffer) - 1;
260 memcpy(buffer, alt_start, alt_len);
261 buffer[alt_len] = '\0';
262 if (matchesGlob(this->chars, buffer)) return true;
263 }
264
265 if (*alt_end == '\0') return false;
266 alt_start = alt_end + 1;
267 }
268 }
269
270 protected:
273 static bool matchesGlob(const char* line, const char* pattern) {
276 int wildcard = 0;
277
278 const char* last_pattern_start = 0;
279 const char* last_line_start = 0;
280 while (*line) {
281 if (*pattern == *line) {
282 if (wildcard == 1) last_line_start = line + 1;
283
284 line++;
285 pattern++;
286 wildcard = 0;
287 } else if (*pattern == '?') {
288 if (*(line) == '\0')
289 return 0;
290 if (wildcard == 1) last_line_start = line + 1;
291 line++;
292 pattern++;
293 wildcard = 0;
294 } else if (*pattern == '*') {
295 if (*(pattern + 1) == '\0') {
296 return 1;
297 }
298
299 last_pattern_start = pattern;
300 // last_line_start = line + 1;
301 wildcard = 1;
302
303 pattern++;
304 } else if (wildcard) {
305 if (*line == *pattern) {
306 wildcard = 0;
307 line++;
308 pattern++;
309 last_line_start = line + 1;
310 } else {
311 line++;
312 }
313 } else if (last_pattern_start != 0) {
314 pattern = last_pattern_start;
315 line = last_line_start;
316 last_line_start = 0;
317 } else {
318 return false;
319 }
320 }
321
322 // consume any trailing '*' left in the pattern: it matches the (now empty) rest of the line
323 while (*pattern == '*') pattern++;
324
325 if (*pattern == '\0') {
326 return true;
327 } else {
328 return false;
329 }
330 }
331
332 public:
333
336 virtual int indexOf(const char c, int start = 0) {
337 for (int j = start; j < len; j++) {
338 if (c == chars[j]) {
339 return j;
340 }
341 }
342 return -1;
343 }
344
346 virtual int nIndexOf(const char c, int n){
347 int result = -1;
348 for (int j=0; j < n; j++){
349 result = indexOf(c, result + 1);
350 if (result < 0) break;
351 }
352 return result;
353 }
354
356 virtual bool contains(const char* str) { return indexOf(str) != -1; }
357
360 virtual int indexOf(const char* cont, int start = 0) {
361 if (chars == nullptr || cont == nullptr) return -1;
362 int contLen = strlen(cont);
363 for (int j = start; j < len; j++) {
364 char* pt = chars + j;
365 if (strncmp(pt, cont, contLen) == 0) {
366 return j;
367 }
368 }
369 return -1;
370 }
371
373 virtual int lastIndexOf(const char* cont) {
374 if (cont == nullptr) return -1;
375 int contLen = strlen(cont);
376 for (int j = (len - contLen); j >= 0; j--) {
377 if (strncmp(cont, chars + j, contLen) == 0) {
378 return j;
379 }
380 }
381 return -1;
382 }
383
385 virtual int nIndexOf(const char* cont, int n){
386 int result = -1;
387 for (int j=0; j < n; j++){
388 result = indexOf(cont, result + 1);
389 if (result < 0) break;
390 }
391 return result;
392 }
393
395 virtual void operator=(const char* str) { set(str); }
396
398 virtual void operator=(char* str) { set(str); }
399
401 virtual void operator=(char c) { set(c); }
402
404 virtual void operator=(double val) { set(val); }
405
407 virtual void operator=(int value) { set(value); }
408
410 virtual void operator<<(int n) {
411 if (n <= 0 || n > len) return;
412 if (isConst()) {
413 this->chars += n;
414 } else {
415 memmove(this->chars, this->chars + n, len - n + 1);
416 }
417 this->len -= n;
418 }
419
420 virtual char operator[](int index) { return chars[index]; }
421
423 virtual void operator+=(const char* str) { add(str); }
424
426 virtual void operator+=(int value) { add(value); }
427
429 virtual void operator+=(double value) { add(value); }
430
432 virtual void operator+=(const char value) { add(value); }
433
435 virtual bool operator==(const StrView& alt) const {
436 if (this->len != alt.len) return false;
437 return strncmp(this->chars, alt.chars, this->len) == 0;
438 }
439
441 virtual bool operator==(const char* alt) const {
442 return strncmp(this->chars, alt, this->len) == 0;
443 }
444
446 virtual bool operator!=(const StrView& alt) const {
447 return strncmp(this->chars, alt.chars, this->len) != 0;
448 }
449
451 virtual bool operator!=(const char* alt) const {
452 return strncmp(this->chars, alt, this->len) != 0;
453 }
454
456 virtual const char* c_str() { return chars; }
457
460 virtual int length() { return len; }
461
463 virtual bool isEmpty() { return len == 0; }
464
466 virtual int maxLength() { return maxlen; }
467
469 virtual bool replace(const char* toReplace, const char* replaced) {
470 bool result = false;
471 if (toReplace == nullptr || replaced == nullptr) {
472 return result;
473 }
474 if (!isConst()) {
475 int pos = indexOf(toReplace);
476 int old_len = length();
477 int insert_len = 0;
478 if (pos >= 0) {
479 int len_replaced = strlen(replaced);
480 int len_to_replace = strlen(toReplace);
481 insert_len = len_replaced - len_to_replace;
482 grow(this->length() + insert_len);
483 // save remainder and create gap
484 memmove(this->chars + pos + len_replaced,
485 this->chars + pos + len_to_replace,
486 old_len - pos - len_to_replace + 1);
487 // move new string into gap
488 memmove(this->chars + pos, replaced, len_replaced);
489 result = true;
490 len += insert_len;
491 }
492 }
493 return result;
494 }
495
497 virtual bool replaceAll(const char* toReplace, const char* replaced) {
498 if (indexOf(toReplace) == -1) {
499 return false;
500 }
501 while (replace(toReplace, replaced));
502 return true;
503 }
504
506 virtual void remove(const char* toRemove) {
507 if (!isConst() && chars != nullptr) {
508 int removeLen = strlen(toRemove);
509 int pos = indexOf(toRemove);
510 if (pos >= 0) {
511 memmove((void*)(chars + pos), (void*)(chars + pos + removeLen),
512 len - (pos + removeLen) + 1);
513 len -= removeLen;
514 }
515 }
516 }
517
519 virtual void removeAll(const char* toRemove) {
520 if (!isConst() && chars != nullptr) {
521 int removeLen = strlen(toRemove);
522 while (true) {
523 int pos = indexOf(toRemove);
524 if (pos == -1) {
525 break;
526 }
527 memmove((void*)(chars + pos), (void*)(chars + pos + removeLen),
528 len - (pos + removeLen) + 1);
529 len -= removeLen;
530 }
531 }
532 }
533
535 virtual void setLength(int len, bool addZero = true) {
536 if (!isConst() && addZero) {
537 this->savedChar = chars[len];
538 this->savedLen = len;
539 this->len = len;
540 chars[len] = 0;
541 }
542 }
543
545 virtual void setLengthUndo() {
546 if (savedLen >= 0) {
548 this->len = savedLen;
549 savedLen = -1;
550 }
551 }
552
554 virtual void substring(StrView& from, int start, int end) {
555 if (end > start) {
556 int len = end - start;
557 grow(len + 1);
558 if (this->chars != nullptr) {
559 len = len < this->maxlen ? len : this->maxlen - 1;
560 strncpy(this->chars, from.chars + start, len);
561 this->len = len;
562 this->chars[len] = 0;
563 }
564 }
565 }
566
568 virtual void substring(const char* from, int start, int end) {
569 if (end > start) {
570 int len = end - start;
571 grow(len + 1);
572 if (this->chars != nullptr) {
573 len = len < this->maxlen ? len : this->maxlen - 1;
574 strncpy(this->chars, from + start, len);
575 this->chars[len] = 0;
576 this->len = len;
577 }
578 }
579 }
580
582 virtual void trim() {
583 if (chars == nullptr) return;
584 rtrim();
585 ltrim();
586 }
587
589 virtual int count(char c, int startPos) {
590 for (int j = startPos; j < len; j++) {
591 if (chars[j] != c) {
592 return j;
593 }
594 }
595 return len;
596 }
597
599 virtual void ltrim() {
600 if (chars == nullptr) return;
601 int n = count(' ', 0);
602 if (n > 0) *this << n;
603 }
604
606 virtual void rtrim() {
607 if (chars == nullptr || len == 0) return;
608 if (!isConst()) {
609 while (len > 0 && isspace(chars[len - 1])) {
610 len--;
611 chars[len] = 0;
612 }
613 }
614 }
615
617 virtual void clear() {
618 if (chars != nullptr && !isConst()) {
619 chars[0] = 0;
620 }
621 len = 0;
622 }
623
625 virtual bool isOnHeap() { return false; }
626
628 virtual bool isConst() { return is_const; }
629
631 virtual void insert(int pos, const char* str) {
632 if (!isConst()) {
633 int insert_len = strlen(str);
634 grow(this->length() + insert_len);
635 int move_len = this->len - pos + 1;
636 memmove(chars + pos + insert_len, chars + pos, move_len);
637 strncpy(chars + pos, str, insert_len);
638 }
639 }
640
642 virtual bool equalsIgnoreCase(const char* alt) {
643 if (alt == nullptr) return isEmpty();
644 if ((size_t)len != strlen(alt)) {
645 return false;
646 }
647 for (int j = 0; j < len; j++) {
648 if (tolower(chars[j]) != tolower(alt[j])) return false;
649 }
650 return true;
651 }
652
654 int toInt() {
655 int result = 0;
656 if (!isEmpty()) {
657 result = atoi(chars);
658 }
659 return result;
660 }
661
663 long toLong() {
664 long result = 0;
665 if (!isEmpty()) {
666 result = atol(chars);
667 }
668 return result;
669 }
670
672 double toDouble() {
673 double result = 0;
674 char* eptr;
675 if (!isEmpty()) {
676 result = strtod(chars, &eptr);
677 }
678 return result;
679 }
680
682 float toFloat() {
683 float result = 0;
684 char* eptr;
685 if (!isEmpty()) {
686#ifdef USE_STRTOD
687 result = strtof(chars, &eptr);
688#else
689 result = strtod(chars, &eptr);
690#endif
691 }
692 return result;
693 }
694
696 void toLowerCase() {
697 if (chars != nullptr) {
698 for (int j = 0; j < len; j++) {
699 chars[j] = tolower(chars[j]);
700 }
701 }
702 }
703
705 void toUpperCase() {
706 if (chars != nullptr) {
707 for (int j = 0; j < len; j++) {
708 chars[j] = toupper(chars[j]);
709 }
710 }
711 }
712
714 static const char* toBinary(void const* const ptr, size_t const size) {
715 static char result[160];
716 unsigned char* b = (unsigned char*)ptr;
717 unsigned char byte;
718 int i, j, idx = 0;
719
720 for (i = size - 1; i >= 0; i--) {
721 for (j = 7; j >= 0; j--) {
722 byte = (b[i] >> j) & 1;
723 result[idx++] = byte ? '1' : '0';
724 }
725 }
726 result[idx] = 0;
727 return result;
728 }
729
731 for (int j = 0; j < len; j++) {
732 if (isdigit(chars[j])) {
733 return true;
734 }
735 }
736 return false;
737 }
738
740 bool isInteger() {
741 bool result = containsNumber();
742 int minus_count = 0;
743 for (int j = 0; j < len; j++) {
744 char c = chars[j];
745 if (!isdigit(c)) {
746 switch (c) {
747 case '-':
748 minus_count++;
749 if (minus_count > 1) {
750 result = false;
751 }
752 break;
753 default:
754 result = false;
755 break;
756 }
757 }
758 }
759 return result;
760 }
761
764 int result = 0;
765 int pos = indexOf(".");
766 if (pos >= 0) {
767 for (int j = pos + 1; j < len; j++) {
768 if (isdigit(chars[j])) {
769 pos++;
770 } else {
771 break;
772 }
773 }
774 }
775 return result;
776 }
777
778 // Returns true if the string is a number
779 bool isNumber() {
780 bool result = containsNumber();
781 int dot_count = 0;
782 int minus_count = 0;
783 for (int j = 0; j < len; j++) {
784 char c = chars[j];
785 if (!isdigit(c)) {
786 switch (c) {
787 case '-':
788 minus_count++;
789 if (minus_count > 1) {
790 result = false;
791 }
792 break;
793 case '.':
794 dot_count++;
795 if (dot_count > 1) {
796 result = false;
797 }
798 break;
799 default:
800 result = false;
801 break;
802 }
803 }
804 }
805 return result;
806 }
807
808
809 protected:
810 char* chars = nullptr;
811 bool is_const = false;
812 int len = 0;
813 int maxlen = 0;
814 int savedLen = -1;
816
818 virtual bool grow(int newMaxLen) { return false; }
819
820 static char* itoa(int n, char s[]) {
821 int i, sign;
822 if ((sign = n) < 0) /* record sign */
823 n = -n; /* make n positive */
824 i = 0;
825 do { /* generate digits in reverse order */
826 s[i++] = n % 10 + '0'; /* get next digit */
827 } while ((n /= 10) > 0); /* delete it */
828 if (sign < 0) s[i++] = '-';
829 s[i] = '\0';
830 reverse(s);
831 return s;
832 }
833
834 static void reverse(char s[]) {
835 int i, j;
836 char c;
837
838 for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
839 c = s[i];
840 s[i] = s[j];
841 s[j] = c;
842 }
843 }
844
845 static char* floatToString(char* outstr, double val, int precision,
846 int widthp) {
847 char temp[16];
848 int i;
849
851 double roundingFactor = 0.5;
852 unsigned long mult = 1;
853 for (i = 0; i < precision; i++) {
854 roundingFactor /= 10.0;
855 mult *= 10;
856 }
857
858 temp[0] = '\0';
859 outstr[0] = '\0';
860
861 if (val < 0.0) {
862 strcpy(outstr, "-\0");
863 val = -val;
864 }
865
866 val += roundingFactor;
867
868 strcat(outstr, itoa(int(val), temp)); // prints the int part
869 if (precision > 0) {
870 strcat(outstr, ".\0");
871 unsigned long frac;
872 unsigned long mult = 1;
873 int padding = precision - 1;
874 while (precision--) mult *= 10;
875
876 if (val >= 0)
877 frac = (val - int(val)) * mult;
878 else
879 frac = (int(val) - val) * mult;
880 unsigned long frac1 = frac;
881
882 while (frac1 /= 10) padding--;
883
884 while (padding--) strcat(outstr, "0\0");
885
886 strcat(outstr, itoa(frac, temp));
887 }
888
890 if ((widthp != 0) && ((size_t)widthp >= strlen(outstr))) {
891 int J = 0;
892 J = widthp - strlen(outstr);
893
894 for (i = 0; i < J; i++) {
895 temp[i] = ' ';
896 }
897
898 temp[i++] = '\0';
899 strcat(temp, outstr);
900 strcpy(outstr, temp);
901 }
902
903 return outstr;
904 }
905
906 static int strncmp_i(const char* s1, const char* s2, int n) {
907 if (n == 0) return (0);
908 do {
909 if (tolower(*s1) != tolower(*s2++))
910 return (*(unsigned char*)s1 - *(unsigned char*)--s2);
911 if (*s1++ == 0) break;
912 } while (--n != 0);
913 return (0);
914 }
915};
916
917} // namespace audio_tools
A simple wrapper to provide string functions on existing allocated char*. If the underlying char* is ...
Definition StrView.h:29
bool is_const
Definition StrView.h:811
static int strncmp_i(const char *s1, const char *s2, int n)
Definition StrView.h:906
static char * floatToString(char *outstr, double val, int precision, int widthp)
Definition StrView.h:845
virtual void operator=(char *str)
we can assign a char*
Definition StrView.h:398
StrView(const char *chars)
Creates a Str for string constant.
Definition StrView.h:34
virtual bool equals(const char *str)
checks if the string equals indicated parameter string
Definition StrView.h:197
virtual bool grow(int newMaxLen)
only supported in subclasses
Definition StrView.h:818
bool containsNumber()
Definition StrView.h:730
int maxlen
Definition StrView.h:813
virtual void set(int value)
Definition StrView.h:92
virtual void operator=(char c)
we can assign a char
Definition StrView.h:401
virtual void operator+=(const char *str)
adds a substring at the end of the string
Definition StrView.h:423
virtual bool endsWith(const char *str)
checks if the string ends with the indicated substring
Definition StrView.h:210
virtual void substring(const char *from, int start, int end)
copies a substring into the current string
Definition StrView.h:568
virtual bool operator!=(const StrView &alt) const
checks if the indicated string is different from the current string
Definition StrView.h:446
bool isInteger()
Returns true if the string is an integer.
Definition StrView.h:740
virtual int length()
Definition StrView.h:460
virtual void operator=(double val)
we can assign a double
Definition StrView.h:404
virtual void set(char chars[], int maxlen, int len=0, bool isConst=false)
assigns a memory buffer
Definition StrView.h:121
virtual bool equalsIgnoreCase(const char *alt)
Compares the string ignoring the case.
Definition StrView.h:642
virtual int maxLength()
provides the maximum length of the string
Definition StrView.h:466
static char * itoa(int n, char s[])
Definition StrView.h:820
virtual bool isOnHeap()
checks if the string is on the heap
Definition StrView.h:625
virtual bool startsWith(const char *str)
checks if the string starts with the indicated substring
Definition StrView.h:203
virtual bool operator==(const char *alt) const
checks if the indicated string is equal to the current string
Definition StrView.h:441
virtual void operator+=(double value)
adds a double at the end of the string
Definition StrView.h:429
virtual bool isEmpty()
checks if the string is empty
Definition StrView.h:463
char * chars
Definition StrView.h:810
virtual void add(const char c)
adds a character
Definition StrView.h:188
virtual int nIndexOf(const char c, int n)
searches for the nth occurence of the indicated character
Definition StrView.h:346
virtual void operator+=(int value)
adds a int at the end of the string
Definition StrView.h:426
double toDouble()
Converts the string to a double.
Definition StrView.h:672
virtual bool operator==(const StrView &alt) const
checks if the indicated string is equal to the current string
Definition StrView.h:435
virtual bool contains(const char *str)
checks if the string contains a substring
Definition StrView.h:356
virtual int lastIndexOf(const char *cont)
provides the position of the last occurrence of the indicated substring
Definition StrView.h:373
virtual void set(double value, int precision=2, int withd=0)
Definition StrView.h:97
virtual void rtrim()
remove trailing spaces
Definition StrView.h:606
virtual bool replaceAll(const char *toReplace, const char *replaced)
Replaces all instances of toReplace with replaced.
Definition StrView.h:497
static void reverse(char s[])
Definition StrView.h:834
virtual void add(const char *append)
adds a string
Definition StrView.h:151
virtual int count(char c, int startPos)
count number of indicated characters as position
Definition StrView.h:589
int numberOfDecimals()
Determines the number of decimals in the number string.
Definition StrView.h:763
virtual void setLength(int len, bool addZero=true)
limits the length of the string (by adding a delimiting 0)
Definition StrView.h:535
virtual void trim()
remove leading and traling spaces
Definition StrView.h:582
virtual void swap(StrView &str)
Definition StrView.h:102
virtual void operator=(int value)
we can assign an int
Definition StrView.h:407
virtual void set(const char *alt)
assigs a value
Definition StrView.h:48
virtual char operator[](int index)
Definition StrView.h:420
virtual void operator+=(const char value)
adds a character
Definition StrView.h:432
int savedLen
Definition StrView.h:814
virtual void operator=(const char *str)
we can assign a const char*
Definition StrView.h:395
virtual bool replace(const char *toReplace, const char *replaced)
Replaces the first instance of toReplace with replaced.
Definition StrView.h:469
StrView(char chars[], int maxlen, int len=0)
Creates a Str with the indicated buffer.
Definition StrView.h:45
virtual void clear()
clears the string by setting the terminating 0 at the beginning
Definition StrView.h:617
long toLong()
Converts the string to an long.
Definition StrView.h:663
virtual void ltrim()
remove leading spaces
Definition StrView.h:599
virtual bool matches(const char *pattern)
Definition StrView.h:229
virtual int nIndexOf(const char *cont, int n)
searches for the nth occurence of the indicated character
Definition StrView.h:385
virtual void substring(StrView &from, int start, int end)
copies a substring into the current string
Definition StrView.h:554
virtual const char * c_str()
provides the string value as const char*
Definition StrView.h:456
virtual const char * printf(const char *fmt,...)
Definition StrView.h:166
float toFloat()
Converts the string to a float.
Definition StrView.h:682
virtual void removeAll(const char *toRemove)
removes the indicated substring from the string
Definition StrView.h:519
static bool matchesGlob(const char *line, const char *pattern)
Definition StrView.h:273
virtual void operator<<(int n)
shift characters to the left -> we just move the pointer
Definition StrView.h:410
virtual bool endsWithIgnoreCase(const char *str)
checks if the string ends with the indicated substring
Definition StrView.h:218
virtual void set(const StrView &alt)
assigs from another Str value
Definition StrView.h:70
int toInt()
Converts the string to an int.
Definition StrView.h:654
virtual void add(double value, int precision=2, int withd=0)
adds a double value
Definition StrView.h:142
virtual int indexOf(const char *cont, int start=0)
Definition StrView.h:360
virtual void remove(const char *toRemove)
removes the indicated substring from the string
Definition StrView.h:506
char savedChar
Definition StrView.h:815
virtual bool isConst()
checks if the string is a constant that must not be changed
Definition StrView.h:628
bool isNumber()
Definition StrView.h:779
virtual void insert(int pos, const char *str)
inserts a substring into the string
Definition StrView.h:631
virtual int indexOf(const char c, int start=0)
Definition StrView.h:336
virtual void add(int value)
adds a int value
Definition StrView.h:133
virtual void set(const char c)
Definition StrView.h:87
static const char * toBinary(void const *const ptr, size_t const size)
provides a binary string represntation
Definition StrView.h:714
void toLowerCase()
Converts the string to lowercase letters.
Definition StrView.h:696
virtual void setLengthUndo()
undo the last setLength call
Definition StrView.h:545
void toUpperCase()
Converts the string to uppercase letters.
Definition StrView.h:705
int len
Definition StrView.h:812
virtual bool operator!=(const char *alt) const
checks if the indicated string is different from the current string
Definition StrView.h:451
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6