diff --git a/main.cpp b/main.cpp index 6d58101d..d312c5e3 100644 --- a/main.cpp +++ b/main.cpp @@ -31,12 +31,6 @@ public: }; int main (int argc, char * argv[]) { - PIFile::setDefaultCharset("utf8"); - piCout << PIFile::defaultCharset(); - PIFile::setDefaultCharset("cp1251"); - piCout << PIFile::defaultCharset(); - return 0; - VC<30, double> x(1.5), y(3.3); double r = 0.0; PITimeMeasurer tm; diff --git a/src/core/pistring.cpp b/src/core/pistring.cpp index 5b507deb..ca772ad4 100755 --- a/src/core/pistring.cpp +++ b/src/core/pistring.cpp @@ -193,6 +193,19 @@ PIString PIString::fromAscii(const char * s) { } +PIString PIString::fromCodepage(const char * s, const char * c) { + int l = 0; + while (s[l] != '\0') ++l; + PIString ret; + if (l > 0) ret.appendFromChars(s, l +#ifdef PIP_ICU + , c +#endif + ); + return ret; +} + + void PIString::buildData(const char * cp) const { data_.clear(); #ifdef PIP_ICU diff --git a/src/core/pistring.h b/src/core/pistring.h index 0b6735b3..eadf9a33 100755 --- a/src/core/pistring.h +++ b/src/core/pistring.h @@ -731,7 +731,10 @@ public: //! \brief Return string constructed from ASCII static PIString fromAscii(const char * s); - + + //! \brief Return string constructed from "c" codepage + static PIString fromCodepage(const char * s, const char * c); + //! \brief Return string contains human readable size in B/kB/MB/GB/TB //! \details Example: \snippet pistring.cpp PIString::readableSize static PIString readableSize(llong bytes) {PIString s; s.setReadableSize(bytes); return s;} diff --git a/src/io/pifile.cpp b/src/io/pifile.cpp index 6a54f7df..7844a918 100755 --- a/src/io/pifile.cpp +++ b/src/io/pifile.cpp @@ -180,7 +180,7 @@ bool PIFile::closeDevice() { PIString PIFile::readLine() { - PIString str; + PIByteArray str; if (!opened_) return str; int cc; while (!isEnd()) { @@ -188,8 +188,12 @@ PIString PIFile::readLine() { if (char(cc) == '\n' || cc == EOF) break; str.push_back(char(cc)); } + str.push_back('\0'); + if (defaultCharset()) { + return PIString::fromCodepage((const char *)str.data(), defaultCharset()); + } //cout << "readline: " << str << endl; - return str; + return PIString(str); }