BIG deep clean
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
String
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
String
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#include "pistring.h"
|
||||
#include "pistringlist.h"
|
||||
#ifdef PIP_ICU
|
||||
# define U_NOEXCEPT
|
||||
# include "unicode/ucnv.h"
|
||||
@@ -216,7 +218,6 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
|
||||
else base = 10;
|
||||
} else
|
||||
if (base < 2 || base > 40) {if (ok != 0) *ok = false; return 0;}
|
||||
//v.reverse();
|
||||
if (ok) *ok = true;
|
||||
PIVector<int> digits;
|
||||
llong ret = 0, m = 1;
|
||||
@@ -236,14 +237,6 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
|
||||
m *= base;
|
||||
}
|
||||
if (neg) ret = -ret;
|
||||
/*piForeachC (PIChar & i, v) {
|
||||
if (i == PIChar('-')) {ret = -ret; continue;}
|
||||
cs = fromBaseN[int(i.toAscii())];
|
||||
cout << i << " = " << cs << endl;
|
||||
if (cs < 0 || cs >= base) return ret;
|
||||
ret += cs * m;
|
||||
m *= base;
|
||||
}*/
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -494,29 +487,6 @@ PIString & PIString::operator +=(const char * str) {
|
||||
|
||||
PIString & PIString::operator +=(const wchar_t * str) {
|
||||
if (!str) return *this;
|
||||
//cout << "wc" << endl;
|
||||
/*int l = 0, sz;
|
||||
char * c = new char[MB_CUR_MAX];
|
||||
while (str[l] != 0) ++l;
|
||||
for (int i = 0; i < l; ++i) {
|
||||
sz = wctomb(c, str[i]);
|
||||
switch (sz) {
|
||||
case 4:
|
||||
push_back(PIChar(*(int*)c));
|
||||
continue;
|
||||
case 3:
|
||||
push_back(PIChar(*(int*)c));
|
||||
back().ch &= 0xFFFFFF;
|
||||
continue;
|
||||
case 2:
|
||||
push_back(PIChar(*(short * )c));
|
||||
continue;
|
||||
default:
|
||||
push_back(PIChar(c[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete[] c;*/
|
||||
int i = -1;
|
||||
while (str[++i])
|
||||
push_back(PIChar(ushort(str[i])));
|
||||
@@ -589,9 +559,6 @@ PIString PIString::mid(const int start, const int len) const {
|
||||
} else {
|
||||
if (l > length() - s)
|
||||
l = length() - s;
|
||||
//for (int i = s; i < s + l; ++i)
|
||||
// str += at(i);
|
||||
// std::cout << "mid " << s << " " << l << " " << size_s() << " " << start << " " << len << "\n";
|
||||
return PIString(&(at(s)), l);
|
||||
}
|
||||
return PIString();
|
||||
@@ -668,8 +635,6 @@ PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
|
||||
|
||||
|
||||
PIString & PIString::insert(int index, const PIString & str) {
|
||||
//uint c = str.length();
|
||||
//for (uint i = 0; i < c; ++i) insert(index + i, str[i]);
|
||||
PIDeque<PIChar>::insert(index, *((const PIDeque<PIChar>*)&str));
|
||||
return *this;
|
||||
}
|
||||
@@ -1094,46 +1059,6 @@ ldouble PIString::toLDouble() const {
|
||||
return atof(toNativeDecimalPoints().data());
|
||||
}
|
||||
|
||||
/*
|
||||
short PIString::toShort() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
short v;
|
||||
if (s.left(2) == "0x") {sscanf(s.data(), "%hx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.data(), "%ho", &v); return v;}
|
||||
sscanf(s.data(), "%hd", &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
int PIString::toInt() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
int v;
|
||||
if (s.left(2) == "0x") {sscanf(s.data(), "%x", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.data(), "%o", &v); return v;}
|
||||
sscanf(s.data(), "%d", &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
long PIString::toLong() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
long v;
|
||||
if (s.left(2) == "0x") {sscanf(s.data(), "%lx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.data(), "%lo", &v); return v;}
|
||||
sscanf(s.data(), "%ld", &v);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
llong PIString::toLLong() const {
|
||||
PIString s(trimmed().toLowerCase().toNativeDecimalPoints());
|
||||
llong v;
|
||||
if (s.left(2) == "0x") {sscanf(s.data(), "%llx", &v); return v;}
|
||||
if (s.left(1) == "0") {sscanf(s.data(), "%llo", &v); return v;}
|
||||
sscanf(s.data(), "%lld", &v);
|
||||
return v;
|
||||
}
|
||||
*/
|
||||
|
||||
PIString & PIString::setReadableSize(llong bytes) {
|
||||
clear();
|
||||
@@ -1164,20 +1089,19 @@ PIString & PIString::setReadableSize(llong bytes) {
|
||||
|
||||
inline char chrUpr(char c) {
|
||||
if (c >= 'a' && c <= 'z') return c + 'A' - 'a';
|
||||
//if (c >= 'а' && c <= 'я') return c + 'А' - 'а';
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
inline char chrLwr(char c) {
|
||||
if (c >= 'A' && c <= 'Z') return c + 'a' - 'A';
|
||||
//if (c >= 'А' && c <= 'Я') return c + 'а' - 'А';
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
const static PIString _versionDelims_ = PIStringAscii("._-+");
|
||||
|
||||
|
||||
void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
|
||||
s.trim();
|
||||
if (s.isEmpty()) {
|
||||
@@ -1220,6 +1144,7 @@ void parseVersion(PIString s, PIVector<int> & codes, PIStringList & strs) {
|
||||
//piCout << codes << strs;
|
||||
}
|
||||
|
||||
|
||||
int versionLabelValue(PIString s) {
|
||||
int ret = -10000;
|
||||
if (s.isEmpty()) return 0;
|
||||
@@ -1240,6 +1165,7 @@ int versionLabelValue(PIString s) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int versionCompare(const PIString & v0, const PIString & v1, int components) {
|
||||
PIStringList strs[2]; PIVector<int> codes[2];
|
||||
parseVersion(v0.toLowerCase(), codes[0], strs[0]);
|
||||
@@ -1291,35 +1217,9 @@ PICout operator <<(PICout s, const PIString & v) {
|
||||
s.space();
|
||||
s.quote();
|
||||
s.setControl(0, true);
|
||||
//if (PICout::isBufferActive())
|
||||
s << v.data();
|
||||
//else {
|
||||
// s << v.dataConsole();
|
||||
//}
|
||||
s << v.data();
|
||||
s.restoreControl();
|
||||
s.quote();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PIStringList& PIStringList::removeDuplicates() {
|
||||
PIStringList l;
|
||||
PIString s;
|
||||
bool ae;
|
||||
for (int i = 0; i < size_s(); ++i) {
|
||||
ae = false;
|
||||
s = at(i);
|
||||
for (int j = 0; j < l.size_s(); ++j) {
|
||||
if (s != l[j]) continue;
|
||||
ae = true; break;
|
||||
}
|
||||
if (!ae) {
|
||||
l << s;
|
||||
continue;
|
||||
}
|
||||
remove(i);
|
||||
--i;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user