string brush
This commit is contained in:
@@ -812,11 +812,12 @@ bool PITerminal::initialize() {
|
||||
//piCoutObj << fr << PRIVATE->fd << pty;
|
||||
if (fr == 0) {
|
||||
char ** argv = new char*[2];
|
||||
argv[0] = new char[PRIVATE->shell.lengthAscii() + 1];
|
||||
memcpy(argv[0], PRIVATE->shell.dataAscii(), PRIVATE->shell.lengthAscii());
|
||||
argv[0][PRIVATE->shell.lengthAscii()] = 0;
|
||||
PIByteArray shell = PRIVATE->shell.toByteArray();
|
||||
argv[0] = new char[shell.size() + 1];
|
||||
memcpy(argv[0], shell.data(), shell.size());
|
||||
argv[0][shell.size()] = 0;
|
||||
argv[1] = 0;
|
||||
execvp(PRIVATE->shell.dataAscii(), argv);
|
||||
execvp(shell.data(), argv);
|
||||
delete[] argv[0];
|
||||
delete[] argv;
|
||||
exit(0);
|
||||
|
||||
@@ -121,7 +121,6 @@ public:
|
||||
|
||||
virtual uint classNameID() const {static uint ret = PIStringAscii("PIObject").hash(); return ret;}
|
||||
|
||||
static const PIString __classNameS() {return PIStringAscii("PIObject");}
|
||||
static const char * __classNameCC() {return "PIObject";}
|
||||
static uint __classNameIDS() {static uint ret = PIStringAscii("PIObject").hash(); return ret;}
|
||||
|
||||
|
||||
@@ -392,7 +392,6 @@
|
||||
protected: \
|
||||
typedef name __PIObject__; \
|
||||
public: \
|
||||
static const PIString __classNameS() {static PIString ret = PIStringAscii(#name); return ret;} \
|
||||
static const char * __classNameCC() {return #name;} \
|
||||
static uint __classNameIDS() {static uint ret = PIStringAscii(#name).hash(); return ret;} \
|
||||
virtual const char * className() const {return #name;} \
|
||||
|
||||
@@ -82,8 +82,6 @@ const float PIString::ElideLeft = 0.f;
|
||||
const float PIString::ElideCenter = .5f;
|
||||
const float PIString::ElideRight = 1.f;
|
||||
|
||||
static const char * _PIString_empty_cc = "";
|
||||
|
||||
|
||||
#ifndef CC_VC
|
||||
# define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); sprintf(ch, f, v); return PIString(ch);
|
||||
@@ -252,6 +250,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
||||
|
||||
PIString PIString::fromConsole(const char * s) {
|
||||
PIString ret;
|
||||
if (!s) return ret;
|
||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __sysoemname__);
|
||||
return ret;
|
||||
|
||||
@@ -260,6 +259,7 @@ PIString PIString::fromConsole(const char * s) {
|
||||
|
||||
PIString PIString::fromSystem(const char * s) {
|
||||
PIString ret;
|
||||
if (!s) return ret;
|
||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __syslocname__);
|
||||
return ret;
|
||||
}
|
||||
@@ -267,6 +267,7 @@ PIString PIString::fromSystem(const char * s) {
|
||||
|
||||
PIString PIString::fromUTF8(const char * s) {
|
||||
PIString ret;
|
||||
if (!s) return ret;
|
||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __utf8name__);
|
||||
return ret;
|
||||
}
|
||||
@@ -331,10 +332,7 @@ PIString PIString::readableSize(llong bytes) {
|
||||
|
||||
void PIString::buildData(const char * cp) const {
|
||||
//data_.clear();
|
||||
if (data_) {
|
||||
free(data_);
|
||||
data_ = nullptr;
|
||||
}
|
||||
deleteData();
|
||||
int sz = 0;
|
||||
#ifdef PIP_ICU
|
||||
UErrorCode e((UErrorCode)0);
|
||||
@@ -395,6 +393,13 @@ void PIString::buildData(const char * cp) const {
|
||||
}
|
||||
|
||||
|
||||
void PIString::deleteData() const {
|
||||
if (!data_) return;
|
||||
free(data_);
|
||||
data_ = nullptr;
|
||||
}
|
||||
|
||||
|
||||
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)) {
|
||||
@@ -445,8 +450,9 @@ PIString & PIString::operator +=(const char * str) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIString::~PIString() {
|
||||
if(data_) free(data_);
|
||||
deleteData();
|
||||
}
|
||||
|
||||
|
||||
@@ -1363,7 +1369,7 @@ PIString PIString::inBrackets(const PIChar start, const PIChar end) const {
|
||||
//! \endcode
|
||||
//! \~\sa \a dataConsole(), \a dataUTF8()
|
||||
const char * PIString::data() const {
|
||||
if (isEmpty()) return _PIString_empty_cc;
|
||||
if (isEmpty()) return "";
|
||||
buildData(__syslocname__);
|
||||
return data_;
|
||||
}
|
||||
@@ -1381,7 +1387,7 @@ const char * PIString::data() const {
|
||||
//! действителен до следующего вызова этого метода
|
||||
//! \~\sa \a data(), \a dataUTF8()
|
||||
const char * PIString::dataConsole() const {
|
||||
if (isEmpty()) return _PIString_empty_cc;
|
||||
if (isEmpty()) return "";
|
||||
buildData(__sysoemname__ );
|
||||
return data_;
|
||||
}
|
||||
@@ -1399,7 +1405,7 @@ const char * PIString::dataConsole() const {
|
||||
//! действителен до следующего вызова этого метода
|
||||
//! \~\sa \a data(), \a dataConsole()
|
||||
const char * PIString::dataUTF8() const {
|
||||
if (isEmpty()) return _PIString_empty_cc;
|
||||
if (isEmpty()) return "";
|
||||
buildData(__utf8name__);
|
||||
return data_;
|
||||
}
|
||||
@@ -1417,11 +1423,8 @@ const char * PIString::dataUTF8() const {
|
||||
//! действителен до следующего вызова этого метода
|
||||
//! \~\sa \a dataConsole(), \a dataUTF8()
|
||||
const char * PIString::dataAscii() const {
|
||||
if (isEmpty()) return _PIString_empty_cc;
|
||||
if (data_) {
|
||||
free(data_);
|
||||
data_ = nullptr;
|
||||
}
|
||||
if (isEmpty()) return "";
|
||||
deleteData();
|
||||
data_ = (char*)malloc(size()+1);
|
||||
for (int i = 0; i < size_s(); ++i) {
|
||||
data_[i] = uchar(at(i).ch);
|
||||
|
||||
@@ -39,7 +39,7 @@ class PIP_EXPORT PIString: public PIDeque<PIChar>
|
||||
public:
|
||||
//! \~english Contructs an empty string
|
||||
//! \~russian Создает пустую строку
|
||||
PIString(): PIDeque<PIChar>() {data_ = nullptr;}
|
||||
PIString(): PIDeque<PIChar>() {}
|
||||
|
||||
//! \~english Value for elide at left
|
||||
//! \~russian Значение для пропуска слева
|
||||
@@ -62,18 +62,18 @@ public:
|
||||
|
||||
//! \~english Contructs a copy of string
|
||||
//! \~russian Создает копию строки
|
||||
PIString(const PIString & o): PIDeque<PIChar>(o) {data_ = nullptr;}
|
||||
PIString(const PIString & o): PIDeque<PIChar>(o) {}
|
||||
|
||||
PIString(PIString && o): PIDeque<PIChar>(std::move(o)) {data_ = nullptr;}
|
||||
PIString(PIString && o): PIDeque<PIChar>(std::move(o)) {}
|
||||
|
||||
|
||||
//! \~english Contructs string with single symbol "c"
|
||||
//! \~russian Создает строку из одного символа "c"
|
||||
PIString(const PIChar c): PIDeque<PIChar>() {data_ = nullptr; *this += c;}
|
||||
PIString(const PIChar c): PIDeque<PIChar>() {*this += c;}
|
||||
|
||||
//! \~english Contructs string with single symbol "c"
|
||||
//! \~russian Создает строку из одного символа "c"
|
||||
PIString(const char c): PIDeque<PIChar>() {data_ = nullptr; *this += PIChar(c);}
|
||||
PIString(const char c): PIDeque<PIChar>() {*this += PIChar(c);}
|
||||
|
||||
//! \~english Contructs string from C-string "str" (system codepage)
|
||||
//! \~russian Создает строку из C-строки "str" (кодировка системы)
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIString s("string");
|
||||
//! \endcode
|
||||
PIString(const char * str): PIDeque<PIChar>() {data_ = nullptr; *this += str;}
|
||||
PIString(const char * str): PIDeque<PIChar>() {*this += str;}
|
||||
|
||||
//! \~english Contructs string from \c wchar_t C-string "str"
|
||||
//! \~russian Создает строку из \c wchar_t C-строки "str"
|
||||
@@ -97,15 +97,15 @@ public:
|
||||
//! \~\code
|
||||
//! PIString s(L"string");
|
||||
//! \endcode
|
||||
PIString(const wchar_t * str): PIDeque<PIChar>() {data_ = nullptr; *this += str;}
|
||||
PIString(const wchar_t * str): PIDeque<PIChar>() {*this += str;}
|
||||
|
||||
//! \~english Contructs string from byte array "ba" (as UTF-8)
|
||||
//! \~russian Создает строку из байтового массива "ba" (как UTF-8)
|
||||
PIString(const PIByteArray & ba): PIDeque<PIChar>() {data_ = nullptr; *this += ba;}
|
||||
PIString(const PIByteArray & ba): PIDeque<PIChar>() {*this += ba;}
|
||||
|
||||
//! \~english Contructs string from "len" characters of buffer "str"
|
||||
//! \~russian Создает строку из "len" символов массива "str"
|
||||
PIString(const PIChar * str, const int len): PIDeque<PIChar>(str, size_t(len)) {data_ = nullptr;}
|
||||
PIString(const PIChar * str, const int len): PIDeque<PIChar>(str, size_t(len)) {}
|
||||
|
||||
//! \~english Contructs string from "len" characters of buffer "str" (system codepage)
|
||||
//! \~russian Создает строку из "len" символов массива "str" (кодировка системы)
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIString s("string", 3); // s = "str"
|
||||
//! \endcode
|
||||
PIString(const char * str, const int len): PIDeque<PIChar>() {data_ = nullptr; appendFromChars(str, len);}
|
||||
PIString(const char * str, const int len): PIDeque<PIChar>() {appendFromChars(str, len);}
|
||||
|
||||
//! \~english Contructs string as sequence of characters "c" of buffer with length "len"
|
||||
//! \~russian Создает строку как последовательность длиной "len" символа "c"
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIString s(5, 'p'); // s = "ppppp"
|
||||
//! \endcode
|
||||
PIString(const int len, const char c): PIDeque<PIChar>() {data_ = nullptr; for (int i = 0; i < len; ++i) PIDeque<PIChar>::push_back(PIChar(c));}
|
||||
PIString(const int len, const char c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) PIDeque<PIChar>::push_back(PIChar(c));}
|
||||
|
||||
//! \~english Contructs string as sequence of symbols "c" of buffer with length "len"
|
||||
//! \~russian Создает строку как последовательность длиной "len" символа "c"
|
||||
@@ -129,7 +129,7 @@ public:
|
||||
//! \~\code
|
||||
//! PIString s(5, "№"); // s = "№№№№№"
|
||||
//! \endcode
|
||||
PIString(const int len, const PIChar c): PIDeque<PIChar>() {data_ = nullptr; for (int i = 0; i < len; ++i) PIDeque<PIChar>::push_back(c);}
|
||||
PIString(const int len, const PIChar c): PIDeque<PIChar>() {for (int i = 0; i < len; ++i) PIDeque<PIChar>::push_back(c);}
|
||||
|
||||
~PIString();
|
||||
|
||||
@@ -1397,8 +1397,10 @@ private:
|
||||
static llong toNumberBase(const PIString & value, int base = -1, bool * ok = 0);
|
||||
void appendFromChars(const char * c, int s, const char * cp = __syslocname__);
|
||||
void buildData(const char * cp = __syslocname__) const;
|
||||
void deleteData() const;
|
||||
void trimsubstr(int &st, int &fn) const;
|
||||
mutable char * data_;
|
||||
|
||||
mutable char * data_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user