first release of translation facility
* runtime - loading and translating * design-time - works with *.ts file (pip_tr utility) * compile-time - CMake macro for compile *.ts
This commit is contained in:
@@ -297,7 +297,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
|
||||
|
||||
|
||||
void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
||||
// piCout << "appendFromChars";
|
||||
// piCout << "appendFromChars";
|
||||
if (s == 0) return;
|
||||
int old_sz = size_s();
|
||||
if (s == -1) s = strlen(c);
|
||||
@@ -523,6 +523,31 @@ void PIString::trimsubstr(int & st, int & fn) const {
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::minArgPlaceholder() {
|
||||
if (size() < 2) return {};
|
||||
int min = -1;
|
||||
PIString ret, tmp;
|
||||
for (int i = 0; i < size_s(); ++i) {
|
||||
if (at(i) == '%') {
|
||||
int j = 0;
|
||||
for (j = i + 1; j < size_s(); ++j) {
|
||||
if (!at(j).isDigit()) break;
|
||||
}
|
||||
bool ok = false;
|
||||
tmp = mid(i + 1, j - i - 1);
|
||||
int cur = tmp.toInt(10, &ok);
|
||||
if (!ok) continue;
|
||||
if (min < 0 || min > cur) {
|
||||
min = cur;
|
||||
ret = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret.isEmpty()) return {};
|
||||
return "%" + ret;
|
||||
}
|
||||
|
||||
|
||||
uint PIString::hash() const {
|
||||
return piHashData((const uchar *)d.data(), d.size() * sizeof(PIChar));
|
||||
}
|
||||
@@ -1744,10 +1769,9 @@ ldouble PIString::toLDouble() const {
|
||||
//! piCout << s; // 47.6 GiB
|
||||
//! \endcode
|
||||
PIString & PIString::setReadableSize(llong bytes) {
|
||||
static const PIString tr_c = "PIString"_a;
|
||||
clear();
|
||||
if (bytes < 1024) {
|
||||
*this += (PIString::fromNumber(bytes) + " "_a + PITranslator::tr("B", tr_c));
|
||||
*this += (PIString::fromNumber(bytes) + " "_a + "B"_tr("PIString"));
|
||||
return *this;
|
||||
}
|
||||
double fres = bytes;
|
||||
@@ -1762,14 +1786,21 @@ PIString & PIString::setReadableSize(llong bytes) {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if (checkRange(PITranslator::tr("KiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("MiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("GiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("TiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("PiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("EiB", tr_c))) return *this;
|
||||
if (checkRange(PITranslator::tr("ZiB", tr_c))) return *this;
|
||||
checkRange(PITranslator::tr("YiB", tr_c), true);
|
||||
if (checkRange("KiB"_tr("PIString"))) return *this;
|
||||
if (checkRange("MiB"_tr("PIString"))) return *this;
|
||||
if (checkRange("GiB"_tr("PIString"))) return *this;
|
||||
if (checkRange("TiB"_tr("PIString"))) return *this;
|
||||
if (checkRange("PiB"_tr("PIString"))) return *this;
|
||||
if (checkRange("EiB"_tr("PIString"))) return *this;
|
||||
if (checkRange("ZiB"_tr("PIString"))) return *this;
|
||||
checkRange("YiB"_tr("PIString"), true);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString & PIString::arg(const PIString & v) {
|
||||
auto ph = minArgPlaceholder();
|
||||
if (!ph.isEmpty()) replaceAll(ph, v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1682,6 +1682,61 @@ public:
|
||||
//! \~\sa PIString::readableSize()
|
||||
PIString & setReadableSize(llong bytes);
|
||||
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! piCout << PIString("color %1 is not %2, but %1").arg("red").arg("green"); // color red is not green, but red
|
||||
//! \endcode
|
||||
PIString & arg(const PIString & v);
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
PIString & arg(short v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
PIString & arg(ushort v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! piCout << PIString("ten = %1").arg(10); // ten = 10
|
||||
//! piCout << PIString("'%1' is max hex letter (%2 in dec)").arg(0xF, 16).arg(0xF); // 'F' is max hex letter (15 in dec)
|
||||
//! \endcode
|
||||
PIString & arg(int v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
PIString & arg(uint v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
PIString & arg(llong v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
PIString & arg(ullong v, int base = 10) { return arg(PIString::fromNumber(v, base)); }
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
PIString & arg(float v, char format = 'f', int precision = 8) { return arg(PIString::fromNumber(v, format, precision)); }
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! piCout << PIString("light speed = %1 %2").arg(M_LIGHT_SPEED, 'g', 4).arg("m/s"); // light speed = 2.998e+08 m/s
|
||||
//! \endcode
|
||||
PIString & arg(double v, char format = 'f', int precision = 8) { return arg(PIString::fromNumber(v, format, precision)); }
|
||||
|
||||
//! \~english Replace all occurances like "%1", "%2", ... with lowest value to "v" and returns this string.
|
||||
//! \~russian Заменяет все вхождения типа "%1", "%2", ... с наименьшим значением на "v" и возвращает эту строку.
|
||||
PIString & arg(ldouble v, char format = 'f', int precision = 8) { return arg(PIString::fromNumber(v, format, precision)); }
|
||||
|
||||
|
||||
//! \~english Returns string contains numeric representation of "value" in base "base".
|
||||
//! \~russian Возвращает строковое представление числа "value" по основанию "base".
|
||||
//! \~\details
|
||||
@@ -1867,6 +1922,7 @@ private:
|
||||
void buildData(const char * cp = __syslocname__) const;
|
||||
void deleteData() const;
|
||||
void trimsubstr(int & st, int & fn) const;
|
||||
PIString minArgPlaceholder();
|
||||
|
||||
PIDeque<PIChar> d;
|
||||
mutable bool changed_ = true;
|
||||
|
||||
Reference in New Issue
Block a user