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