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