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;
205 bool grow(
int newMaxLen)
override {
207 assert(newMaxLen < 1024 * 10);
208 if (newMaxLen < 0)
return false;
223 snprintf(result, maxLen,
"%c", c);
224 }
else if (isspace(c)) {
225 snprintf(result, maxLen,
"%s",
"+");
227 snprintf(result, maxLen,
"%%%X%X", c >> 4, c % 16);
232 if (ch >=
'0' && ch <=
'9') {
233 return (
char)(ch -
'0');
235 if (ch >=
'a' && ch <=
'f') {
236 return (
char)(ch -
'a' + 10);
238 if (ch >=
'A' && ch <=
'F') {
239 return (
char)(ch -
'A' + 10);
249 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:25
char * chars
Definition: StrView.h:747
int len
Definition: StrView.h:749
int maxlen
Definition: StrView.h:750
virtual void set(const char *alt)
assigs a value
Definition: StrView.h:51
bool is_const
Definition: StrView.h:748
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
char charToInt(char ch)
Definition: Str.h:231
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:197
void reset()
Definition: Str.h:191
Str & move(Str &other)
Definition: Str.h:199
void allocate(int len=-1)
Definition: Str.h:87
bool grow(int newMaxLen) override
only supported in subclasses
Definition: Str.h:205
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:244
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:221
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