version 3.17.0

finally properly works PIIOString inside PIIOStream
This commit is contained in:
2024-04-05 15:34:38 +03:00
parent 8d585439bb
commit 9283c88b4e
6 changed files with 155 additions and 47 deletions

View File

@@ -324,6 +324,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
ucs2.copy((char16_t *)d.data(old_sz), ucs2.size());
# endif
#endif
changed_ = true;
}
@@ -455,6 +456,9 @@ PIString PIString::readableSize(llong bytes) {
void PIString::buildData(const char * cp) const {
if (!changed_ && (last_loc_ == cp) && data_) return;
last_loc_ = cp;
changed_ = false;
deleteData();
#ifdef PIP_ICU
UErrorCode e((UErrorCode)0);
@@ -464,7 +468,8 @@ void PIString::buildData(const char * cp) const {
data_ = (char *)malloc(len);
int sz = ucnv_fromUChars(cc, data_, len, (const UChar *)(d.data()), d.size_s(), &e);
ucnv_close(cc);
data_[sz] = '\0';
data_[sz] = '\0';
data_size_ = sz;
return;
}
#else
@@ -477,13 +482,15 @@ void PIString::buildData(const char * cp) const {
}
data_ = (char *)malloc(sz + 1);
WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), (LPSTR)data_, sz, NULL, NULL);
data_[sz] = '\0';
data_[sz] = '\0';
data_size_ = sz;
return;
# else
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> ucs2conv;
std::string u8str = ucs2conv.to_bytes((char16_t *)d.data(), (char16_t *)d.data() + d.size());
data_ = (char *)malloc(u8str.size() + 1);
strcpy(data_, u8str.c_str());
data_size_ = u8str.size();
# endif
#endif
}
@@ -492,7 +499,8 @@ void PIString::buildData(const char * cp) const {
void PIString::deleteData() const {
if (!data_) return;
free(data_);
data_ = nullptr;
data_ = nullptr;
data_size_ = 0;
}
@@ -594,6 +602,7 @@ PIString & PIString::operator+=(const wchar_t * str) {
while (str[++i]) {
d.push_back(PIChar(str[i]));
}
changed_ = true;
return *this;
}
@@ -604,12 +613,14 @@ PIString & PIString::operator+=(const char16_t * str) {
while (str[++i]) {
d.push_back(PIChar(str[i]));
}
changed_ = true;
return *this;
}
PIString & PIString::operator+=(const PIString & str) {
d.append(str.d);
changed_ = true;
return *this;
}
@@ -622,6 +633,7 @@ PIString & PIString::operator+=(const PIConstChars & str) {
d[os + l] = str[l];
}
}
changed_ = true;
return *this;
}
@@ -729,6 +741,7 @@ PIString & PIString::cutMid(int start, int len) {
if (len > length() - start) len = length() - start;
d.remove(start, len);
}
changed_ = true;
return *this;
}
@@ -781,6 +794,7 @@ PIString & PIString::replace(int from, int count, const PIString & with) {
d.remove(from, count);
d.insert(from, with.d);
}
changed_ = true;
return *this;
}
@@ -837,6 +851,7 @@ PIString & PIString::replaceAll(const PIString & what, const PIString & with) {
i += dl;
}
}
changed_ = true;
return *this;
}
@@ -863,6 +878,7 @@ PIString & PIString::replaceAll(const PIString & what, const char with) {
if (dl > 0) d.remove(i, dl);
d[i] = PIChar(with);
}
changed_ = true;
return *this;
}
@@ -879,6 +895,7 @@ PIString & PIString::replaceAll(const char what, const char with) {
for (int i = 0; i < l; ++i) {
if (at(i) == what) d[i] = with;
}
changed_ = true;
return *this;
}
@@ -898,12 +915,14 @@ PIString & PIString::removeAll(const PIString & str) {
d.remove(i, l);
i -= l;
}
changed_ = true;
return *this;
}
PIString & PIString::insert(int index, const PIString & str) {
d.insert(index, str.d);
changed_ = true;
return *this;
}
@@ -920,6 +939,7 @@ PIString & PIString::elide(int size, float pos) {
int ls = piRoundf(ns * pos);
d.remove(ls, length() - ns);
d.insert(ls, s_dotdot.d);
changed_ = true;
return *this;
}