PIString and PIChar fixes

This commit is contained in:
Andrey
2022-03-25 13:49:32 +03:00
parent 8bb1af8d2a
commit 649850a1ba
3 changed files with 274 additions and 131 deletions

View File

@@ -38,19 +38,19 @@ class PIP_EXPORT PIChar
public:
//! \~english Contructs Ascii symbol
//! \~russian Создает символ Ascii
PIChar(const char c) {ch = c; ch &= 0xFF;}
//! \~english Contructs 2-bytes symbol
//! \~russian Создает 2-байтный символ
PIChar(const short c) {ch = c;}
PIChar(char c) {ch = c; ch &= 0xFF;}
//! \~english Contructs ascii symbol
//! \~russian Создает символ Ascii
PIChar(const uchar c) {ch = c;}
PIChar(uchar c) {ch = c;}
//! \~english Contructs 2-bytes symbol
//! \~russian Создает 2-байтный символ
PIChar(const ushort c = 0) {ch = c;}
PIChar(ushort c = 0) {ch = c;}
//! \~english Contructs 2-bytes symbol from `wchar_t`
//! \~russian Создает 2-байтный символ из `wchar_t`
PIChar(wchar_t c) {ch = c;}
//! \~english Contructs symbol from system locale and no more than 4 bytes of string
//! \~russian Создает символ из системной локали не более 4 байт длины

View File

