3#include "AudioTools/CoreAudio/AudioBasic/StrView.h"
4#include "AudioTools/CoreAudio/AudioBasic/Collections/Vector.h"
29 maxlen = initialAllocatedLength;
39 if (chars !=
nullptr) {
84 size_t capacity() {
return maxlen; }
86 void setCapacity(
size_t newLen) {
grow(newLen); }
89 void allocate(
int len = -1) {
90 int new_size = len < 0 ? maxlen : len;
96 void copyFrom(
const char *source,
int len,
int maxlen = 0) {
97 this->maxlen = maxlen == 0 ? len : maxlen;
99 if (this->chars !=
nullptr) {
101 this->is_const =
false;
102 memmove(this->chars, source, len);
103 this->chars[len] = 0;
96 void copyFrom(
const char *source,
int len,
int maxlen = 0) {
…}
110 if (this->chars !=
nullptr) {
111 for (
int j = 0; j < len; j++) {
115 this->is_const =
false;
116 this->chars[len] = 0;
125 for (
size_t i = 0; i < len; i++) {
126 urlEncodeChar(chars[i], temp, 4);
127 new_size += strlen(temp);
130 char result[new_size + 1];
131 memset(result,0, new_size+1);
132 for (
size_t i = 0; i < len; i++) {
133 urlEncodeChar(chars[i], temp, 4);
134 strcat(result, temp);
138 strcpy(chars, result);
139 this->len = strlen(temp);
146 size_t result_idx = 0;
148 if (chars[i] ==
'%') {
149 szTemp[0] = chars[i + 1];
150 szTemp[1] = chars[i + 2];
151 chars[result_idx] = strToBin(szTemp);
153 }
else if (chars[i] ==
'+') {
154 chars[result_idx] =
' ';
157 chars[result_idx] += chars[i];
162 chars[result_idx] = 0;
163 this->len = result_idx;
173 void swap(
Str &other){
175 int tmp_maxlen = maxlen;
177 maxlen = other.maxlen;
178 vector.swap(other.vector);
179 chars = vector.data();
180 other.chars = other.vector.data();
187 Str& move(Str &other) {
193 bool grow(
int newMaxLen)
override {
195 assert(newMaxLen < 1024 * 10);
196 if (newMaxLen < 0)
return false;
198 if (chars ==
nullptr || newMaxLen > maxlen) {
199 LOGD(
"grow(%d)", newMaxLen);
203 int newSize = newMaxLen > maxlen ? newMaxLen : maxlen;
204 vector.resize(newSize + 1);
193 bool grow(
int newMaxLen)
override {
…}
211 void urlEncodeChar(
char c,
char *result,
int maxLen) {
213 snprintf(result, maxLen,
"%c", c);
214 }
else if (isspace(c)) {
215 snprintf(result, maxLen,
"%s",
"+");
217 snprintf(result, maxLen,
"%%%X%X", c >> 4, c % 16);
221 char charToInt(
char ch) {
222 if (ch >=
'0' && ch <=
'9') {
223 return (
char)(ch -
'0');
225 if (ch >=
'a' && ch <=
'f') {
226 return (
char)(ch -
'a' + 10);
228 if (ch >=
'A' && ch <=
'F') {
229 return (
char)(ch -
'A' + 10);
234 char strToBin(
char *pString) {
237 szBuffer[0] = charToInt(pString[0]);
238 szBuffer[1] = charToInt(pString[1]);
239 ch = (szBuffer[0] << 4) | szBuffer[1];