PIString fix

git-svn-id: svn://db.shs.com.ru/pip@44 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
2015-03-30 08:49:19 +00:00
parent 8c051235aa
commit 595543bea9
8 changed files with 301 additions and 69 deletions

View File

@@ -32,6 +32,7 @@ class PIStringList;
class PIP_EXPORT PIString: public PIDeque<PIChar>
{
friend PIByteArray & operator >>(PIByteArray & s, PIString & v);
public:
//! Contructs an empty string
PIString(): PIDeque<PIChar>() {/*reserve(256); */piMonitor.strings++; piMonitor.containers--;}
@@ -122,7 +123,7 @@ public:
operator const char*() {return data();}
//! Return std::string representation of string
operator const std::string() {if (size() == 0) return std::string(); std::string s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toAscii()); return s;}
//operator const std::string() {if (size() == 0) return std::string(); std::string s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toAscii()); return s;}
//! Return symbol at index "pos"
PIChar operator [](const int pos) const {return at(pos);}
@@ -452,10 +453,10 @@ public:
/*! \brief Return real bytes count of this string
* \details It`s equivalent length of char sequence
* returned by function \a data() \n
* returned by function \a data() - 1, without terminating null-char \n
* Example: \snippet pistring.cpp PIString::lengthAscii
* \sa \a data() */
int lengthAscii() const;
int lengthAscii() const {buildData(); return data_.size_s() - 1;}
/*! \brief Return \c char * representation of this string
* \details This function fill buffer by sequence
@@ -464,7 +465,7 @@ public:
* execution of this function.\n
* Example: \snippet pistring.cpp PIString::data
* \sa \a lengthAscii() */
const char * data() const;
const char * data() const {buildData(); return (const char *)(data_.data());}
//! \brief Return \c std::string representation of this string
std::string stdString() const {return convertToStd();}
@@ -473,8 +474,8 @@ public:
wstring stdWString() const {return convertToWString();}
#endif
//! \brief Return \a PIByteArray contains \a data() of this string
PIByteArray toByteArray() const {const char * d = data(); return PIByteArray(d, lengthAscii());}
//! \brief Return \a PIByteArray contains \a data() of this string without terminating null-char
PIByteArray toByteArray() const {buildData(); return data_.resized(data_.size_s() - 1);}
/*! \brief Split string with delimiter "delim" to \a PIStringList and return it
* \details Example: \snippet pistring.cpp PIString::split */
@@ -779,6 +780,7 @@ private:
return ret;
}
void appendFromChars(const char * c, int s);
void buildData() const;
std::string convertToStd() const;
#ifdef HAS_LOCALE
wstring convertToWString() const {wstring s; for (int i = 0; i < length(); ++i) s.push_back(at(i).toWChar()); return s;}
@@ -802,10 +804,10 @@ inline PICout operator <<(PICout s, const PIString & v) {s.space(); s.quote(); s
//! \relatesalso PIString \relatesalso PIByteArray \brief Output operator to PIByteArray
inline PIByteArray & operator <<(PIByteArray & s, const PIString & v) {int l = v.lengthAscii(); s << l; if (l <= 0) return s; int os = s.size_s(); s.enlarge(l); memcpy(s.data(os), v.data(), l); return s;}
inline PIByteArray & operator <<(PIByteArray & s, const PIString & v) {s << v.toByteArray(); return s;}
//! \relatesalso PIString \relatesalso PIByteArray \brief Input operator from PIByteArray
inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {if (s.size() < 4) {v.clear(); return s;} int l; s >> l; if (l <= 0) return s; v = PIString((const char * )s.data(), l); s.remove(0, l); return s;}
inline PIByteArray & operator >>(PIByteArray & s, PIString & v) {PIByteArray sc; s >> sc; v.clear(); v.appendFromChars((const char *)sc.data(), sc.size_s()); return s;}
//! \relatesalso PIString \brief Return concatenated string