@@ -139,26 +139,23 @@ const float PIString::ElideRight = 1.f;
#ifndef CC_VC
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf(ch, f, v);
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf(ch, f, v); return PIString(ch);
#else
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf_s(ch, 256, f, v);
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf_s(ch, 256, f, v); return PIString(ch);
#endif
#ifdef ANDROID
//int wctomb(char * c, wchar_t w) {*c = ((char * )&w)[0]; return 1;}
#endif
PIString PIString::itos(const int num) {pisprintf("%d", num); return PIString(ch);}
PIString PIString::ltos(const long num) {pisprintf("%ld", num); return PIString(ch);}
PIString PIString::lltos(const llong num) {pisprintf("%lld", num); return PIString(ch);}
PIString PIString::uitos(const uint num) {pisprintf("%u", num); return PIString(ch);}
PIString PIString::ultos(const ulong num) {pisprintf("%lu", num); return PIString(ch);}
PIString PIString::ulltos(const ullong num) {pisprintf("%llu", num); return PIString(ch);}
PIString PIString::itos(const int num) {pisprintf("%d", num);}
PIString PIString::ltos(const long num) {pisprintf("%ld", num);}
PIString PIString::lltos(const llong num) {pisprintf("%lld", num);}
PIString PIString::uitos(const uint num) {pisprintf("%u", num);}
PIString PIString::ultos(const ulong num) {pisprintf("%lu", num);}
PIString PIString::ulltos(const ullong num) {pisprintf("%llu", num);}
PIString PIString::ftos(const float num, char format, int precision) {
char f[8] = "%.";
int wr = sprintf(&(f[2]), "%d", precision);
f[2 + wr] = format;
f[3 + wr] = 0;
pisprintf(f, num);
return PIString(ch);
}
PIString PIString::dtos(const double num, char format, int precision) {
char f[8] = "%.";
@@ -166,7 +163,6 @@ PIString PIString::dtos(const double num, char format, int precision) {
f[2 + wr] = format;
f[3 + wr] = 0;
pisprintf(f, num);
return PIString(ch);
}
#undef pisprintf
@@ -174,7 +170,10 @@ PIString PIString::dtos(const double num, char format, int precision) {
PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) {
if (value == 0LL) return PIString('0');
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();}
if (base < 2 || base > 40) {
if (ok != 0) *ok = false;
return PIString();
}
if (ok != 0) *ok = true;
if (base == 10) return lltos(value);
PIString ret;
@@ -193,7 +192,10 @@ PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) {
PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) {
if (value == 0ULL) return PIString('0');
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return PIString();}
if (base < 2 || base > 40) {
if (ok != 0) *ok = false;
return PIString();
}
if (ok != 0) *ok = true;
if (base == 10) return ulltos(value);
PIString ret;
@@ -215,17 +217,26 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
PIString v = value.trimmed();
if (base < 0) {
int ind = v.find(s_0x);
if (ind == 0 || ind == 1) {v.remove(ind, 2); base = 16;}
else base = 10;
} else
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return 0;}
if (ind == 0 || ind == 1) {
v.remove(ind, 2);
base = 16;
} else {
base = 10;
}
} else if (base < 2 || base > 40) {
if (ok != 0) *ok = false;
return 0;
}
if (ok) *ok = true;
PIVector<int> digits;
llong ret = 0, m = 1;
bool neg = false;
int cs;
for (int i = 0; i < v.size_s(); ++i) {
if (v[i] == PIChar('-')) {neg = !neg; continue;}
if (v[i] == PIChar('-')) {
neg = !neg;
continue;
}
cs = fromBaseN[int(v[i].toAscii())];
if (cs < 0 || cs >= base) {
if (ok) *ok = false;
@@ -256,8 +267,9 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
//printf("appendFromChars %d -> %d\n", s, sz);
//printf("PIString %d -> %d\n", c[0], ucs[0]);
reserve(size_s() + sz);
for (int i = 0; i < sz; ++i)
for (int i = 0; i < sz; ++i) {
push_back(PIChar(ucs[i]));
}
delete[] ucs;
ucnv_close(cc);
return;
@@ -339,8 +351,10 @@ PIString PIString::fromAscii(const char * s) {
PIString PIString::fromAscii(const char * s, int len) {
PIString ret;
for (int l = 0; l < len; ++l)
ret.reserve(len);
for (int l = 0; l < len; ++l) {
ret.push_back(PIChar(s[l]));
}
return ret;
}
@@ -379,15 +393,16 @@ void PIString::buildData(const char * cp) const {
char uc[8];
data_.reserve(size_s());
for (int i = 0; i < size_s(); ++i) {
if (at(i).isAscii())
if (at(i).isAscii()) {
data_.push_back(uchar(at(i).unicode16Code()));
else {
} else {
e = (UErrorCode)0;
sz = ucnv_fromUChars(cc, uc, 8, (const UChar*)(PIDeque<PIChar>::data(i)), 1, &e);
for (int j = 0; j < sz; ++j)
for (int j = 0; j < sz; ++j) {
data_.push_back(uc[j]);
}
}
}
ucnv_close(cc);
data_.push_back('\0');
return;
@@ -416,9 +431,10 @@ void PIString::buildData(const char * cp) const {
}
wc = at(i).toWChar();
sz = wctomb(tc, wc);
for (int b = 0; b < sz; ++b)
for (int b = 0; b < sz; ++b) {
data_.push_back(uchar(tc[b]));
}
}
data_.push_back(uchar('\0'));
# endif
#endif
@@ -426,13 +442,19 @@ void PIString::buildData(const char * cp) const {
void PIString::trimsubstr(int &st, int &fn) const {
for (int i = 0; i < length(); ++i)
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0))
{st = i; break;}
for (int i = 0; i < length(); ++i) {
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0)) {
st = i;
break;
}
}
if (st < 0) return;
for (int i = length() - 1; i >= 0; --i)
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0))
{fn = i; break;}
for (int i = length() - 1; i >= 0; --i) {
if (at(i) != ' ' && at(i) != '\t' && at(i) != '\n' && at(i) != '\r' && at(i) != char(12) && at(i) != uchar(0)) {
fn = i;
break;
}
}
}
@@ -450,8 +472,9 @@ const char * PIString::dataUTF8() const {
const char * PIString::dataAscii() const {
data_.clear();
for (int i = 0; i < size_s(); ++i)
for (int i = 0; i < size_s(); ++i) {
data_.push_back(uchar(at(i).ch));
}
data_.push_back(uchar('\0'));
return (const char *)data_.data();
}
@@ -497,8 +520,9 @@ PIString & PIString::operator +=(const char * str) {
PIString & PIString::operator +=(const wchar_t * str) {
if (!str) return *this;
int i = -1;
while (str[++i])
push_back(PIChar(ushort(str[i])));
while (str[++i]) {
push_back(PIChar(str[i]));
}
return *this;
}
@@ -512,9 +536,9 @@ PIString & PIString::operator +=(const PIString & str) {
bool PIString::operator ==(const PIString & str) const {
uint l = str.size();
if (size() != l) return false;
for (uint i = 0; i < l; ++i)
if (str[i] != at(i))
return false;
for (uint i = 0; i < l; ++i) {
if (str[i] != at(i)) return false;
}
return true;
}
@@ -522,9 +546,9 @@ bool PIString::operator ==(const PIString & str) const {
bool PIString::operator !=(const PIString & str) const {
uint l = str.size();
if (size() != l) return true;
for (uint i = 0; i < l; ++i)
if (str[i] != at(i))
return true;
for (uint i = 0; i < l; ++i) {
if (str[i] != at(i)) return true;
}
return false;
}
@@ -566,8 +590,7 @@ PIString PIString::mid(const int start, const int len) const {
if (l < 0) {
return PIString(&(at(s)), size_s() - s);
} else {
if (l > length() - s)
l = length() - s;
if (l > length() - s) l = length() - s;
return PIString(&(at(s)), l);
}
return PIString();
@@ -581,11 +604,10 @@ PIString & PIString::cutMid(const int start, const int len) {
l += s;
s = 0;
}
if (l < 0)
if (l < 0) {
remove(s, size() - s);
else {
if (l > length() - s)
l = length() - s;
} else {
if (l > length() - s) l = length() - s;
remove(s, l);
}
return *this;
@@ -615,9 +637,9 @@ PIString PIString::trimmed() const {
PIString & PIString::replace(int from, int count, const PIString & with) {
count = piMini(count, length() - from);
if (count == with.size_s())
if (count == with.size_s()) {
memcpy(PIDeque<PIChar>::data(from), static_cast<PIDeque<PIChar>>(with).data(), count * sizeof(PIChar));
else {
} else {
remove(from, count);
PIDeque<PIChar>::insert(from, with);
}
@@ -639,8 +661,9 @@ PIString & PIString::replace(const PIString & what, const PIString & with, bool
PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
if (what.isEmpty() || what == with) return *this;
if (with.isEmpty()) removeAll(what);
else {
if (with.isEmpty()) {
removeAll(what);
} else {
int l = what.length(), dl = with.length() - what.length();
for (int i = 0; i < length() - l + 1; ++i) {
bool match = true;
@@ -654,7 +677,6 @@ PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
if (dl > 0) PIDeque<PIChar>::insert(i, PIDeque<PIChar>((size_t)dl));
if (dl < 0) PIDeque<PIChar>::remove(i, -dl);
memcpy(PIDeque<PIChar>::data(i), &(with.at(0)), with.length() * sizeof(PIChar));
//i -= l;
}
}
return *this;
@@ -675,7 +697,6 @@ PIString & PIString::replaceAll(const PIString & what, const char with) {
if (!match) continue;
if (dl > 0) PIDeque<PIChar>::remove(i, dl);
(*this)[i] = PIChar(with);
//i -= l;
}
return *this;
}
@@ -684,8 +705,7 @@ PIString & PIString::replaceAll(const PIString & what, const char with) {
PIString & PIString::replaceAll(const char what, const char with) {
int l = length();
for (int i = 0; i < l; ++i) {
if (at(i) == what)
(*this)[i] = with;
if (at(i) == what) (*this)[i] = with;
}
return *this;
}
@@ -748,35 +768,35 @@ PIStringList PIString::split(const PIString & delim) const {
int PIString::find(const char c, const int start) const {
for (int i = start; i < length(); ++i)
if (at(i) == c)
return i;
for (int i = start; i < length(); ++i) {
if (at(i) == c) return i;
}
return -1;
}
int PIString::find(const PIString & str, const int start) const {
int l = str.length();
for (int i = start; i < length() - l + 1; ++i)
if (mid(i, l) == str)
return i;
for (int i = start; i < length() - l + 1; ++i) {
if (mid(i, l) == str) return i;
}
return -1;
}
int PIString::findLast(const char c, const int start) const {
for (int i = length() - 1; i >= start; --i)
if (at(i) == c)
return i;
for (int i = length() - 1; i >= start; --i) {
if (at(i) == c) return i;
}
return -1;
}
int PIString::findLast(const PIString & str, const int start) const {
int l = str.length();
for (int i = length() - l; i >= start; --i)
if (mid(i, l) == str)
return i;
for (int i = length() - l; i >= start; --i) {
if (mid(i, l) == str) return i;
}
return -1;
}
@@ -786,8 +806,20 @@ int PIString::findWord(const PIString & word, const int start) const {
while ((f = find(word, f + 1)) >= 0) {
bool ok = true;
PIChar c;
if (f > 0) {c = (*this)[f - 1]; if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {ok = false; continue;}}
if (f + wl < tl) {c = (*this)[f + wl]; if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {ok = false; continue;}}
if (f > 0) {
c = (*this)[f - 1];
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {
ok = false;
continue;
}
}
if (f + wl < tl) {
c = (*this)[f + wl];
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) {
ok = false;
continue;
}
}
if (ok) return f;
}
return -1;
@@ -799,8 +831,20 @@ int PIString::findCWord(const PIString & word, const int start) const {
while ((f = find(word, f + 1)) >= 0) {
bool ok = true;
PIChar c;
if (f > 0) {c = (*this)[f - 1]; if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) {ok = false; continue;}}
if (f + wl < tl) {c = (*this)[f + wl]; if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) {ok = false; continue;}}
if (f > 0) {
c = (*this)[f - 1];
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) {
ok = false;
continue;
}
}
if (f + wl < tl) {
c = (*this)[f + wl];
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) {
ok = false;
continue;
}
}
if (ok) return f;
}
return -1;
@@ -813,7 +857,10 @@ int PIString::findRange(const PIChar start, const PIChar end, const PIChar shiel
int sz = size_s(), ls = -1, le = -1, cnt = 0;
for (int i = start_index; i < sz; ++i) {
PIChar c = at(i);
if (c == shield) {++i; continue;}
if (c == shield) {
++i;
continue;
}
if (trim_) {
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
continue;
@@ -845,25 +892,26 @@ int PIString::findRange(const PIChar start, const PIChar end, const PIChar shiel
int PIString::findAny(const PIString & str, const int start) const {
for (int i = start; i < length(); ++i)
if (str.contains(at(i)))
return i;
for (int i = start; i < length(); ++i) {
if (str.contains(at(i))) return i;
}
return -1;
}
int PIString::findAnyLast(const PIString & str, const int start) const {
for (int i = length() - 1; i >= start; --i)
if (str.contains(at(i)))
return i;
for (int i = length() - 1; i >= start; --i) {
if (str.contains(at(i))) return i;
}
return -1;
}
int PIString::entries(const PIChar c) const {
int sz = size_s(), ret = 0;
for (int i = 0; i < sz; ++i)
for (int i = 0; i < sz; ++i) {
if (at(i) == c) ++ret;
}
return ret;
}
@@ -898,8 +946,7 @@ PIString PIString::takeSymbol() {
int sz = size_s(), ss = -1;
for (int i = 0; i < sz; ++i) {
PIChar c = at(i);
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
continue;
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') continue;
ss = i;
break;
}
@@ -942,10 +989,11 @@ PIString PIString::takeCWord() {
}
} else {
if (ws < 0) {
if (c.isAlpha() || c == '_')
if (c.isAlpha() || c == '_') {
ws = i;
else
} else {
return ret;
}
} else {
if (!c.isAlpha() && !c.isDigit() && c != '_') {
we = i;
@@ -971,9 +1019,11 @@ PIString PIString::takeLine() {
}
}
PIString ret = left(le);
if (!ret.isEmpty())
if (ret.back() == '\r')
if (!ret.isEmpty()) {
if (ret.back() == '\r') {
ret.cutRight(1);
}
}
cutLeft(le < 0 ? sz : le + 1);
return ret;
}
@@ -988,37 +1038,75 @@ PIString PIString::takeNumber() {
//piCout << "char " << c << "phase" << phase;
switch (phase) {
case 0: // trim
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
continue;
}
phase = 7;
case 7: // sign
if (c == '-' || c == '+') {ls = i; phase = 1; break;}
if (c == '-' || c == '+') {
ls = i;
phase = 1;
break;
}
case 1: // search start
if (c >= '0' && c <= '9') {le = i; if (ls < 0) ls = i; phase = 2; break;}
if (c == '.') {le = i; if (ls < 0) ls = i; phase = 3; break;}
if ((c >= '0' && c <= '9') || c == '.') {
le = i;
if (ls < 0) ls = i;
if (c == '.') phase = 3;
else phase = 2;
break;
}
phase = 9;
break;
case 2: // integer
if (c == '.') {le = i; phase = 3; break;}
if (c == 'e' || c == 'E') {le = i; phase = 4; break;}
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || c == 'x') {le = i; break;}
if (c == '.') {
le = i;
phase = 3;
break;
}
if (c == 'e' || c == 'E') {
le = i;
phase = 4;
break;
}
if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || c == 'x') {
le = i;
break;
}
phase = 6;
break;
case 3: // point
if (c == 'e' || c == 'E') {le = i; phase = 4; break;}
if (c >= '0' && c <= '9') {le = i; break;}
if (c == 'e' || c == 'E') {
le = i;
phase = 4;
break;
}
if (c >= '0' && c <= '9') {
le = i;
break;
}
phase = 6;
break;
case 4: // exp
if ((c >= '0' && c <= '9') || c == '-' || c == '+') {le = i; phase = 5; break;}
if ((c >= '0' && c <= '9') || c == '-' || c == '+') {
le = i;
phase = 5;
break;
}
phase = 6;
break;
case 5: // power
if (c >= '0' && c <= '9') {le = i; break;}
if (c >= '0' && c <= '9') {
le = i;
break;
}
phase = 6;
break;
case 6: // suffix
if (c == 'f' || c == 's' || c == 'u' || c == 'l' || c == 'L') {le = i; break;}
if (c == 'f' || c == 's' || c == 'u' || c == 'l' || c == 'L') {
le = i;
break;
}
phase = 9;
break;
}
@@ -1041,16 +1129,25 @@ PIString PIString::takeRange(const PIChar start, const PIChar end, const PIChar
int sz = size_s(), ls = -1, le = -1, cnt = 0;
for (int i = 0; i < sz; ++i) {
PIChar c = at(i);
if (c == shield) {++i; continue;}
if (trim_) {
if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
if (c == shield) {
++i;
continue;
}
if (trim_) {
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') {
continue;
}
trim_ = false;
}
if (eq) {
if (c == start) {
if (cnt == 0) ls = i;
else {le = i; cnt = 0; break;}
if (cnt == 0) {
ls = i;
} else {
le = i;
cnt = 0;
break;
}
cnt++;
}
} else {
@@ -1095,7 +1192,9 @@ PIString PIString::inBrackets(const PIChar start, const PIChar end) const {
PIString PIString::toUpperCase() const {
PIString str(*this);
int l = str.size();
for (int i = 0; i < l; ++i) str[i] = str[i].toUpper();
for (int i = 0; i < l; ++i) {
str[i] = str[i].toUpper();
}
return str;
}
@@ -1103,7 +1202,9 @@ PIString PIString::toUpperCase() const {
PIString PIString::toLowerCase() const {
PIString str(*this);
int l = str.size();
for (int i = 0; i < l; ++i) str[i] = str[i].toLower();
for (int i = 0; i < l; ++i) {
str[i] = str[i].toLower();
}
return str;
}
@@ -1144,23 +1245,38 @@ ldouble PIString::toLDouble() const {
PIString & PIString::setReadableSize(llong bytes) {
clear();
if (bytes < 1024) {*this += (PIString::fromNumber(bytes) + PIStringAscii(" B")); return *this;}
if (bytes < 1024) {
*this += (PIString::fromNumber(bytes) + PIStringAscii(" B"));
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")); return *this;}
if (res < 1024) {
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" kB"));
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")); return *this;}
if (res < 1024) {
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" MB"));
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")); return *this;}
if (res < 1024) {
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" GB"));
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")); return *this;}
if (res < 1024) {
*this += (PIString::fromNumber(res) + PIStringAscii(".") + PIString::fromNumber(llong(fres * 10)).left(1) + PIStringAscii(" TB"));
return *this;
}
fres = res / 1024.;
res /= 1024;
fres -= res;
@@ -1183,12 +1299,12 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
int ind = s.findLast('.') + 1;
while (!_versionDelims_.contains(s[ind])) {
++ind;
if (ind > s.size_s() - 1)
break;
if (ind > s.size_s() - 1) break;
}
for (int i = 0; i < mccnt; ++i)
for (int i = 0; i < mccnt; ++i) {
s.insert(ind, PIStringAscii(".0"));
}
}
PIStringList comps;
while (!s.isEmpty()) {
int ind = s.findAny(_versionDelims_);
@@ -1201,8 +1317,7 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
}
}
for (int i = 0; i < comps.size_s(); ++i) {
if (comps[i].isEmpty())
comps[i] = '0';
if (comps[i].isEmpty()) comps[i] = '0';
bool ok = false;
int val = comps[i].toInt(-1, &ok);
if (ok) {

View File

@@ -34,13 +34,13 @@
inline std::string PIString2StdString(const PIString & v) {
std::string s;
uint wc;
ushort wc;
uchar tc;
if (v.size() > 0) {
for (int i = 0; i < v.length(); ++i) {
wc = uint(v.at(i).unicode16Code());
wc = v[i].unicode16Code();
while (tc = wc & 0xFF, tc) {
s.push_back(char(tc));
s.push_back(tc);
wc >>= 8;
}
}
@@ -48,22 +48,28 @@ inline std::string PIString2StdString(const PIString & v) {
return s;
}
inline PIString StdString2PIString(const std::string & v) {
return PIString(v.c_str(), v.length());
}
#ifdef HAS_LOCALE
inline std::wstring PIString2StdWString(const PIString & v) {
std::wstring s;
for (int i = 0; i < v.length(); ++i)
s.push_back(v.at(i).toWChar());
for (int i = 0; i < v.length(); ++i) {
s.push_back(v[i].toWChar());
}
return s;
}
inline PIString StdWString2PIString(const std::wstring & v) {
PIString s;
uint l = v.size();
for (uint i = 0; i < l; ++i) s.push_back(v[i]);
for (uint i = 0; i < l; ++i) {
s.push_back(v[i]);
}
return s;
}
#endif
@@ -71,20 +77,42 @@ inline PIString StdWString2PIString(const std::wstring & v) {
//! \relatesalso PIChar \brief Output operator to \c std::ostream
inline std::ostream & operator <<(std::ostream & s, const PIChar & v) {s << v.toCharPtr(); return s;}
inline std::ostream & operator <<(std::ostream & s, const PIChar & v) {
s << v.toCharPtr();
return s;
}
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const PIString & f, const std::string & str) {PIString s(f); s += StdString2PIString(str); return s;}
inline PIString operator +(const PIString & f, const std::string & str) {
PIString s(f);
s += StdString2PIString(str);
return s;
}
//! \relatesalso PIString \brief Return concatenated string
inline PIString operator +(const std::string & str, const PIString & f) {return StdString2PIString(str) + f;}
inline PIString operator +(const std::string & str, const PIString & f) {
return StdString2PIString(str) + f;
}
//! \relatesalso PIString \brief Output operator to std::ostream (cout)
inline std::ostream & operator <<(std::ostream & s, const PIString & v) {for (int i = 0; i < v.length(); ++i) s << v[i]; return s;}
inline std::ostream & operator <<(std::ostream & s, const PIString & v) {
for (int i = 0; i < v.length(); ++i) {
s << v[i];
}
return s;
}
//! \relatesalso PIString \brief Input operator from std::istream (cin)
inline std::istream & operator >>(std::istream & s, PIString & v) {std::string ss; s >> ss; v = StdString2PIString(ss); return s;}
inline std::istream & operator >>(std::istream & s, PIString & v) {
std::string ss;
s >> ss;
v = StdString2PIString(ss);
return s;
}
//! \relatesalso PIStringList \brief Output operator to std::ostream (cout)