diff --git a/src/core/pistring.cpp b/src/core/pistring.cpp index ca772ad4..58cdb9a8 100755 --- a/src/core/pistring.cpp +++ b/src/core/pistring.cpp @@ -294,6 +294,17 @@ PIByteArray PIString::toUTF8() const { } +PIByteArray PIString::toCharset(const char * c) const { + buildData( +#ifdef PIP_ICU + c +#endif + ); + return data_.resized(data_.size_s() - 1); + +} + + PIString & PIString::operator +=(const char * str) { int l = 0; while (str[l] != '\0') ++l; diff --git a/src/core/pistring.h b/src/core/pistring.h index eadf9a33..172f953d 100755 --- a/src/core/pistring.h +++ b/src/core/pistring.h @@ -505,6 +505,9 @@ public: //! \brief Return \a PIByteArray contains UTF-8 \a data() of this string without terminating null-char PIByteArray toUTF8() const; + //! \brief Return \a PIByteArray contains custom charset representation of this string without terminating null-char + PIByteArray toCharset(const char * c) const; + /*! \brief Split string with delimiter "delim" to \a PIStringList and return it * \details Example: \snippet pistring.cpp PIString::split */ PIStringList split(const PIString & delim) const; diff --git a/src/io/pifile.cpp b/src/io/pifile.cpp index 81a1a02b..857c4ad8 100755 --- a/src/io/pifile.cpp +++ b/src/io/pifile.cpp @@ -382,6 +382,13 @@ PIFile & PIFile::writeToBinLog(ushort id, const void * data, int size) { } +PIFile &PIFile::operator <<(const PIString & v) { + if (canWrite() && fd != 0) + *this << v.toCharset(defaultCharset()); + return *this; +} + + void PIFile::clear() { close(); fd = fopen(path().data(), "w"); diff --git a/src/io/pifile.h b/src/io/pifile.h index a52617c1..573ee1b5 100755 --- a/src/io/pifile.h +++ b/src/io/pifile.h @@ -188,7 +188,7 @@ public: PIFile & operator <<(const char v) {if (canWrite() && fd != 0) write(&v, 1); return *this;} //PIFile & operator <<(const string & v) {write(v.c_str(), v.size()); return *this;} //! Write to file string "v" - PIFile & operator <<(const PIString & v) {if (canWrite() && fd != 0) *this << v.toByteArray(); return *this;} + PIFile & operator <<(const PIString & v); //! Write to file text representation of "v" PIFile & operator <<(const PIByteArray & v) {if (canWrite() && fd != 0) write(v.data(), v.size()); return *this;} //! Write to file text representation of "v"