From dbe80f4e8375aa018007581329d4d5f1a8e58996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 14 Apr 2015 20:17:20 +0000 Subject: [PATCH] PIChar ICU fixes git-svn-id: svn://db.shs.com.ru/pip@95 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/core/pichar.cpp | 56 +++++++++++++++++++++++++++++++--- src/core/pichar.h | 1 + src/io/pidir.cpp | 1 + src/io/pifiletransfer.cpp | 31 +++++++++++-------- utils/system_daemon/daemon.cpp | 3 +- 5 files changed, 74 insertions(+), 18 deletions(-) diff --git a/src/core/pichar.cpp b/src/core/pichar.cpp index f45350d2..11898137 100644 --- a/src/core/pichar.cpp +++ b/src/core/pichar.cpp @@ -110,27 +110,47 @@ PIChar PIChar::fromUTF8(const char * c) { bool PIChar::operator ==(const PIChar & o) const { - return strcmp(o.toCharPtr(), toCharPtr()) == 0; + return ch == o.ch; } bool PIChar::operator >(const PIChar & o) const { - return strcmp(o.toCharPtr(), toCharPtr()) < 0; + return +#ifdef PIP_ICU + u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) > 0; +#else + strcmp(toCharPtr(), o.toCharPtr()) > 0; +#endif } bool PIChar::operator <(const PIChar & o) const { - return strcmp(o.toCharPtr(), toCharPtr()) > 0; + return +#ifdef PIP_ICU + u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) < 0; +#else + strcmp(toCharPtr(), o.toCharPtr()) < 0; +#endif } bool PIChar::operator >=(const PIChar & o) const { - return strcmp(o.toCharPtr(), toCharPtr()) <= 0; + return +#ifdef PIP_ICU + u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) >= 0; +#else + strcmp(toCharPtr(), o.toCharPtr()) >= 0; +#endif } bool PIChar::operator <=(const PIChar & o) const { - return strcmp(o.toCharPtr(), toCharPtr()) >= 0; + return +#ifdef PIP_ICU + u_strCompare((const UChar*)&(ch), 1, (const UChar*)&(o.ch), 1, FALSE) <= 0; +#else + strcmp(toCharPtr(), o.toCharPtr()) <= 0; +#endif } @@ -217,12 +237,26 @@ char PIChar::toConcole1Byte() const { PIChar PIChar::toUpper() const { +#ifdef PIP_ICU + UChar c(0); + UErrorCode e((UErrorCode)0); + u_strToUpper(&c, 1, (const UChar*)(&ch), 1, 0, &e); + return PIChar(c); +#else return PIChar(toupper(ch)); +#endif } PIChar PIChar::toLower() const { +#ifdef PIP_ICU + UChar c(0); + UErrorCode e((UErrorCode)0); + u_strToLower(&c, 1, (const UChar*)(&ch), 1, 0, &e); + return PIChar(c); +#else return PIChar(tolower(ch)); +#endif } @@ -237,6 +271,18 @@ std::ostream & operator <<(std::ostream & s, const PIChar & v) { PICout operator <<(PICout s, const PIChar & v) { s.space(); s.setControl(0, true); +#ifdef PIP_ICU + UErrorCode e((UErrorCode)0); + UConverter * cc = ucnv_open(PICout::isBufferActive() ? __syslocname__ : __sysoemname__, &e); + if (cc) { + char uc[8]; + memset(uc, 0, 8); + e = (UErrorCode)0; + ucnv_fromUChars(cc, uc, 8, (const UChar*)(&v.ch), 1, &e); + ucnv_close(cc); + s << uc; + } else +#endif s << v.toCharPtr(); s.restoreControl(); return s; diff --git a/src/core/pichar.h b/src/core/pichar.h index bf0664a6..97b2c32f 100755 --- a/src/core/pichar.h +++ b/src/core/pichar.h @@ -35,6 +35,7 @@ class PIP_EXPORT PIChar friend class PIString; friend PIByteArray & operator <<(PIByteArray & s, const PIChar & v); friend PIByteArray & operator >>(PIByteArray & s, PIChar & v); + friend PICout operator <<(PICout s, const PIChar & v); public: //! Contructs ascii symbol PIChar(const char c) {ch = c; ch &= 0xFF;} diff --git a/src/io/pidir.cpp b/src/io/pidir.cpp index bd01265e..73c72940 100755 --- a/src/io/pidir.cpp +++ b/src/io/pidir.cpp @@ -149,6 +149,7 @@ PIDir & PIDir::cleanPath() { PIString PIDir::relative(const PIString & path) const { PIDir td(path); PIStringList dl(absolutePath().split(separator)), pl(td.absolutePath().split(separator)), rl; + //piCout << pl << "rel to" << dl; while (!dl.isEmpty() && !pl.isEmpty()) { if (dl.front() != pl.front()) break; dl.pop_front(); diff --git a/src/io/pifiletransfer.cpp b/src/io/pifiletransfer.cpp index 39df6224..03d8d31a 100644 --- a/src/io/pifiletransfer.cpp +++ b/src/io/pifiletransfer.cpp @@ -54,9 +54,12 @@ bool PIFileTransfer::send(PIVector entries) { PIVector fls = d.allEntries(); scanning = false; d.up(); - for (int j=0; j &files) { void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) { -// piCout << "processFile" << id << files_.size(); + //piCout << "processFile" << id << files_.size(); PFTFileInfo fi = files_[id-1]; bytes_file_all = fi.size; bytes_file_cur = start; cur_file_string = fi.dest_path; PIString path = dir.absolutePath() + dir.separator + fi.dest_path; -// piCout << "receive" << path << fi.size << data.size(); + //piCout << "receive" << path << fi.size << data.size(); if (fi.isDir()) { - // piCoutObj << "make dir" << fi.entry.path; + //piCoutObj << "make dir" << fi.entry.path; if (!PIDir::make(path)) { cur_file_string = "ERROR! while create directory " + path; piCoutObj << cur_file_string; @@ -119,7 +122,9 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) { } if (fi.isFile()) { if (work_file.path() != path || !work_file.isOpened()) { + //piCout << "file close"; work_file.close(); + //piCout << "new file" << path << work_file.path() << work_file.isOpened(); if (!work_file.open(path, PIIODevice::ReadWrite)) { cur_file_string = "ERROR! while open file " + path; piCoutObj << cur_file_string; @@ -128,17 +133,17 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) { } PIFile::applyFileInfo(path, fi); if (work_file.size() > fi.size) { - // piCoutObj << "error size" << work_file.size() << fi.size; + //piCoutObj << "error size" << work_file.size() << fi.size; work_file.clear(); work_file.resize(fi.size); - // piCoutObj << "correct size" << work_file.size() << fi.size; + //piCoutObj << "correct size" << work_file.size() << fi.size; } } - // piCoutObj << "write file" << path << work_file.path() << work_file.size() << fi.entry.size << work_file.pos() << fi.fstart << fi.fsize; + //piCoutObj << "write file" << path << work_file.path() << work_file.size() << fi.entry.size << work_file.pos() << fi.fstart << fi.fsize; if (work_file.size() < (llong)start) { - // piCoutObj << "error pos size" << work_file.pos() << fi.fstart; + //piCoutObj << "error pos size" << work_file.pos() << fi.fstart; work_file.resize(start); - // piCoutObj << "correct pos size" << work_file.pos() << fi.fstart; + //piCoutObj << "correct pos size" << work_file.pos() << fi.fstart; } if (work_file.size() > fi.size) { piCoutObj << "****** error size" << work_file.size() << fi.size; @@ -146,7 +151,7 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) { work_file.resize(fi.size); piCoutObj << "****** correct size" << work_file.size() << fi.size; } - // if (fi.fstart != work_file.pos()) piCoutObj << "error pos" << work_file.pos() << fi.fstart; + //if (fi.fstart != work_file.pos()) piCoutObj << "error pos" << work_file.pos() << fi.fstart; work_file.seek(start); int rs = work_file.write(data.data(), data.size()); if (rs != data.size_s()) { @@ -160,8 +165,8 @@ void PIFileTransfer::processFile(int id, ullong start, PIByteArray & data) { PIByteArray PIFileTransfer::buildPacket(Part p) { - // piCoutObj << "Step" << pftheader.step; - // piCoutObj << "session id" << pftheader.session_id; + //piCoutObj << "Step" << pftheader.step; + //piCoutObj << "session id" << pftheader.session_id; PIByteArray ba; switch(pftheader.step) { case pft_None: @@ -285,6 +290,7 @@ void PIFileTransfer::receive_finished(bool ok) { } else resume(); } if (pftheader.step == pft_Data) { + //piCout << "file close"; work_file.close(); started_ = false; receiveFilesFinished(ok); @@ -293,6 +299,7 @@ void PIFileTransfer::receive_finished(bool ok) { void PIFileTransfer::send_finished(bool ok) { + //piCout << "file close"; work_file.close(); started_ = false; } diff --git a/utils/system_daemon/daemon.cpp b/utils/system_daemon/daemon.cpp index ebc32666..b950a5fb 100644 --- a/utils/system_daemon/daemon.cpp +++ b/utils/system_daemon/daemon.cpp @@ -358,6 +358,7 @@ void Daemon::fmActionRequest(bool remote_tile, FileManager::Action type, PIVaria case FileManager::Copy: if (remote_tile) { PIByteArray ba; + //piCout << fm.selectedRemote(); ba << int(CopyFiles) << fm.selectedRemote(); r->ft.setDirectory(fm.localDir()); send(conn_name, ba); @@ -515,7 +516,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) { ba >> dir; r->dir_my.cd(dir); r->ft.setDirectory(r->dir_my); - piCout << "store to" << r->dir_my.absolutePath(); + //piCout << "store to" << r->dir_my.absolutePath(); piCout << "cd to" << dir << ", abs =" << r->dir_my.absolutePath(); sendDirToRemote(r); break;