doc and brush

This commit is contained in:
2023-07-04 13:08:37 +03:00
parent 9e78546b7e
commit 35aadb0e78
10 changed files with 106 additions and 69 deletions

View File

@@ -20,6 +20,7 @@
#include "pistring.h"
#include "piincludes_p.h"
#include "piliterals.h"
#include "pimathbase.h"
#include "pistringlist.h"
#ifdef PIP_ICU
@@ -254,7 +255,7 @@ PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) {
llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
static const PIString s_0x = PIStringAscii("0x");
static const PIString s_0x = "0x"_a;
PIString v = value.trimmed();
if (base < 0) {
int ind = v.find(s_0x);
@@ -430,11 +431,11 @@ PIString PIString::fromCodepage(const char * s, const char * c) {
//! Пример:
//! \~\code
//! piCout << PIString::readableSize(512); // 512 B
//! piCout << PIString::readableSize(5120); // 5.0 kB
//! piCout << PIString::readableSize(512000); // 500.0 kB
//! piCout << PIString::readableSize(5120000); // 4.8 MB
//! piCout << PIString::readableSize(512000000); // 488.2 MB
//! piCout << PIString::readableSize(51200000000); // 47.6 GB
//! piCout << PIString::readableSize(5120); // 5.0 KiB
//! piCout << PIString::readableSize(512000); // 500.0 KiB
//! piCout << PIString::readableSize(5120000); // 4.8 MiB
//! piCout << PIString::readableSize(512000000); // 488.2 MiB
//! piCout << PIString::readableSize(51200000000); // 47.6 GiB
//! \endcode
PIString PIString::readableSize(llong bytes) {
PIString s;
@@ -894,7 +895,7 @@ PIString & PIString::insert(int index, const PIString & str) {
PIString & PIString::elide(int size, float pos) {
static const PIString s_dotdot = PIStringAscii("..");
static const PIString s_dotdot = ".."_a;
if (length() <= size) return *this;
if (length() <= 2) {
fill('.');
@@ -1185,10 +1186,10 @@ bool PIString::endsWith(const PIString & str) const {
//! piCout << PIString("").toBool(); // false
//! \endcode
bool PIString::toBool() const {
static const PIString s_true = PIStringAscii("true");
static const PIString s_yes = PIStringAscii("yes");
static const PIString s_on = PIStringAscii("on");
static const PIString s_ok = PIStringAscii("ok");
static const PIString s_true = "true"_a;
static const PIString s_yes = "yes"_a;
static const PIString s_on = "on"_a;
static const PIString s_ok = "ok"_a;
PIString s(*this);
s = s.trimmed().toLowerCase();
if (s == s_true || s == s_yes || s == s_on || s == s_ok) return true;
@@ -1662,59 +1663,59 @@ ldouble PIString::toLDouble() const {
//! s.setReadableSize(512);
//! piCout << s; // 512 B
//! s.setReadableSize(5120);
//! piCout << s; // 5.0 kB
//! piCout << s; // 5.0 KiB
//! s.setReadableSize(512000);
//! piCout << s; // 500.0 kB
//! piCout << s; // 500.0 KiB
//! s.setReadableSize(5120000);
//! piCout << s; // 4.8 MB
//! piCout << s; // 4.8 MiB
//! s.setReadableSize(512000000);
//! piCout << s; // 488.2 MB
//! piCout << s; // 488.2 MiB
//! s.setReadableSize(51200000000);
//! piCout << s; // 47.6 GB
//! piCout << s; // 47.6 GiB
//! \endcode
PIString & PIString::setReadableSize(llong bytes) {
clear();
if (bytes < 1024) {
*this += (PIString::fromNumber(bytes) + PIStringAscii(" B"));
*this += (PIString::fromNumber(bytes) + " B"_a);
return *this;
}
double fres = bytes / 1024.;
llong res = bytes / 1024;
fres -= res;
if (res < 1024) {
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" kB"));
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " KiB"_a);
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
if (res < 1024) {
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" MB"));
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " MiB"_a);
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
if (res < 1024) {
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" GB"));
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " GiB"_a);
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
if (res < 1024) {
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" TB"));
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " TiB"_a);
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" PB"));
*this += (PIString::fromNumber(res) + "."_a + PIString::fromNumber(llong(fres * 10)).left(1) + " PiB"_a);
return *this;
}
const static PIString _versionDelims_ = PIStringAscii("._-+");
const static PIString _versionDelims_ = "._-+"_a;
void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
@@ -1731,7 +1732,7 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
if (ind > s.size_s() - 1) break;
}
for (int i = 0; i < mccnt; ++i) {
s.insert(ind, PIStringAscii(".0"));
s.insert(ind, ".0"_a);
}
}
PIStringList comps;
@@ -1762,20 +1763,20 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
int versionLabelValue(PIString s) {
int ret = -10000;
if (s.isEmpty()) return 0;
if (s.startsWith(PIStringAscii("pre"))) {
if (s.startsWith("pre"_a)) {
s.cutLeft(3);
ret -= 1;
}
if (s.startsWith(PIStringAscii("rc"))) {
if (s.startsWith("rc"_a)) {
s.cutLeft(2);
ret += s.toInt();
}
if (s.startsWith(PIStringAscii("r"))) {
if (s.startsWith("r"_a)) {
s.cutLeft(1);
ret += 10000 + s.toInt();
}
if (s == PIStringAscii("alpha")) ret -= 4;
if (s == PIStringAscii("beta")) ret -= 2;
if (s == "alpha"_a) ret -= 4;
if (s == "beta"_a) ret -= 2;
return ret;
}