PICout::withExternalBufferAnd decomposed to PICout::withExternalBufferAndID and PICout::withExternalBufferAnd

PIString::toPercentageEncoding/fromPercentageEncoding
piStringify()
PIHTTPClient support arguments
some doc
This commit is contained in:
2024-11-26 18:26:02 +03:00
parent 12114b3e77
commit 65d3168eb5
10 changed files with 156 additions and 50 deletions

View File

@@ -1810,6 +1810,46 @@ PIString & PIString::setReadableSize(llong bytes) {
}
PIString PIString::toPercentageEncoding() const {
static const PIString valid = "-._~"_a;
PIString ret;
PIByteArray utf8;
bool ok = false;
for (const auto & c: *this) {
ok = false;
if (c.isAscii()) {
if (c.isAlpha() || c.isDigit())
ok = true;
else if (valid.contains(c))
ok = true;
}
if (ok) {
ret.append(c);
} else {
utf8 = PIString(c).toUTF8();
for (auto u: utf8)
ret.append('%').append(PIString::fromNumber(u, 16).expandLeftTo(2, '0'));
}
}
return ret;
}
PIString PIString::fromPercentageEncoding(const PIString & in) {
PIByteArray utf8;
PIChar c;
for (int i = 0; i < in.size_s(); ++i) {
c = in[i];
if (c == '%') {
utf8 << static_cast<uchar>(in.mid(i + 1, 2).toInt(16));
i += 2;
} else
utf8 << static_cast<uchar>(c.toAscii());
}
return PIString::fromUTF8(utf8);
}
PIString & PIString::arg(const PIString & v) {
auto ph = minArgPlaceholder();
if (!ph.isEmpty()) replaceAll(ph, v);