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