diff --git a/_container_a_v_i_8h_source.html b/_container_a_v_i_8h_source.html index a7212834b2..bef22b9001 100644 --- a/_container_a_v_i_8h_source.html +++ b/_container_a_v_i_8h_source.html @@ -774,8 +774,8 @@
audio_tools::Print
Definition: NoArduino.h:58
audio_tools::Stack
LIFO Stack which is based on a List.
Definition: Stack.h:14
audio_tools::StrExt
Str which keeps the data on the heap. We grow the allocated memory only if the copy source is not fit...
Definition: StrExt.h:23
-
audio_tools::StrExt::copyFrom
void copyFrom(const char *source, int len, int maxlen=0)
assigns a memory buffer
Definition: StrExt.h:111
-
audio_tools::StrExt::setChars
void setChars(char c, int len)
Fills the string with len chars.
Definition: StrExt.h:123
+
audio_tools::StrExt::copyFrom
void copyFrom(const char *source, int len, int maxlen=0)
assigns a memory buffer
Definition: StrExt.h:89
+
audio_tools::StrExt::setChars
void setChars(char c, int len)
Fills the string with len chars.
Definition: StrExt.h:101
audio_tools::Str
A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not a...
Definition: Str.h:26
audio_tools::Str::equals
virtual bool equals(const char *str)
checks if the string equals indicated parameter string
Definition: Str.h:170
audio_tools::Str::c_str
virtual const char * c_str()
provides the string value as const char*
Definition: Str.h:412
diff --git a/_str_ext_8h_source.html b/_str_ext_8h_source.html index 6b6c2aa311..5ead19f820 100644 --- a/_str_ext_8h_source.html +++ b/_str_ext_8h_source.html @@ -77,148 +77,201 @@
6 
23 class StrExt : public Str {
24 
-
25  public:
-
26  StrExt() = default;
+
25 public:
+
26  StrExt() = default;
27 
-
28  StrExt(int initialAllocatedLength) : Str() {
-
29  maxlen = initialAllocatedLength;
-
30  is_const = false;
-
31  }
+
28  StrExt(int initialAllocatedLength) : Str() {
+
29  maxlen = initialAllocatedLength;
+
30  is_const = false;
+
31  }
32 
-
33  StrExt(Str &source) : Str() {
-
34  set(source);
-
35  }
-
36 
-
37  StrExt(StrExt &source) : Str(){
-
38  set(source);
-
39  }
-
40 
-
41  StrExt(const char* str) : Str() {
-
42  if (str!=nullptr){
-
43  len = strlen(str);
-
44  maxlen = len;
-
45  grow(maxlen);
-
46  if (chars!=nullptr){
-
47  strcpy(chars, str);
-
48  }
-
49  }
-
50  }
-
51 
-
52  // move constructor
-
53  StrExt (StrExt &&obj) = default;
-
54 
-
55  // move assignment
-
56  StrExt& operator = (StrExt &&obj) {
-
57  set(obj.c_str());
-
58  return *this;
-
59  }
-
60 
-
61  // copy assingment
-
62  StrExt& operator = (StrExt &obj) {
-
63  set(obj.c_str());
-
64  return *this;
-
65  };
+
33  StrExt(Str &source) : Str() { set(source); }
+
34 
+
35  StrExt(StrExt &source) : Str() { set(source); }
+
36 
+
37  StrExt(const char *str) : Str() {
+
38  if (str != nullptr) {
+
39  len = strlen(str);
+
40  maxlen = len;
+
41  grow(maxlen);
+
42  if (chars != nullptr) {
+
43  strcpy(chars, str);
+
44  }
+
45  }
+
46  }
+
47 
+
48  // move constructor
+
49  StrExt(StrExt &&obj) = default;
+
50 
+
51  // move assignment
+
52  StrExt &operator=(StrExt &&obj) {
+
53  set(obj.c_str());
+
54  return *this;
+
55  }
+
56 
+
57  // copy assingment
+
58  StrExt &operator=(StrExt &obj) {
+
59  set(obj.c_str());
+
60  return *this;
+
61  };
+
62 
+
63  ~StrExt() {}
+
64 
+
65  bool isOnHeap() override { return true; }
66 
-
67 
-
68  ~StrExt() {
-
69  }
+
67  bool isConst() override { return false; }
+
68 
+
69  void operator=(const char *str) { set(str); }
70 
-
71  bool isOnHeap() override {
-
72  return true;
-
73  }
-
74 
-
75  bool isConst() override {
-
76  return false;
-
77  }
+
71  void operator=(char *str) { set(str); }
+
72 
+
73  void operator=(int v) { set(v); }
+
74 
+
75  void operator=(double v) { set(v); }
+
76 
+
77  size_t capacity() { return maxlen; }
78 
-
79  void operator=(const char* str) {
-
80  set(str);
-
81  }
-
82 
-
83  void operator=(char* str) {
-
84  set(str);
-
85  }
-
86 
-
87  void operator=(int v) {
-
88  set(v);
-
89  }
-
90 
-
91  void operator=(double v) {
-
92  set(v);
-
93  }
-
94 
-
95  size_t capacity() {
-
96  return maxlen;
-
97  }
-
98 
-
99  void setCapacity(size_t newLen){
-
100  grow(newLen);
-
101  }
-
102 
-
103  // make sure that the max size is allocated
-
104  void allocate(int len=-1) {
-
105  int new_size = len<0?maxlen:len;
-
106  grow(new_size);
-
107  this->len = new_size;
-
108  }
-
109 
-
111  void copyFrom(const char *source, int len, int maxlen=0){
-
112  this->maxlen = maxlen==0? len : maxlen;
-
113  grow(this->maxlen);
-
114  if (this->chars!=nullptr){
-
115  this->len = len;
-
116  this->is_const = false;
-
117  memmove(this->chars, source, len);
-
118  this->chars[len] = 0;
-
119  }
-
120  }
-
121 
-
123  void setChars(char c, int len){
-
124  grow(this->maxlen);
-
125  if (this->chars!=nullptr){
-
126  for (int j=0;j<len;j++){
-
127  this->chars[j]=c;
-
128  }
-
129  this->len = len;
-
130  this->is_const = false;
-
131  this->chars[len]=0;
-
132  }
-
133  }
-
134 
-
135  protected:
-
136  Vector<char> vector;
-
137 
-
138  bool grow(int newMaxLen){
-
139  bool grown = false;
-
140  assert(newMaxLen<1024*10);
-
141 
-
142  if (chars==nullptr || newMaxLen > maxlen ){
-
143  LOGD("grow(%d)",newMaxLen);
-
144 
-
145  grown = true;
-
146  // we use at minimum the defined maxlen
-
147  int newSize = newMaxLen > maxlen ? newMaxLen : maxlen;
-
148  vector.resize(newSize+1);
-
149  chars = &vector[0];
-
150  maxlen = newSize;
-
151 
-
152  }
-
153  return grown;
-
154  }
-
155 };
-
156 
-
157 }
-
158 
+
79  void setCapacity(size_t newLen) { grow(newLen); }
+
80 
+
81  // make sure that the max size is allocated
+
82  void allocate(int len = -1) {
+
83  int new_size = len < 0 ? maxlen : len;
+
84  grow(new_size);
+
85  this->len = new_size;
+
86  }
+
87 
+
89  void copyFrom(const char *source, int len, int maxlen = 0) {
+
90  this->maxlen = maxlen == 0 ? len : maxlen;
+
91  grow(this->maxlen);
+
92  if (this->chars != nullptr) {
+
93  this->len = len;
+
94  this->is_const = false;
+
95  memmove(this->chars, source, len);
+
96  this->chars[len] = 0;
+
97  }
+
98  }
+
99 
+
101  void setChars(char c, int len) {
+
102  grow(this->maxlen);
+
103  if (this->chars != nullptr) {
+
104  for (int j = 0; j < len; j++) {
+
105  this->chars[j] = c;
+
106  }
+
107  this->len = len;
+
108  this->is_const = false;
+
109  this->chars[len] = 0;
+
110  }
+
111  }
+
112 
+
114  void urlEncode() {
+
115  char temp[4];
+
116  int new_size = 0;
+
117  // Calculate the new size
+
118  for (size_t i = 0; i < len; i++) {
+
119  urlEncodeChar(chars[i], temp, 4);
+
120  new_size += strlen(temp);
+
121  }
+
122  // build new string
+
123  char result[new_size + 1] = {0};
+
124  for (size_t i = 0; i < len; i++) {
+
125  urlEncodeChar(chars[i], temp, 4);
+
126  strcat(result, temp);
+
127  }
+
128  // save result
+
129  grow(new_size);
+
130  strcpy(chars, result);
+
131  this->len = strlen(temp);
+
132  }
+
133 
+
135  void urlDecode() {
+
136  char szTemp[2];
+
137  size_t i = 0;
+
138  size_t result_idx = 0;
+
139  while (i < len) {
+
140  if (chars[i] == '%') {
+
141  szTemp[0] = chars[i + 1];
+
142  szTemp[1] = chars[i + 2];
+
143  chars[result_idx] = strToBin(szTemp);
+
144  i = i + 3;
+
145  } else if (chars[i] == '+') {
+
146  chars[result_idx] = ' ';
+
147  i++;
+
148  } else {
+
149  chars[result_idx] += chars[i];
+
150  i++;
+
151  }
+
152  result_idx++;
+
153  }
+
154  chars[result_idx] = 0;
+
155  this->len = result_idx;
+
156  }
+
157 
+
158 protected:
+
159  Vector<char> vector;
+
160 
+
161  bool grow(int newMaxLen) {
+
162  bool grown = false;
+
163  assert(newMaxLen < 1024 * 10);
+
164 
+
165  if (chars == nullptr || newMaxLen > maxlen) {
+
166  LOGD("grow(%d)", newMaxLen);
+
167 
+
168  grown = true;
+
169  // we use at minimum the defined maxlen
+
170  int newSize = newMaxLen > maxlen ? newMaxLen : maxlen;
+
171  vector.resize(newSize + 1);
+
172  chars = &vector[0];
+
173  maxlen = newSize;
+
174  }
+
175  return grown;
+
176  }
+
177 
+
178  void urlEncodeChar(char c, char *result, int maxLen) {
+
179  if (isalnum(c)) {
+
180  snprintf(result, maxLen, "%c", c);
+
181  } else if (isspace(c)) {
+
182  snprintf(result, maxLen, "%s", "+");
+
183  } else {
+
184  snprintf(result, maxLen, "%%%X%X", c >> 4, c % 16);
+
185  }
+
186  }
+
187 
+
188  char charToInt(char ch) {
+
189  if (ch >= '0' && ch <= '9') {
+
190  return (char)(ch - '0');
+
191  }
+
192  if (ch >= 'a' && ch <= 'f') {
+
193  return (char)(ch - 'a' + 10);
+
194  }
+
195  if (ch >= 'A' && ch <= 'F') {
+
196  return (char)(ch - 'A' + 10);
+
197  }
+
198  return -1;
+
199  }
+
200 
+
201  char strToBin(char *pString) {
+
202  char szBuffer[2];
+
203  char ch;
+
204  szBuffer[0] = charToInt(pString[0]); // make the B to 11 -- 00001011
+
205  szBuffer[1] = charToInt(pString[1]); // make the 0 to 0 -- 00000000
+
206  ch = (szBuffer[0] << 4) | szBuffer[1]; // to change the BO to 10110000
+
207  return ch;
+
208  }
+
209 };
+
210 
+
211 } // namespace audio_tools
audio_tools::StrExt
Str which keeps the data on the heap. We grow the allocated memory only if the copy source is not fit...
Definition: StrExt.h:23
-
audio_tools::StrExt::grow
bool grow(int newMaxLen)
only supported in subclasses
Definition: StrExt.h:138
-
audio_tools::StrExt::copyFrom
void copyFrom(const char *source, int len, int maxlen=0)
assigns a memory buffer
Definition: StrExt.h:111
-
audio_tools::StrExt::operator=
void operator=(const char *str)
we can assign a const char*
Definition: StrExt.h:79
-
audio_tools::StrExt::operator=
void operator=(int v)
we can assign an int
Definition: StrExt.h:87
-
audio_tools::StrExt::isConst
bool isConst() override
checks if the string is a constant that must not be changed
Definition: StrExt.h:75
-
audio_tools::StrExt::operator=
void operator=(char *str)
we can assign a char*
Definition: StrExt.h:83
-
audio_tools::StrExt::setChars
void setChars(char c, int len)
Fills the string with len chars.
Definition: StrExt.h:123
-
audio_tools::StrExt::operator=
void operator=(double v)
we can assign a double
Definition: StrExt.h:91
-
audio_tools::StrExt::isOnHeap
bool isOnHeap() override
checks if the string is on the heap
Definition: StrExt.h:71
+
audio_tools::StrExt::grow
bool grow(int newMaxLen)
only supported in subclasses
Definition: StrExt.h:161
+
audio_tools::StrExt::urlDecode
void urlDecode()
decodes a url encoded string
Definition: StrExt.h:135
+
audio_tools::StrExt::copyFrom
void copyFrom(const char *source, int len, int maxlen=0)
assigns a memory buffer
Definition: StrExt.h:89
+
audio_tools::StrExt::operator=
void operator=(const char *str)
we can assign a const char*
Definition: StrExt.h:69
+
audio_tools::StrExt::operator=
void operator=(int v)
we can assign an int
Definition: StrExt.h:73
+
audio_tools::StrExt::isConst
bool isConst() override
checks if the string is a constant that must not be changed
Definition: StrExt.h:67
+
audio_tools::StrExt::operator=
void operator=(char *str)
we can assign a char*
Definition: StrExt.h:71
+
audio_tools::StrExt::setChars
void setChars(char c, int len)
Fills the string with len chars.
Definition: StrExt.h:101
+
audio_tools::StrExt::urlEncode
void urlEncode()
url encode the string
Definition: StrExt.h:114
+
audio_tools::StrExt::operator=
void operator=(double v)
we can assign a double
Definition: StrExt.h:75
+
audio_tools::StrExt::isOnHeap
bool isOnHeap() override
checks if the string is on the heap
Definition: StrExt.h:65
audio_tools::Str
A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not a...
Definition: Str.h:26
audio_tools::Str::set
virtual void set(const char *alt)
assigs a value
Definition: Str.h:52
audio_tools::Str::c_str
virtual const char * c_str()
provides the string value as const char*
Definition: Str.h:412
diff --git a/classaudio__tools_1_1_str_ext-members.html b/classaudio__tools_1_1_str_ext-members.html index 62fc831d2a..db95e81b3e 100644 --- a/classaudio__tools_1_1_str_ext-members.html +++ b/classaudio__tools_1_1_str_ext-members.html @@ -80,85 +80,87 @@ c_str()Strinlinevirtual capacity() (defined in StrExt)StrExtinline chars (defined in Str)Strprotected - clear()Strinlinevirtual - contains(const char *str)Strinlinevirtual - containsNumber() (defined in Str)Strinline - copyFrom(const char *source, int len, int maxlen=0)StrExtinline - count(char c, int startPos)Strinlinevirtual - endsWith(const char *str)Strinlinevirtual - endsWithIgnoreCase(const char *str)Strinlinevirtual - equals(const char *str)Strinlinevirtual - equalsIgnoreCase(const char *alt)Strinlinevirtual - floatToString(char *outstr, double val, int precision, int widthp)Strinlineprotectedstatic - grow(int newMaxLen)StrExtinlineprotectedvirtual - indexOf(const char c, int start=0)Strinlinevirtual - indexOf(const char *cont, int start=0)Strinlinevirtual - insert(int pos, const char *str)Strinlinevirtual - is_const (defined in Str)Strprotected - isConst() overrideStrExtinlinevirtual - isEmpty()Strinlinevirtual - isInteger()Strinline - isNumber() (defined in Str)Strinline - isOnHeap() overrideStrExtinlinevirtual - itoa(int n, char s[]) (defined in Str)Strinlineprotectedstatic - lastIndexOf(const char *cont)Strinlinevirtual - len (defined in Str)Strprotected - length()Strinlinevirtual - ltrim()Strinlinevirtual - matches(const char *pattern)Strinlinevirtual - maxlen (defined in Str)Strprotected - maxLength()Strinlinevirtual - numberOfDecimals()Strinline - operator!=(const Str &alt) constStrinlinevirtual - operator!=(const char *alt) constStrinlinevirtual - operator+=(const char *str)Strinlinevirtual - operator+=(int value)Strinlinevirtual - operator+=(double value)Strinlinevirtual - operator+=(const char value)Strinlinevirtual - operator<<(int n)Strinlinevirtual - operator=(StrExt &&obj) (defined in StrExt)StrExtinline - operator=(StrExt &obj) (defined in StrExt)StrExtinline - operator=(const char *str)StrExtinlinevirtual - operator=(char *str)StrExtinlinevirtual - operator=(int v)StrExtinlinevirtual - operator=(double v)StrExtinlinevirtual - operator=(const Str &)=default (defined in Str)Str - operator=(Str &&)=default (defined in Str)Str - audio_tools::Str::operator=(char c)Strinlinevirtual - operator==(const Str &alt) constStrinlinevirtual - operator==(const char *alt) constStrinlinevirtual - operator[](int index) (defined in Str)Strinlinevirtual - remove(const char *toRemove)Strinlinevirtual - removeAll(const char *toRemove)Strinlinevirtual - replace(const char *toReplace, const char *replaced)Strinlinevirtual - replaceAll(const char *toReplace, const char *replaced)Strinlinevirtual - reverse(char s[]) (defined in Str)Strinlineprotectedstatic - rtrim()Strinlinevirtual - savedChar (defined in Str)Strprotected - savedLen (defined in Str)Strprotected - set(const char *alt)Strinlinevirtual - set(const Str &alt)Strinlinevirtual - set(const char c) (defined in Str)Strinlinevirtual - set(int value) (defined in Str)Strinlinevirtual - set(double value, int precision=2, int withd=0) (defined in Str)Strinlinevirtual - set(char chars[], int maxlen, int len=0, bool isConst=false)Strinlinevirtual - setCapacity(size_t newLen) (defined in StrExt)StrExtinline - setChars(char c, int len)StrExtinline - setLength(int len, bool addZero=true)Strinlinevirtual - setLengthUndo()Strinlinevirtual - startsWith(const char *str)Strinlinevirtual - Str()=default (defined in Str)Str - Str(const char *chars)Strinline - Str(char chars[], int maxlen, int len=0)Strinline - Str(const Str &)=default (defined in Str)Str - Str(Str &&)=default (defined in Str)Str - StrExt()=default (defined in StrExt)StrExt - StrExt(int initialAllocatedLength) (defined in StrExt)StrExtinline - StrExt(Str &source) (defined in StrExt)StrExtinline - StrExt(StrExt &source) (defined in StrExt)StrExtinline - StrExt(const char *str) (defined in StrExt)StrExtinline - StrExt(StrExt &&obj)=default (defined in StrExt)StrExt - strncmp_i(const char *s1, const char *s2, int n) (defined in Str)Strinlineprotectedstatic + charToInt(char ch) (defined in StrExt)StrExtinlineprotected + clear()Strinlinevirtual + contains(const char *str)Strinlinevirtual + containsNumber() (defined in Str)Strinline + copyFrom(const char *source, int len, int maxlen=0)StrExtinline + count(char c, int startPos)Strinlinevirtual + endsWith(const char *str)Strinlinevirtual + endsWithIgnoreCase(const char *str)Strinlinevirtual + equals(const char *str)Strinlinevirtual + equalsIgnoreCase(const char *alt)Strinlinevirtual + floatToString(char *outstr, double val, int precision, int widthp)Strinlineprotectedstatic + grow(int newMaxLen)StrExtinlineprotectedvirtual + indexOf(const char c, int start=0)Strinlinevirtual + indexOf(const char *cont, int start=0)Strinlinevirtual + insert(int pos, const char *str)Strinlinevirtual + is_const (defined in Str)Strprotected + isConst() overrideStrExtinlinevirtual + isEmpty()Strinlinevirtual + isInteger()Strinline + isNumber() (defined in Str)Strinline + isOnHeap() overrideStrExtinlinevirtual + itoa(int n, char s[]) (defined in Str)Strinlineprotectedstatic + lastIndexOf(const char *cont)Strinlinevirtual + len (defined in Str)Strprotected + length()Strinlinevirtual + ltrim()Strinlinevirtual + matches(const char *pattern)Strinlinevirtual + maxlen (defined in Str)Strprotected + maxLength()Strinlinevirtual + numberOfDecimals()Strinline + operator!=(const Str &alt) constStrinlinevirtual + operator!=(const char *alt) constStrinlinevirtual + operator+=(const char *str)Strinlinevirtual + operator+=(int value)Strinlinevirtual + operator+=(double value)Strinlinevirtual + operator+=(const char value)Strinlinevirtual + operator<<(int n)Strinlinevirtual + operator=(StrExt &&obj) (defined in StrExt)StrExtinline + operator=(StrExt &obj) (defined in StrExt)StrExtinline + operator=(const char *str)StrExtinlinevirtual + operator=(char *str)StrExtinlinevirtual + operator=(int v)StrExtinlinevirtual + operator=(double v)StrExtinlinevirtual + operator=(const Str &)=default (defined in Str)Str + operator=(Str &&)=default (defined in Str)Str + audio_tools::Str::operator=(char c)Strinlinevirtual + operator==(const Str &alt) constStrinlinevirtual + operator==(const char *alt) constStrinlinevirtual + operator[](int index) (defined in Str)Strinlinevirtual + remove(const char *toRemove)Strinlinevirtual + removeAll(const char *toRemove)Strinlinevirtual + replace(const char *toReplace, const char *replaced)Strinlinevirtual + replaceAll(const char *toReplace, const char *replaced)Strinlinevirtual + reverse(char s[]) (defined in Str)Strinlineprotectedstatic + rtrim()Strinlinevirtual + savedChar (defined in Str)Strprotected + savedLen (defined in Str)Strprotected + set(const char *alt)Strinlinevirtual + set(const Str &alt)Strinlinevirtual + set(const char c) (defined in Str)Strinlinevirtual + set(int value) (defined in Str)Strinlinevirtual + set(double value, int precision=2, int withd=0) (defined in Str)Strinlinevirtual + set(char chars[], int maxlen, int len=0, bool isConst=false)Strinlinevirtual + setCapacity(size_t newLen) (defined in StrExt)StrExtinline + setChars(char c, int len)StrExtinline + setLength(int len, bool addZero=true)Strinlinevirtual + setLengthUndo()Strinlinevirtual + startsWith(const char *str)Strinlinevirtual + Str()=default (defined in Str)Str + Str(const char *chars)Strinline + Str(char chars[], int maxlen, int len=0)Strinline + Str(const Str &)=default (defined in Str)Str + Str(Str &&)=default (defined in Str)Str + StrExt()=default (defined in StrExt)StrExt + StrExt(int initialAllocatedLength) (defined in StrExt)StrExtinline + StrExt(Str &source) (defined in StrExt)StrExtinline + StrExt(StrExt &source) (defined in StrExt)StrExtinline + StrExt(const char *str) (defined in StrExt)StrExtinline + StrExt(StrExt &&obj)=default (defined in StrExt)StrExt + strncmp_i(const char *s1, const char *s2, int n) (defined in Str)Strinlineprotectedstatic + strToBin(char *pString) (defined in StrExt)StrExtinlineprotected substring(Str &from, int start, int end)Strinlinevirtual substring(const char *from, int start, int end)Strinlinevirtual swap(Str &str) (defined in Str)Strinlinevirtual @@ -169,8 +171,11 @@ toLowerCase()Strinline toUpperCase()Strinline trim()Strinlinevirtual - vector (defined in StrExt)StrExtprotected - ~StrExt() (defined in StrExt)StrExtinline + urlDecode()StrExtinline + urlEncode()StrExtinline + urlEncodeChar(char c, char *result, int maxLen) (defined in StrExt)StrExtinlineprotected + vector (defined in StrExt)StrExtprotected + ~StrExt() (defined in StrExt)StrExtinline