26 Str(
int initialAllocatedLength) :
Str() {
27 maxlen = initialAllocatedLength;
37 if (
chars !=
nullptr) {
97 if (this->
chars !=
nullptr) {
108 if (this->
chars !=
nullptr) {
109 for (
int j = 0; j <
len; j++) {
123 for (
size_t i = 0; i <
len; i++) {
125 new_size += strlen(temp);
128 char result[new_size + 1];
129 memset(result,0, new_size+1);
130 for (
size_t i = 0; i <
len; i++) {
132 strcat(result, temp);
136 strcpy(
chars, result);
137 this->len = strlen(temp);
144 size_t result_idx = 0;
146 if (
chars[i] ==
'%') {
147 szTemp[0] =
chars[i + 1];
148 szTemp[1] =
chars[i + 2];
151 }
else if (
chars[i] ==
'+') {
152 chars[result_idx] =
' ';
160 chars[result_idx] = 0;
161 this->
len = result_idx;
198 if (end > start && this->
chars !=
nullptr) {
199 int len = end - start;
202 char* target = (
char*) result.
c_str();
203 strncpy(target, this->
c_str() + start,
len);
219 bool grow(
int newMaxLen)
override {
221 assert(newMaxLen < 1024 * 10);
222 if (newMaxLen < 0)
return false;
237 snprintf(result, maxLen,
"%c", c);
238 }
else if (isspace(c)) {
239 snprintf(result, maxLen,
"%s",
"+");
241 snprintf(result, maxLen,
"%%%X%X", c >> 4, c % 16);
246 if (ch >=
'0' && ch <=
'9') {
247 return (
char)(ch -
'0');
249 if (ch >=
'a' && ch <=
'f') {
250 return (
char)(ch -
'a' + 10);
252 if (ch >=
'A' && ch <=
'F') {
253 return (
char)(ch -
'A' + 10);
263 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:750
int len
Definition: StrView.h:752
int maxlen
Definition: StrView.h:753
virtual void set(const char *alt)
assigs a value
Definition: StrView.h:45
bool is_const
Definition: StrView.h:751
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:171
Str(int initialAllocatedLength)
Definition: Str.h:26
void operator=(const char *str) override
we can assign a const char*
Definition: Str.h:74
void urlEncode()
url encode the string
Definition: Str.h:119
void clear() override
clears the string by setting the terminating 0 at the beginning
Definition: Str.h:164
Str(const char *str)
Definition: Str.h:32
Str & operator=(Str &obj)
Copy assingment.
Definition: Str.h:64
Str substring(int start, int end)
copies a substring into the current string
Definition: Str.h:196
char charToInt(char ch)
Definition: Str.h:245
bool isOnHeap() override
checks if the string is on the heap
Definition: Str.h:70
Str(Str &&obj)
Move constructor.
Definition: Str.h:50
void setChars(char c, int len)
Fills the string with len chars.
Definition: Str.h:106
void copyFrom(const char *source, int len, int maxlen=0)
assigns a memory buffer
Definition: Str.h:94
Str(Str &source)
Copy constructor.
Definition: Str.h:47
size_t capacity()
Definition: Str.h:82
void urlDecode()
decodes a url encoded string
Definition: Str.h:141
Str & operator=(Str &&obj)
Move assignment.
Definition: Str.h:59
Vector< char > vector
Definition: Str.h:211
void reset()
Definition: Str.h:191
Str & move(Str &other)
Definition: Str.h:213
void allocate(int len=-1)
Definition: Str.h:87
bool grow(int newMaxLen) override
only supported in subclasses
Definition: Str.h:219
Str(StrView &source)
Convert StrView to Str.
Definition: Str.h:44
void swap(Str &other)
Definition: Str.h:178
char strToBin(char *pString)
Definition: Str.h:258
void operator=(double v) override
we can assign a double
Definition: Str.h:80
bool isConst() override
checks if the string is a constant that must not be changed
Definition: Str.h:72
~Str()
Destructor.
Definition: Str.h:53
void operator=(char *str) override
we can assign a char*
Definition: Str.h:76
void setCapacity(size_t newLen)
Definition: Str.h:84
void urlEncodeChar(char c, char *result, int maxLen)
Definition: Str.h:235
void operator=(int v) override
we can assign an int
Definition: Str.h:78
const char * c_str()
provides the string value as const char*
Definition: Str.h:188
bool resize(int newSize, T value)
Definition: Vector.h:247
void swap(Vector< T > &in)
Definition: Vector.h:225
T * data()
Definition: Vector.h:294
Definition: Allocator.h:6