25 Str(
int initialAllocatedLength = 0) {
26 maxlen = initialAllocatedLength;
36 if (
chars !=
nullptr) {
96 if (this->
chars !=
nullptr) {
107 if (this->
chars !=
nullptr) {
108 for (
int j = 0; j <
len; j++) {
122 for (
size_t i = 0; i <
len; i++) {
124 new_size += strlen(temp);
127 char result[new_size + 1];
128 memset(result,0, new_size+1);
129 for (
size_t i = 0; i <
len; i++) {
131 strcat(result, temp);
135 strcpy(
chars, result);
136 this->len = strlen(temp);
143 size_t result_idx = 0;
145 if (
chars[i] ==
'%') {
146 szTemp[0] =
chars[i + 1];
147 szTemp[1] =
chars[i + 2];
150 }
else if (
chars[i] ==
'+') {
151 chars[result_idx] =
' ';
159 chars[result_idx] = 0;
160 this->
len = result_idx;
197 if (end > start && this->
chars !=
nullptr) {
198 int len = end - start;
201 char* target = (
char*) result.
c_str();
202 strncpy(target, this->
c_str() + start,
len);
210 if (n >= this->
length()) {
215 int remaining = this->
length() - n;
216 memmove(this->
chars, this->
chars + n, remaining);
217 this->
chars[remaining] = 0;
218 this->
len = remaining;
232 bool grow(
int newMaxLen)
override {
234 assert(newMaxLen < 1024 * 10);
235 if (newMaxLen < 0)
return false;
236 if (newMaxLen == 0 &&
chars ==
nullptr)
return false;
251 snprintf(result, maxLen,
"%c", c);
252 }
else if (isspace(c)) {
253 snprintf(result, maxLen,
"%s",
"+");
255 snprintf(result, maxLen,
"%%%X%X", c >> 4, c % 16);
260 if (ch >=
'0' && ch <=
'9') {
261 return (
char)(ch -
'0');
263 if (ch >=
'a' && ch <=
'f') {
264 return (
char)(ch -
'a' + 10);
266 if (ch >=
'A' && ch <=
'F') {
267 return (
char)(ch -
'A' + 10);
277 ch = (szBuffer[0] << 4) | szBuffer[1];
A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not a...
Definition: StrView.h:19
char * chars
Definition: StrView.h:756
virtual int length()
Definition: StrView.h:380
int len
Definition: StrView.h:758
int maxlen
Definition: StrView.h:759
virtual void set(const char *alt)
assigs a value
Definition: StrView.h:45
bool is_const
Definition: StrView.h:757
String implementation which keeps the data on the heap. We grow the allocated memory only if the copy...
Definition: Str.h:22
void resize(int size)
Definition: Str.h:170
void operator=(const char *str) override
we can assign a const char*
Definition: Str.h:73
const char * c_str()
provides the string value as const char*
Definition: Str.h:187
void urlEncode()
url encode the string
Definition: Str.h:118
void clear() override
clears the string by setting the terminating 0 at the beginning
Definition: Str.h:163
Str(const char *str)
Definition: Str.h:31
Str substring(int start, int end)
copies a substring into the current string
Definition: Str.h:195
char charToInt(char ch)
Definition: Str.h:259
bool isOnHeap() override
checks if the string is on the heap
Definition: Str.h:69
Str(Str &&obj)
Move constructor.
Definition: Str.h:49
void setChars(char c, int len)
Fills the string with len chars.
Definition: Str.h:105
Str & operator=(Str &&obj)
Move assignment.
Definition: Str.h:58
void copyFrom(const char *source, int len, int maxlen=0)
assigns a memory buffer
Definition: Str.h:93
Str(Str &source)
Copy constructor.
Definition: Str.h:46
size_t capacity()
Definition: Str.h:81
void urlDecode()
decodes a url encoded string
Definition: Str.h:140
Vector< char > vector
Definition: Str.h:224
void reset()
Definition: Str.h:190
void allocate(int len=-1)
Definition: Str.h:86
bool grow(int newMaxLen) override
only supported in subclasses
Definition: Str.h:232
Str & operator=(Str &obj)
Copy assingment.
Definition: Str.h:63
Str(StrView &source)
Convert StrView to Str.
Definition: Str.h:43
void swap(Str &other)
Definition: Str.h:177
char strToBin(char *pString)
Definition: Str.h:272
void operator=(double v) override
we can assign a double
Definition: Str.h:79
bool isConst() override
checks if the string is a constant that must not be changed
Definition: Str.h:71
Str(int initialAllocatedLength=0)
Definition: Str.h:25
~Str()
Destructor.
Definition: Str.h:52
void operator=(char *str) override
we can assign a char*
Definition: Str.h:75
void setCapacity(size_t newLen)
Definition: Str.h:83
void urlEncodeChar(char c, char *result, int maxLen)
Definition: Str.h:249
void remove(int n)
removes the first n characters
Definition: Str.h:209
Str & move(Str &other)
Definition: Str.h:226
void operator=(int v) override
we can assign an int
Definition: Str.h:77
Vector implementation which provides the most important methods as defined by std::vector....
Definition: Vector.h:21
bool resize(int newSize, T value)
Definition: Vector.h:251
void swap(Vector< T > &in)
Definition: Vector.h:229
T * data()
Definition: Vector.h:298
Definition: Allocator.h:6