From 9cd0389a0bfc1f70e8c9e8bdafddd8f092ed9b16 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 26 Apr 2022 14:41:12 +0300 Subject: [PATCH 1/4] PIString wo pideue parent --- libs/main/core/pistring.cpp | 156 +++++++++++------------------ libs/main/core/pistring.h | 195 +++++++++++++++++++++++++----------- 2 files changed, 194 insertions(+), 157 deletions(-) diff --git a/libs/main/core/pistring.cpp b/libs/main/core/pistring.cpp index 9395c78d..36a4ea5e 100644 --- a/libs/main/core/pistring.cpp +++ b/libs/main/core/pistring.cpp @@ -83,11 +83,7 @@ const float PIString::ElideCenter = .5f; const float PIString::ElideRight = 1.f; -#ifndef CC_VC -# 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); return PIString(ch); -#endif +#define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); snprintf(ch, 256, f, v); return PIString(ch); PIString PIString::itos(const int num) {pisprintf("%d", num);} PIString PIString::ltos(const long num) {pisprintf("%ld", num);} @@ -206,18 +202,10 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { UConverter * cc = ucnv_open(codepage, &e); if (cc) { if (s == -1) s = strlen(c); - enlarge(s); -// UChar * ucs = new UChar[s]; -// memset(ucs, 0, s * sizeof(UChar)); + d.enlarge(s); e = (UErrorCode)0; - int sz = ucnv_toUChars(cc, (UChar*)(PIDeque::data(old_sz)), s, c, s, &e); - //printf("appendFromChars %d -> %d\n", s, sz); - //printf("PIString %d -> %d\n", c[0], ucs[0]); - resize(old_sz+sz); -// for (int i = 0; i < sz; ++i) { -// push_back(PIChar((ushort)ucs[i])); -// } -// delete[] ucs; + int sz = ucnv_toUChars(cc, (UChar*)(d.data(old_sz)), s, c, s, &e); + d.resize(old_sz+sz); ucnv_close(cc); return; } @@ -226,10 +214,9 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { if (s == -1) s = strlen(c); int sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0); if (sz <= 0) return; - enlarge(sz); - MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)PIDeque::data(old_sz), sz); + d.enlarge(sz); + MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)d.data(old_sz), sz); return; - //printf("request %d\n", sz); # else mbstate_t state; memset(&state, 0, sizeof(state)); @@ -247,9 +234,8 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { wchar_t wstr[len+1]; mbsrtowcs(&wstr[0], pc, len+1, &state); if (c_) free(c_); - enlarge(len); - for (size_t i=0; i::data()), size_s(), &e); -// char uc[8]; -// data_.reserve(size_s()); -// for (int i = 0; i < size_s(); ++i) { -// if (at(i).isAscii()) { -// data_.push_back(uchar(at(i).unicode16Code())); -// } else { -// e = (UErrorCode)0; -// for (int j = 0; j < sz; ++j) { -// data_.push_back(uc[j]); -// } -// } -// } + sz = ucnv_fromUChars(cc, data_, len, (const UChar*)(d.data()), d.size_s(), &e); ucnv_close(cc); data_[sz] = '\0'; -// data_.push_back('\0'); return; } #else # ifdef WINDOWS - sz = WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)PIDeque::data(), PIDeque::size_s(), 0, 0, NULL, NULL); - //printf("WideCharToMultiByte %d %d\n", (uint)(uintptr_t)cp, sz); + sz = WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), 0, 0, NULL, NULL); if (sz <= 0) { - //printf("WideCharToMultiByte erro %d\n", GetLastError()); data_ = (char *)malloc(1); data_[0] = '\0'; return; } data_ = (char *)malloc(sz+1); - //data_.resize(sz); - WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)PIDeque::data(), PIDeque::size_s(), (LPSTR)data_, sz, NULL, NULL); + WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), (LPSTR)data_, sz, NULL, NULL); data_[sz] = '\0'; return; # else wchar_t wc; - //char tc[MB_CUR_MAX]; mbstate_t state; memset(&state, 0, sizeof(state)); data_ = (char *)malloc(MB_CUR_MAX*size()+1); char *p = data_; - for (int i = 0; i < size_s(); ++i) { -// if (at(i).isAscii()) { -// data_.push_back(uchar(at(i).toAscii())); -// continue; -// } + for (int i = 0; i < d.size_s(); ++i) { wc = at(i).toWChar(); sz = wcrtomb(p, wc, &state); if (sz < 0) break; @@ -411,14 +375,14 @@ void PIString::deleteData() const { void PIString::trimsubstr(int &st, int &fn) const { - for (int i = 0; i < length(); ++i) { + for (int i = 0; i < d.size_s(); ++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) { + for (int i = d.size_s() - 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; @@ -428,7 +392,7 @@ void PIString::trimsubstr(int &st, int &fn) const { uint PIString::hash() const { - return piHashData((const uchar*)PIDeque::data(), size() * sizeof(PIChar)); + return piHashData((const uchar*)d.data(), d.size() * sizeof(PIChar)); } @@ -470,45 +434,35 @@ PIString & PIString::operator +=(const wchar_t * str) { if (!str) return *this; int i = -1; while (str[++i]) { - push_back(PIChar(str[i])); + d.push_back(PIChar(str[i])); } return *this; } PIString & PIString::operator +=(const PIString & str) { - PIDeque::append(*(const PIDeque*)&str); + d.append(str.d); return *this; } 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; - } - return true; + return d == str.d; } 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; - } - return false; + return d != str.d; } bool PIString::operator <(const PIString & str) const { - uint l = str.size(); + size_t l = str.size(); if (size() < l) return true; if (size() > l) return false; - for (uint i = 0; i < l; ++i) { - if (at(i) == str[i]) continue; - if (at(i) < str[i]) return true; + for (size_t i = 0; i < l; ++i) { + if (at(i) == str.at(i)) continue; + if (at(i) < str.at(i)) return true; else return false; } return false; @@ -516,12 +470,12 @@ bool PIString::operator <(const PIString & str) const { bool PIString::operator >(const PIString & str) const { - uint l = str.size(); + size_t l = str.size(); if (size() < l) return false; if (size() > l) return true; - for (uint i = 0; i < l; ++i) { - if (at(i) == str[i]) continue; - if (at(i) < str[i]) return false; + for (size_t i = 0; i < l; ++i) { + if (at(i) == str.at(i)) continue; + if (at(i) < str.at(i)) return false; else return true; } return false; @@ -552,10 +506,10 @@ PIString PIString::mid(const int start, const int len) const { s = 0; } if (l < 0) { - return PIString(&(at(s)), size_s() - s); + return PIString(d.data(s), size_s() - s); } else { if (l > length() - s) l = length() - s; - return PIString(&(at(s)), l); + return PIString(d.data(s), l); } return PIString(); } @@ -580,10 +534,10 @@ PIString & PIString::cutMid(const int start, const int len) { s = 0; } if (l < 0) { - remove(s, size() - s); + d.remove(s, size() - s); } else { if (l > length() - s) l = length() - s; - remove(s, l); + d.remove(s, l); } return *this; } @@ -632,10 +586,10 @@ PIString PIString::trimmed() const { PIString & PIString::replace(int from, int count, const PIString & with) { count = piMini(count, length() - from); if (count == with.size_s()) { - memcpy(PIDeque::data(from), static_cast>(with).data(), count * sizeof(PIChar)); + memcpy(d.data(from), with.d.data(), count * sizeof(PIChar)); } else { - remove(from, count); - PIDeque::insert(from, with); + d.remove(from, count); + d.insert(from, with.d); } return *this; } @@ -687,9 +641,9 @@ PIString & PIString::replaceAll(const PIString & what, const PIString & with) { } } if (!match) continue; - if (dl > 0) PIDeque::insert(i, PIDeque((size_t)dl)); - if (dl < 0) PIDeque::remove(i, -dl); - memcpy(PIDeque::data(i), &(with.at(0)), with.length() * sizeof(PIChar)); + if (dl > 0) d.insert(i, PIDeque((size_t)dl)); + if (dl < 0) d.remove(i, -dl); + memcpy(d.data(i), with.d.data(), with.size() * sizeof(PIChar)); } } return *this; @@ -715,8 +669,8 @@ PIString & PIString::replaceAll(const PIString & what, const char with) { } } if (!match) continue; - if (dl > 0) PIDeque::remove(i, dl); - (*this)[i] = PIChar(with); + if (dl > 0) d.remove(i, dl); + d[i] = PIChar(with); } return *this; } @@ -732,7 +686,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) d[i] = with; } return *this; } @@ -744,13 +698,13 @@ PIString & PIString::removeAll(const PIString & str) { for (int i = 0; i < length() - l + 1; ++i) { bool match = true; for (int j = 0; j < l; ++j) { - if (at(j + i) != str[j]) { + if (d.at(j + i) != str.at(j)) { match = false; break; } } if (!match) continue; - PIDeque::remove(i, l); + d.remove(i, l); i -= l; } return *this; @@ -758,7 +712,7 @@ PIString & PIString::removeAll(const PIString & str) { PIString & PIString::insert(int index, const PIString & str) { - PIDeque::insert(index, *((const PIDeque*)&str)); + d.insert(index, str.d); return *this; } @@ -773,8 +727,8 @@ PIString & PIString::elide(int size, float pos) { pos = piClampf(pos, 0.f, 1.f); int ns = size - 2; int ls = piRoundf(ns * pos); - remove(ls, length() - ns); - insert(ls, s_dotdot); + d.remove(ls, length() - ns); + d.insert(ls, s_dotdot.d); return *this; } @@ -860,6 +814,14 @@ int PIString::findLast(const char c, const int start) const { return -1; } +int PIString::findLast(PIChar c, const int start) const +{ + for (int i = length() - 1; i >= start; --i) { + if (at(i) == c) return i; + } + return -1; +} + //! \~\details //! \~\code @@ -909,14 +871,14 @@ int PIString::findWord(const PIString & word, const int start) const { bool ok = true; PIChar c; if (f > 0) { - c = (*this)[f - 1]; + c = at(f - 1); if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) { ok = false; continue; } } if (f + wl < tl) { - c = (*this)[f + wl]; + c = at(f + wl); if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) { ok = false; continue; @@ -943,14 +905,14 @@ int PIString::findCWord(const PIString & word, const int start) const { bool ok = true; PIChar c; if (f > 0) { - c = (*this)[f - 1]; + c = at(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]; + c = at(f + wl); if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r' || (c != '_' && !c.isAlpha() && !c.isDigit()))) { ok = false; continue; @@ -1448,7 +1410,7 @@ PIString PIString::toUpperCase() const { PIString str(*this); int l = str.size(); for (int i = 0; i < l; ++i) { - str[i] = str[i].toUpper(); + str.d[i] = str.d[i].toUpper(); } return str; } @@ -1458,7 +1420,7 @@ PIString PIString::toLowerCase() const { PIString str(*this); int l = str.size(); for (int i = 0; i < l; ++i) { - str[i] = str[i].toLower(); + str.d[i] = str.d[i].toLower(); } return str; } diff --git a/libs/main/core/pistring.h b/libs/main/core/pistring.h index 99fd4da2..2080e810 100644 --- a/libs/main/core/pistring.h +++ b/libs/main/core/pistring.h @@ -33,13 +33,25 @@ class PIStringList; -class PIP_EXPORT PIString: public PIDeque +class PIP_EXPORT PIString { friend PIByteArray & operator >>(PIByteArray & s, PIString & v); + friend PIByteArray & operator <<(PIByteArray & s, const PIString & v); public: + typedef PIDeque::iterator iterator; + typedef PIDeque::const_iterator const_iterator; + typedef PIDeque::reverse_iterator reverse_iterator; + typedef PIDeque::const_reverse_iterator const_reverse_iterator; + typedef PIChar value_type; + typedef PIChar* pointer; + typedef const PIChar* const_pointer; + typedef PIChar& reference; + typedef const PIChar& const_reference; + typedef size_t size_type; + //! \~english Contructs an empty string //! \~russian Создает пустую строку - PIString(): PIDeque() {} + PIString() {} //! \~english Value for elide at left //! \~russian Значение для пропуска слева @@ -53,8 +65,8 @@ public: //! \~russian Значение для пропуска справа static const float ElideRight ; - PIString & operator +=(const PIChar & c) {PIDeque::push_back(c); return *this;} - PIString & operator +=(const char c) {PIDeque::push_back(PIChar(c)); return *this;} + PIString & operator +=(const PIChar & c) {d.push_back(c); return *this;} + PIString & operator +=(const char c) {d.push_back(PIChar(c)); return *this;} PIString & operator +=(const char * str); PIString & operator +=(const wchar_t * str); PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;} @@ -62,18 +74,18 @@ public: //! \~english Contructs a copy of string //! \~russian Создает копию строки - PIString(const PIString & o): PIDeque(o) {} + PIString(const PIString & o) {d = o.d;} - PIString(PIString && o): PIDeque(std::move(o)) {} + PIString(PIString && o): d(std::move(o.d)) {piSwap(data_, o.data_);} //! \~english Contructs string with single symbol "c" //! \~russian Создает строку из одного символа "c" - PIString(const PIChar c): PIDeque() {*this += c;} + PIString(const PIChar c) {*this += c;} //! \~english Contructs string with single symbol "c" //! \~russian Создает строку из одного символа "c" - PIString(const char c): PIDeque() {*this += PIChar(c);} + PIString(const char c) {*this += PIChar(c);} //! \~english Contructs string from C-string "str" (system codepage) //! \~russian Создает строку из C-строки "str" (кодировка системы) @@ -85,7 +97,7 @@ public: //! \~\code //! PIString s("string"); //! \endcode - PIString(const char * str): PIDeque() {*this += str;} + PIString(const char * str) {*this += str;} //! \~english Contructs string from \c wchar_t C-string "str" //! \~russian Создает строку из \c wchar_t C-строки "str" @@ -97,15 +109,15 @@ public: //! \~\code //! PIString s(L"string"); //! \endcode - PIString(const wchar_t * str): PIDeque() {*this += str;} + PIString(const wchar_t * str) {*this += str;} //! \~english Contructs string from byte array "ba" (as UTF-8) //! \~russian Создает строку из байтового массива "ba" (как UTF-8) - PIString(const PIByteArray & ba): PIDeque() {*this += ba;} + PIString(const PIByteArray & ba) {*this += ba;} //! \~english Contructs string from "len" characters of buffer "str" //! \~russian Создает строку из "len" символов массива "str" - PIString(const PIChar * str, const int len): PIDeque(str, size_t(len)) {} + PIString(const PIChar * str, const int len): d(str, size_t(len)) {} //! \~english Contructs string from "len" characters of buffer "str" (system codepage) //! \~russian Создает строку из "len" символов массива "str" (кодировка системы) @@ -113,7 +125,7 @@ public: //! \~\code //! PIString s("string", 3); // s = "str" //! \endcode - PIString(const char * str, const int len): PIDeque() {appendFromChars(str, len);} + PIString(const char * str, const int len) {appendFromChars(str, len);} //! \~english Contructs string as sequence of characters "c" of buffer with length "len" //! \~russian Создает строку как последовательность длиной "len" символа "c" @@ -121,7 +133,7 @@ public: //! \~\code //! PIString s(5, 'p'); // s = "ppppp" //! \endcode - PIString(const int len, const char c): PIDeque() {for (int i = 0; i < len; ++i) PIDeque::push_back(PIChar(c));} + PIString(const int len, const char c) {for (int i = 0; i < len; ++i) d.push_back(PIChar(c));} //! \~english Contructs string as sequence of symbols "c" of buffer with length "len" //! \~russian Создает строку как последовательность длиной "len" символа "c" @@ -129,16 +141,16 @@ public: //! \~\code //! PIString s(5, "№"); // s = "№№№№№" //! \endcode - PIString(const int len, const PIChar c): PIDeque() {for (int i = 0; i < len; ++i) PIDeque::push_back(c);} + PIString(const int len, const PIChar c) {for (int i = 0; i < len; ++i) d.push_back(c);} ~PIString(); //! \~english Assign operator //! \~russian Оператор присваивания - PIString & operator =(const PIString & o) {if (this == &o) return *this; clear(); *this += o; return *this;} + PIString & operator =(const PIString & o) {if (this == &o) return *this; d = o.d; return *this;} - PIString & operator =(PIString && o) {swap(o); return *this;} + PIString & operator =(PIString && o) {d.swap(o.d); piSwap(data_, o.data_); return *this;} //! \~english Compare operator //! \~russian Оператор сравнения @@ -146,7 +158,7 @@ public: //! \~english Compare operator //! \~russian Оператор сравнения - bool operator ==(const PIChar c) const {if (size_s() != 1) return false; return at(0) == c;} + bool operator ==(const PIChar c) const {if (d.size() != 1) return false; return d.at(0) == c;} //! \~english Compare operator //! \~russian Оператор сравнения @@ -158,7 +170,7 @@ public: //! \~english Compare operator //! \~russian Оператор сравнения - bool operator !=(const PIChar c) const {if (size_s() != 1) return true; return at(0) != c;} + bool operator !=(const PIChar c) const {if (d.size() != 1) return true; return d.at(0) != c;} //! \~english Compare operator //! \~russian Оператор сравнения @@ -170,7 +182,7 @@ public: //! \~english Compare operator //! \~russian Оператор сравнения - bool operator <(const PIChar c) const {if (size_s() != 1) return size_s() < 1; return at(0) < c;} + bool operator <(const PIChar c) const {if (d.size() != 1) return d.size() < 1; return d.at(0) < c;} //! \~english Compare operator //! \~russian Оператор сравнения @@ -182,7 +194,7 @@ public: //! \~english Compare operator //! \~russian Оператор сравнения - bool operator >(const PIChar c) const {if (size_s() != 1) return size_s() > 1; return at(0) > c;} + bool operator >(const PIChar c) const {if (d.size() != 1) return d.size() > 1; return d.at(0) > c;} //! \~english Compare operator //! \~russian Оператор сравнения @@ -228,7 +240,7 @@ public: //! PIString s("stri"); //! s << PIChar('n') << PIChar('g'); // s = "string" //! \endcode - PIString & operator <<(const PIChar c) {*this += c; return *this;} + PIString & operator <<(const PIChar c) {d.append(c); return *this;} //! \~english Append symbol `c` at the end of string //! \~russian Добавляет в конец символ `c` @@ -237,7 +249,7 @@ public: //! PIString s("stri"); //! s << 'n' << 'g'; // s = "string" //! \endcode - PIString & operator <<(const char c) {*this += PIChar(c); return *this;} + PIString & operator <<(const char c) {d.append(PIChar(c)); return *this;} //! \~english Append С-string "str" at the end of string //! \~russian Добавляет в конец C-строку "str" @@ -298,6 +310,36 @@ public: //! \endcode PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;} + inline iterator begin() {return d.begin();} + inline iterator end() {return d.end();} + + inline const_iterator begin() const {return d.begin();} + inline const_iterator end() const {return d.end();} + + inline reverse_iterator rbegin() {return d.rbegin();} + inline reverse_iterator rend() {return d.rend();} + + inline const_reverse_iterator rbegin() const {return d.rbegin();} + inline const_reverse_iterator rend() const {return d.rend();} + + inline PIChar & operator [](size_t index) {return d[index];} + inline PIChar operator [](size_t index) const {return d[index];} + + inline const PIChar at(size_t index) const {return d.at(index);} + + inline PIChar & back() {return d.back();} + inline PIChar back() const {return d.back();} + + inline PIChar & front() {return d.front();} + inline PIChar front() const {return d.front();} + + inline PIString & resize(size_t new_size, PIChar c = PIChar()) {d.resize(new_size, c); return *this;} + + inline PIString & pop_back() {d.pop_back(); return *this;} + inline PIString & pop_front() {d.pop_front(); return *this;} + + inline PIString & remove(size_t index, size_t count = 1) {d.remove(index, count); return *this;} + inline PIString & fill(PIChar c = PIChar()) {d.fill(c); return *this;} //! \~english Insert string "str" at the begin of string //! \~russian Вставляет "str" в начало строки @@ -305,15 +347,15 @@ public: //! \~english Insert string "str" at the begin of string //! \~russian Вставляет "str" в начало строки - PIString & prepend(const PIString & str) {insert(0, str); return *this;} + PIString & prepend(const PIString & str) {d.prepend(str.d); return *this;} //! \~english Insert symbol `c` at the begin of string //! \~russian Вставляет символ `c` в начало строки - PIString & prepend(const PIChar c) {PIDeque::prepend(c); return *this;} + PIString & prepend(const PIChar c) {d.prepend(c); return *this;} //! \~english Insert symbol `c` at the begin of string //! \~russian Вставляет символ `c` в начало строки - PIString & prepend(const char c) {PIDeque::prepend(PIChar(c)); return *this;} + PIString & prepend(const char c) {d.prepend(PIChar(c)); return *this;} //! \~english Insert string "str" at the begin of string //! \~russian Вставляет "str" в начало строки @@ -321,15 +363,15 @@ public: //! \~english Insert string "str" at the begin of string //! \~russian Вставляет "str" в начало строки - PIString & push_front(const PIString & str) {insert(0, str); return *this;} + PIString & push_front(const PIString & str) {d.push_front(str.d); return *this;} //! \~english Insert symbol `c` at the begin of string //! \~russian Вставляет символ `c` в начало строки - PIString & push_front(const PIChar c) {PIDeque::push_front(c); return *this;} + PIString & push_front(const PIChar c) {d.push_front(c); return *this;} //! \~english Insert symbol `c` at the begin of string //! \~russian Вставляет символ `c` в начало строки - PIString & push_front(const char c) {PIDeque::push_front(PIChar(c)); return *this;} + PIString & push_front(const char c) {d.push_front(PIChar(c)); return *this;} //! \~english Insert string "str" at the end of string //! \~russian Вставляет "str" в конец строки @@ -337,15 +379,15 @@ public: //! \~english Insert string "str" at the end of string //! \~russian Вставляет "str" в конец строки - PIString & append(const PIString & str) {*this += str; return *this;} + PIString & append(const PIString & str) {d.append(str.d); return *this;} //! \~english Insert symbol `c` at the end of string //! \~russian Вставляет символ `c` в конец строки - PIString & append(const PIChar c) {PIDeque::append(c); return *this;} + PIString & append(const PIChar c) {d.append(c); return *this;} //! \~english Insert symbol `c` at the end of string //! \~russian Вставляет символ `c` в конец строки - PIString & append(const char c) {PIDeque::append(PIChar(c)); return *this;} + PIString & append(const char c) {d.append(PIChar(c)); return *this;} //! \~english Insert string "str" at the end of string //! \~russian Вставляет "str" в конец строки @@ -353,15 +395,15 @@ public: //! \~english Insert string "str" at the end of string //! \~russian Вставляет "str" в конец строки - PIString & push_back(const PIString & str) {*this += str; return *this;} + PIString & push_back(const PIString & str) {d.push_back(str.d); return *this;} //! \~english Insert symbol `c` at the end of string //! \~russian Вставляет символ `c` в конец строки - PIString & push_back(const PIChar c) {PIDeque::push_back(c); return *this;} + PIString & push_back(const PIChar c) {d.push_back(c); return *this;} //! \~english Insert symbol `c` at the end of string //! \~russian Вставляет символ `c` в конец строки - PIString & push_back(const char c) {PIDeque::push_back(PIChar(c)); return *this;} + PIString & push_back(const char c) {d.push_back(PIChar(c)); return *this;} //! \~english Returns part of string from symbol at index "start" and maximum length "len" @@ -513,7 +555,7 @@ public: //! \~english Remove all founded symbols "what" and return this string //! \~russian Удаляет все найденные символы "what", возвращает эту строку - PIString & removeAll(char c) {PIDeque::removeAll(PIChar(c)); return *this;} + PIString & removeAll(char c) {d.removeAll(PIChar(c)); return *this;} //! \~english Repeat content of string "times" times and return this string //! \~russian Повторяет содержимое строки "times" раз и возвращает эту строку @@ -545,7 +587,7 @@ public: //! s.insert(1, "i"); //! piCout << s; // s = "pip" //! \endcode - PIString & insert(const int index, const PIChar c) {PIDeque::insert(index, c); return *this;} + PIString & insert(const int index, const PIChar c) {d.insert(index, c); return *this;} //! \~english Insert symbol "c" after index "index" and return this string //! \~russian Вставляет символ "c" после позиции "index" и возвращает эту строку @@ -588,7 +630,7 @@ public: //! piCout << s; // s = "str___" //! \endcode //! \~\sa \a expandLeftTo(), \a expandedRightTo(), \a expandedLeftTo() - PIString & expandRightTo(const int len, const PIChar c) {if (len > length()) resize(len, c); return *this;} + PIString & expandRightTo(const int len, const PIChar c) {if (len > d.size_s()) d.resize(len, c); return *this;} //! \~english Enlarge string to length "len" by addition symbols "c" at the begin, and return this string //! \~russian Увеличивает длину строки до "len" добавлением символов "c" в начало и возвращает эту строку @@ -601,7 +643,7 @@ public: //! piCout << s; // s = "___str" //! \endcode //! \~\sa \a expandRightTo(), \a expandedRightTo(), \a expandedLeftTo() - PIString & expandLeftTo(const int len, const PIChar c) {if (len > length()) insert(0, PIString(len - length(), c)); return *this;} + PIString & expandLeftTo(const int len, const PIChar c) {if (len > d.size_s()) insert(0, PIString(len - d.size_s(), c)); return *this;} //! \~english Enlarge copy of this string to length "len" by addition symbols "c" at the end //! \~russian Увеличивает длину копии этой строки до "len" добавлением символов "c" в конец @@ -634,7 +676,7 @@ public: //! piCout << s; // s = ""str"" //! \endcode //! \~\sa \a quoted() - PIString & quote(PIChar c = PIChar('"')) {insert(0, c); *this += c; return *this;} + PIString & quote(PIChar c = PIChar('"')) {d.prepend(c); d.append(c); return *this;} //! \~english Returns quoted copy of this string //! \~russian Возвращает копию строки с добавленным в начало и конец символом "c" @@ -656,7 +698,7 @@ public: //! piCout << s; // s = "9876543210" //! \endcode //! \~\sa \a reversed() - PIString & reverse() {PIDeque::reverse(); return *this;} + PIString & reverse() {d.reverse(); return *this;} //! \~english Reverse copy of this string //! \~russian Разворачивает копию этой строки @@ -804,7 +846,7 @@ public: //! \~english Returns if string contains symbol "c" //! \~russian Возвращает содержит ли строка символ "c" - bool contains(const char c) const {return PIDeque::contains(PIChar(c));} + bool contains(const char c) const {return d.contains(PIChar(c));} //! \~english Returns if string contains substring "str" //! \~russian Возвращает содержит ли строка подстроку "str" @@ -818,10 +860,17 @@ public: //! \~english Search symbol "c" from symbol at index "start" and return first occur position //! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение int find(const char c, const int start = 0) const; + int indexOf(const char c, const int start = 0) const {return find(c, start);} + + //! \~english Search symbol "c" from symbol at index "start" and return first occur position + //! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение + int find(PIChar c, const int start = 0) const {return d.indexOf(c, start);} + int indexOf(PIChar c, const int start = 0) const {return d.indexOf(c, start);} //! \~english Search substring "str" from symbol at index "start" and return first occur position //! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение int find(const PIString & str, const int start = 0) const; + int indexOf(const PIString & str, const int start = 0) const {return find(str, start);} //! \~english Search substring "str" from symbol at index "start" and return first occur position //! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение @@ -835,6 +884,7 @@ public: //! \endcode //! \~\sa \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange() int find(const char * str, const int start = 0) const {return find(PIString(str), start);} + int indexOf(const char * str, const int start = 0) const {return find(str, start);} //! \~english Search any symbol of "str" from symbol at index "start" and return first occur position //! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение @@ -854,10 +904,17 @@ public: //! \~english Search symbol "c" from symbol at index "start" and return last occur position //! \~russian Ищет символ "c" от символа "start" и возвращает последнее вхождение int findLast(const char c, const int start = 0) const; + int lastIndexOf(const char c, const int start = 0) const {return findLast(c, start);} + //! \~english Search symbol "c" from symbol at index "start" and return last occur position + //! \~russian Ищет символ "c" от символа "start" и возвращает последнее вхождение + int findLast(PIChar c, const int start = 0) const; + int lastIndexOf(PIChar c, const int start = 0) const {return findLast(c, start);} + //! \~english Search substring "str" from symbol at index "start" and return last occur position //! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение int findLast(const PIString & str, const int start = 0) const; + int lastIndexOf(const PIString & str, const int start = 0) const {return findLast(str, start);} //! \~english Search substring "str" from symbol at index "start" and return last occur position //! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение @@ -871,6 +928,7 @@ public: //! \endcode //! \~\sa \a find(), \a findAny(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange() int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);} + int lastIndexOf(const char * str, const int start = 0) const {return findLast(str, start);} //! \~english Search any symbol of "str" from symbol at index "start" and return last occur position //! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение @@ -924,19 +982,28 @@ public: //! \~english Returns if string ends with "str" //! \~russian Возвращает оканчивается ли строка на "str" bool endsWith(const PIString & str) const; - + //! \~english Returns symbols length of string //! \~russian Возвращает длину строки в символах - int length() const {return size();} + int length() const {return d.size_s();} + + //! \~english Returns symbols length of string + //! \~russian Возвращает длину строки в символах + size_t size() const {return d.size();} + + //! \~english Returns symbols length of string + //! \~russian Возвращает длину строки в символах + ssize_t size_s() const {return d.size_s();} //! \~english Returns \c true if string is empty, i.e. length = 0 //! \~russian Возвращает \c true если строка пустая, т.е. длина = 0 - bool isEmpty() const {return (size() == 0 || *this == "");} + bool isEmpty() const {if (d.isEmpty()) return true; if (d.at(0) == PIChar()) return true; return false;} //! \~english Returns \c true if string is not empty, i.e. length > 0 //! \~russian Возвращает \c true если строка непустая, т.е. длина > 0 bool isNotEmpty() const {return !isEmpty();} + void clear() {d.clear();} //! \~english Returns \c true if string equal "true", "yes", "on" or positive not null numeric value //! \~russian Возвращает \c true если строка равна "true", "yes", "on" или числу > 0 @@ -1090,7 +1157,7 @@ public: //! s.setNumber(123, 16); //! piCout << s; // 7B //! \endcode - PIString & setNumber(const short value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;} + PIString & setNumber(const short value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;} //! \~english Set string content to text representation of "value" in base "base" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку @@ -1102,7 +1169,7 @@ public: //! s.setNumber(123, 16); //! piCout << s; // 7B //! \endcode - PIString & setNumber(const ushort value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;} + PIString & setNumber(const ushort value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;} //! \~english Set string content to text representation of "value" in base "base" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку @@ -1114,7 +1181,7 @@ public: //! s.setNumber(123, 16); //! piCout << s; // 7B //! \endcode - PIString & setNumber(const int value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;} + PIString & setNumber(const int value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;} //! \~english Set string content to text representation of "value" in base "base" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку @@ -1126,7 +1193,7 @@ public: //! s.setNumber(123, 16); //! piCout << s; // 7B //! \endcode - PIString & setNumber(const uint value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;} + PIString & setNumber(const uint value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;} //! \~english Set string content to text representation of "value" in base "base" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку @@ -1138,7 +1205,7 @@ public: //! s.setNumber(123, 16); //! piCout << s; // 7B //! \endcode - PIString & setNumber(const long value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;} + PIString & setNumber(const long value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;} //! \~english Set string content to text representation of "value" in base "base" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку @@ -1150,7 +1217,7 @@ public: //! s.setNumber(123, 16); //! piCout << s; // 7B //! \endcode - PIString & setNumber(const ulong value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;} + PIString & setNumber(const ulong value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;} //! \~english Set string content to text representation of "value" in base "base" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку @@ -1162,7 +1229,7 @@ public: //! s.setNumber(123, 16); //! piCout << s; // 7B //! \endcode - PIString & setNumber(const llong & value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;} + PIString & setNumber(const llong & value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;} //! \~english Set string content to text representation of "value" in base "base" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" по основанию "base" и возвращает эту строку @@ -1174,7 +1241,7 @@ public: //! s.setNumber(123, 16); //! piCout << s; // 7B //! \endcode - PIString & setNumber(const ullong & value, int base = 10, bool * ok = 0) {clear(); *this += PIString::fromNumber(value, base, ok); return *this;} + PIString & setNumber(const ullong & value, int base = 10, bool * ok = 0) {*this = PIString::fromNumber(value, base, ok); return *this;} //! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку @@ -1192,7 +1259,7 @@ public: //! s.setNumber(123456789., 'f', 0); //! piCout << s; // 123456789 //! \endcode - PIString & setNumber(const float value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;} + PIString & setNumber(const float value, char format = 'f', int precision = 8) {*this = PIString::fromNumber(value, format, precision); return *this;} //! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку @@ -1210,7 +1277,7 @@ public: //! s.setNumber(123456789., 'f', 0); //! piCout << s; // 123456789 //! \endcode - PIString & setNumber(const double & value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;} + PIString & setNumber(const double & value, char format = 'f', int precision = 8) {*this = PIString::fromNumber(value, format, precision); return *this;} //! \~english Set string content to text representation of "value" with format "format" and precision "precision" and return this string //! \~russian Устанавливает содержимое строки в текстовое представление "value" в формате "format" и точностью "precision" и возвращает эту строку @@ -1228,7 +1295,7 @@ public: //! s.setNumber(123456789., 'f', 0); //! piCout << s; // 123456789 //! \endcode - PIString & setNumber(const ldouble & value, char format = 'f', int precision = 8) {clear(); *this += PIString::fromNumber(value, format, precision); return *this;} + PIString & setNumber(const ldouble & value, char format = 'f', int precision = 8) {*this = PIString::fromNumber(value, format, precision); return *this;} //! \~english Set string content to human readable size in B/kB/MB/GB/TB/PB //! \~russian Устанавливает содержимое в строку с читаемым размером B/kB/MB/GB/TB/PB @@ -1345,7 +1412,7 @@ public: //! \~english Returns "true" or "false" //! \~russian Возвращает "true" или "false" - static PIString fromBool(const bool value) {return PIString(value ? "true" : "false");} + static PIString fromBool(const bool value) {return PIString(value ? PIStringAscii("true") : PIStringAscii("false"));} //! \~english Returns string constructed from terminal codepage //! \~russian Возвращает строку созданную из кодировки консоли @@ -1380,6 +1447,11 @@ public: //! \~\sa PIString::setReadableSize() static PIString readableSize(llong bytes); + void swap(PIString & str) { + d.swap(str.d); + piSwap(data_, str.data_); + } + private: static const char toBaseN[]; static const int fromBaseN[]; @@ -1400,6 +1472,7 @@ private: void deleteData() const; void trimsubstr(int &st, int &fn) const; + PIDeque d; mutable char * data_ = nullptr; }; @@ -1412,12 +1485,12 @@ PIP_EXPORT PICout operator <<(PICout s, const PIString & v); //! \relatesalso PIByteArray //! \~english Store operator //! \~russian Оператор сохранения -inline PIByteArray & operator <<(PIByteArray & s, const PIString & v) {s << *(PIDeque*)&v; return s;} +inline PIByteArray & operator <<(PIByteArray & s, const PIString & v) {s << v.d; return s;} //! \relatesalso PIByteArray //! \~english Restore operator //! \~russian Оператор извлечения -inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {v.clear(); s >> *(PIDeque*)&v; return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {v.d.clear(); s >> v.d; return s;} //! \~english Returns concatenated string @@ -1457,6 +1530,8 @@ PIString PIP_EXPORT versionNormalize(const PIString & v); //! \~russian Возвращает хэш строки template<> inline uint piHash(const PIString & s) {return s.hash();} -template<> inline void piSwap(PIString & f, PIString & s) {f.swap(s);} +template<> inline void piSwap(PIString & f, PIString & s) { + f.swap(s); +} #endif // PISTRING_H From 7ad520a1c3d9bc6a9ef306d60d03b57c4fc19431 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 26 Apr 2022 17:19:05 +0300 Subject: [PATCH 2/4] PIString optimization --- libs/main/core/pistring.cpp | 22 +++++++++++----------- main.cpp | 6 ++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libs/main/core/pistring.cpp b/libs/main/core/pistring.cpp index 2448e0ed..fd90b325 100644 --- a/libs/main/core/pistring.cpp +++ b/libs/main/core/pistring.cpp @@ -85,7 +85,7 @@ const float PIString::ElideCenter = .5f; const float PIString::ElideRight = 1.f; -#define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); snprintf(ch, 256, f, v); return PIString(ch); +#define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); snprintf(ch, 256, f, v); return PIStringAscii(ch); PIString PIString::itos(const int num) {pisprintf("%d", num);} PIString PIString::ltos(const long num) {pisprintf("%ld", num);} @@ -95,14 +95,14 @@ 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); + int wr = snprintf(&(f[2]), 8, "%d", precision); f[2 + wr] = format; f[3 + wr] = 0; pisprintf(f, num); } PIString PIString::dtos(const double num, char format, int precision) { char f[8] = "%."; - int wr = sprintf(&(f[2]), "%d", precision); + int wr = snprintf(&(f[2]), 8, "%d", precision); f[2 + wr] = format; f[3 + wr] = 0; pisprintf(f, num); @@ -113,7 +113,7 @@ 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 ((base < 2) || (base > 40)) { if (ok != 0) *ok = false; return PIString(); } @@ -135,7 +135,7 @@ 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 ((base < 2) || (base > 40)) { if (ok != 0) *ok = false; return PIString(); } @@ -166,7 +166,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) { } else { base = 10; } - } else if (base < 2 || base > 40) { + } else if ((base < 2) || (base > 40)) { if (ok != 0) *ok = false; return 0; } @@ -197,6 +197,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) { void PIString::appendFromChars(const char * c, int s, const char * codepage) { +// piCout << "appendFromChars"; if (s == 0) return; int old_sz = size_s(); if (s == -1) s = strlen(c); @@ -221,7 +222,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { std::wstring_convert, char16_t> ucs2conv; std::u16string ucs2 = ucs2conv.from_bytes(c, c+s); enlarge(ucs2.size()); - ucs2.copy((char16_t *)PIDeque::data(old_sz), ucs2.size()); + ucs2.copy((char16_t *)d.data(old_sz), ucs2.size()); # endif #endif } @@ -311,21 +312,20 @@ PIString PIString::readableSize(llong bytes) { void PIString::buildData(const char * cp) const { deleteData(); - int sz = 0; #ifdef PIP_ICU UErrorCode e((UErrorCode)0); UConverter * cc = ucnv_open(cp, &e); if (cc) { const size_t len = MB_CUR_MAX*size()+1; data_ = (char *)malloc(len); - sz = ucnv_fromUChars(cc, data_, len, (const UChar*)(d.data()), d.size_s(), &e); + int sz = ucnv_fromUChars(cc, data_, len, (const UChar*)(d.data()), d.size_s(), &e); ucnv_close(cc); data_[sz] = '\0'; return; } #else # ifdef WINDOWS - sz = WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), 0, 0, NULL, NULL); + int sz = WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), 0, 0, NULL, NULL); if (sz <= 0) { data_ = (char *)malloc(1); data_[0] = '\0'; @@ -337,7 +337,7 @@ void PIString::buildData(const char * cp) const { return; # else std::wstring_convert, char16_t> ucs2conv; - std::string u8str = ucs2conv.to_bytes((char16_t*)PIDeque::data(), (char16_t*)PIDeque::data()+size()); + 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()); # endif diff --git a/main.cpp b/main.cpp index 38a223b9..057e06ab 100644 --- a/main.cpp +++ b/main.cpp @@ -130,7 +130,13 @@ int main(int argc, char * argv[]) { } piCout << l << "PIString::fromNumber" << tm.elapsed_m(); tm.reset(); + for(int i=0; i Date: Tue, 26 Apr 2022 17:20:07 +0300 Subject: [PATCH 3/4] fix --- libs/main/core/pistring.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/main/core/pistring.cpp b/libs/main/core/pistring.cpp index fd90b325..16e26151 100644 --- a/libs/main/core/pistring.cpp +++ b/libs/main/core/pistring.cpp @@ -221,7 +221,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { # else std::wstring_convert, char16_t> ucs2conv; std::u16string ucs2 = ucs2conv.from_bytes(c, c+s); - enlarge(ucs2.size()); + d.enlarge(ucs2.size()); ucs2.copy((char16_t *)d.data(old_sz), ucs2.size()); # endif #endif From d3028a3ce81529796e127faeb874af463fd59497 Mon Sep 17 00:00:00 2001 From: peri4 Date: Tue, 26 Apr 2022 21:01:20 +0300 Subject: [PATCH 4/4] pistring remove indexOf* --- libs/main/core/pistring.h | 8 -------- utils/deploy_tool/main.cpp | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/libs/main/core/pistring.h b/libs/main/core/pistring.h index 2080e810..4c791f40 100644 --- a/libs/main/core/pistring.h +++ b/libs/main/core/pistring.h @@ -860,17 +860,14 @@ public: //! \~english Search symbol "c" from symbol at index "start" and return first occur position //! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение int find(const char c, const int start = 0) const; - int indexOf(const char c, const int start = 0) const {return find(c, start);} //! \~english Search symbol "c" from symbol at index "start" and return first occur position //! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение int find(PIChar c, const int start = 0) const {return d.indexOf(c, start);} - int indexOf(PIChar c, const int start = 0) const {return d.indexOf(c, start);} //! \~english Search substring "str" from symbol at index "start" and return first occur position //! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение int find(const PIString & str, const int start = 0) const; - int indexOf(const PIString & str, const int start = 0) const {return find(str, start);} //! \~english Search substring "str" from symbol at index "start" and return first occur position //! \~russian Ищет подстроку "str" от символа "start" и возвращает первое вхождение @@ -884,7 +881,6 @@ public: //! \endcode //! \~\sa \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange() int find(const char * str, const int start = 0) const {return find(PIString(str), start);} - int indexOf(const char * str, const int start = 0) const {return find(str, start);} //! \~english Search any symbol of "str" from symbol at index "start" and return first occur position //! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение @@ -904,17 +900,14 @@ public: //! \~english Search symbol "c" from symbol at index "start" and return last occur position //! \~russian Ищет символ "c" от символа "start" и возвращает последнее вхождение int findLast(const char c, const int start = 0) const; - int lastIndexOf(const char c, const int start = 0) const {return findLast(c, start);} //! \~english Search symbol "c" from symbol at index "start" and return last occur position //! \~russian Ищет символ "c" от символа "start" и возвращает последнее вхождение int findLast(PIChar c, const int start = 0) const; - int lastIndexOf(PIChar c, const int start = 0) const {return findLast(c, start);} //! \~english Search substring "str" from symbol at index "start" and return last occur position //! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение int findLast(const PIString & str, const int start = 0) const; - int lastIndexOf(const PIString & str, const int start = 0) const {return findLast(str, start);} //! \~english Search substring "str" from symbol at index "start" and return last occur position //! \~russian Ищет подстроку "str" от символа "start" и возвращает последнее вхождение @@ -928,7 +921,6 @@ public: //! \endcode //! \~\sa \a find(), \a findAny(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange() int findLast(const char * str, const int start = 0) const {return findLast(PIString(str), start);} - int lastIndexOf(const char * str, const int start = 0) const {return findLast(str, start);} //! \~english Search any symbol of "str" from symbol at index "start" and return last occur position //! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение diff --git a/utils/deploy_tool/main.cpp b/utils/deploy_tool/main.cpp index 7afdf214..0966ba82 100644 --- a/utils/deploy_tool/main.cpp +++ b/utils/deploy_tool/main.cpp @@ -185,7 +185,7 @@ PIString frameworkName(const PIString & l) { PIString frameworkInternalPath(const PIString & l) { - return l.right(l.size_s() - l.lastIndexOf(".framework") - 11); + return l.right(l.size_s() - l.findLast('.') - 11); } @@ -632,7 +632,7 @@ int main(int argc, char * argv[]) { if (styles.isEmpty()) styles << ""; PIStringList qpd = cli.argumentValue("qt-plugins").toLowerCase().split(DELIM); piForeachC (PIString & qp, qpd) { - int _i = qp.indexOf("="); + int _i = qp.find('='); if (_i < 0) continue; PIString pname = qp.left(_i).trim(); PIStringList pfilt = qp.mid(_i + 1).trim().split(",");