version 2.39.0

PIString works with PIConstChars
picodeinfo optimizations
PIIODevice::availableClasses
This commit is contained in:
2022-05-03 18:44:00 +03:00
parent 8d5730f715
commit 28ce6e8f3f
9 changed files with 106 additions and 55 deletions

View File

@@ -263,7 +263,7 @@ PIString PIString::fromAscii(const char * s, int len) {
PIString ret;
ret.resize(len);
for (int l = 0; l < len; ++l) {
ret[l] = s[l];
ret[l] = s[l];
}
return ret;
}
@@ -369,14 +369,14 @@ uint PIString::hash() const {
PIByteArray PIString::toUTF8() const {
if (isEmpty()) return PIByteArray(1,'\0');
if (isEmpty()) return PIByteArray();
buildData(__utf8name__);
return PIByteArray(data_, strlen(data_));
}
PIByteArray PIString::toCharset(const char * c) const {
if (isEmpty()) return PIByteArray(1,'\0');
if (isEmpty()) return PIByteArray();
buildData(
#ifdef PIP_ICU
c
@@ -418,6 +418,18 @@ PIString & PIString::operator +=(const PIString & str) {
}
PIString & PIString::operator +=(const PIConstChars & str) {
if (!str.isEmpty()) {
size_t os = d.size();
d.enlarge(str.size());
for (size_t l = 0; l < d.size(); ++l) {
d[os + l] = str[l];
}
}
return *this;
}
bool PIString::operator ==(const PIString & str) const {
return d == str.d;
}

View File

@@ -27,6 +27,7 @@
#define PISTRING_H
#include "pibytearray.h"
#include "piconstchars.h"
#define PIStringAscii PIString::fromAscii
@@ -71,6 +72,7 @@ public:
PIString & operator +=(const wchar_t * str);
PIString & operator +=(const PIByteArray & ba) {appendFromChars((const char * )ba.data(), ba.size_s(), __utf8name__); return *this;}
PIString & operator +=(const PIString & str);
PIString & operator +=(const PIConstChars & str);
//! \~english Contructs a copy of string.
//! \~russian Создает копию строки.
@@ -143,6 +145,8 @@ public:
//! PIString s(5, "№"); // s = "№№№№№"
//! \endcode
PIString(const int len, const PIChar c) {for (int i = 0; i < len; ++i) d.push_back(c);}
PIString(const PIConstChars & c) {*this += c;}
~PIString();
@@ -154,6 +158,14 @@ public:
//! \~russian Оператор перемещающего присваивания.
PIString & operator =(PIString && o) {d.swap(o.d); piSwap(data_, o.data_); return *this;}
//! \~english Assign operator.
//! \~russian Оператор присваивания.
PIString & operator =(const PIConstChars & o) {d.clear(); *this += o; return *this;}
//! \~english Assign operator.
//! \~russian Оператор присваивания.
PIString & operator =(const char * o) {d.clear(); *this += o; return *this;}
//! \~english Compare operator.
//! \~russian Оператор сравнения.
bool operator ==(const PIString & str) const;
@@ -271,6 +283,8 @@ public:
//! \endcode
PIString & operator <<(const wchar_t * str) {*this += str; return *this;}
PIString & operator <<(const PIConstChars & str) {*this += str; return *this;}
//! \~english Append string representation of "num" at the end of string.
//! \~russian Добавляет в конец строковое представление "num".
//! \~\details
@@ -453,6 +467,8 @@ public:
//! \~russian Вставляет "str" в конец строки.
PIString & append(const PIString & str) {d.append(str.d); return *this;}
PIString & append(const PIConstChars & str) {*this += str; return *this;}
//! \~english Insert character `c` at the end of string.
//! \~russian Вставляет символ `c` в конец строки.
PIString & append(const PIChar c) {d.append(c); return *this;}
@@ -469,6 +485,8 @@ public:
//! \~russian Вставляет "str" в конец строки.
PIString & push_back(const PIString & str) {d.push_back(str.d); return *this;}
PIString & push_back(const PIConstChars & str) {*this += str; return *this;}
//! \~english Insert character `c` at the end of string.
//! \~russian Вставляет символ `c` в конец строки.
PIString & push_back(const PIChar c) {d.push_back(c); return *this;}