PICout::withExternalBufferAnd decomposed to PICout::withExternalBufferAndID and PICout::withExternalBufferAnd
PIString::toPercentageEncoding/fromPercentageEncoding piStringify() PIHTTPClient support arguments some doc
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -1687,6 +1687,10 @@ public:
|
||||
PIString & setReadableSize(llong bytes);
|
||||
|
||||
|
||||
//! \~english Returns [percentage-encoded](https://en.wikipedia.org/wiki/Percent-encoding) string.
|
||||
//! \~russian Возвращает [URL-кодированную](https://ru.wikipedia.org/wiki/URL) строку.
|
||||
PIString toPercentageEncoding() const;
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
//! \~\details
|
||||
@@ -1906,6 +1910,10 @@ public:
|
||||
//! \~\sa PIString::setReadableSize()
|
||||
static PIString readableSize(llong bytes);
|
||||
|
||||
//! \~english Returns string from [percentage-encoded](https://en.wikipedia.org/wiki/Percent-encoding) "in".
|
||||
//! \~russian Возвращает строку из [URL-кодированной](https://ru.wikipedia.org/wiki/URL)"in".
|
||||
static PIString fromPercentageEncoding(const PIString & in);
|
||||
|
||||
//! \~english Swaps string `str` other with this string.
|
||||
//! \~russian Меняет строку `str` с этой строкой.
|
||||
//! \~\details
|
||||
@@ -2020,4 +2028,15 @@ inline void piSwap(PIString & f, PIString & s) {
|
||||
f.swap(s);
|
||||
}
|
||||
|
||||
|
||||
//! \~english Returns string representation of \"v\", using PICout operator<<(T)
|
||||
//! \~russian Возвращает строковое представление \"v\", используя PICout operator<<(T)
|
||||
template<typename T>
|
||||
inline PIString piStringify(const T & v) {
|
||||
PIString ret;
|
||||
PICout::withExternalBuffer(&ret) << v;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#endif // PISTRING_H
|
||||
|
||||
Reference in New Issue
Block a user