From fe5c4098e5f2913c0e91eda04170ee7299c354bd Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Sun, 21 Apr 2013 14:10:04 -0500 Subject: [PATCH 1/2] more indentation fixes --- Zip/include/Poco/Zip/ZipArchive.h | 2 +- Zip/src/ZipArchive.cpp | 6 +++--- Zip/src/ZipArchiveInfo.cpp | 4 ++-- Zip/testsuite/src/CompressTest.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Zip/include/Poco/Zip/ZipArchive.h b/Zip/include/Poco/Zip/ZipArchive.h index d2a5a4565..7a134c6da 100644 --- a/Zip/include/Poco/Zip/ZipArchive.h +++ b/Zip/include/Poco/Zip/ZipArchive.h @@ -83,7 +83,7 @@ public: FileHeaders::const_iterator headerEnd() const; - const std::string& getZipComment() const; + const std::string& getZipComment() const; private: void parse(std::istream& in, ParseCallback& pc); diff --git a/Zip/src/ZipArchive.cpp b/Zip/src/ZipArchive.cpp index 4338e8942..0dda2d17e 100644 --- a/Zip/src/ZipArchive.cpp +++ b/Zip/src/ZipArchive.cpp @@ -120,9 +120,9 @@ void ZipArchive::parse(std::istream& in, ParseCallback& pc) const std::string& ZipArchive::getZipComment() const { - // It seems that only the "first" disk is populated (look at Compress::close()), so getting the first ZipArchiveInfo - DirectoryInfos::const_iterator it = _disks.begin(); - return it->second.getZipComment(); + // It seems that only the "first" disk is populated (look at Compress::close()), so getting the first ZipArchiveInfo + DirectoryInfos::const_iterator it = _disks.begin(); + return it->second.getZipComment(); } diff --git a/Zip/src/ZipArchiveInfo.cpp b/Zip/src/ZipArchiveInfo.cpp index 9811ec59e..73f851f18 100644 --- a/Zip/src/ZipArchiveInfo.cpp +++ b/Zip/src/ZipArchiveInfo.cpp @@ -105,7 +105,7 @@ std::string ZipArchiveInfo::createHeader() const void ZipArchiveInfo::setZipComment(const std::string& comment) -{ +{ // Confirm string is of valid size if (comment.size() > 65535) throw ZipException("Maximum number of entries for a ZIP file reached: 65535"); @@ -113,7 +113,7 @@ void ZipArchiveInfo::setZipComment(const std::string& comment) // Change the value of the ZIP Comment Size to reflect new comment size ZipUtil::set16BitValue(static_cast(comment.size()), _rawInfo, ZIPCOMMENT_LENGTH_POS); - // Now change our internal comment + // Now change our internal comment _comment = comment; } diff --git a/Zip/testsuite/src/CompressTest.h b/Zip/testsuite/src/CompressTest.h index 98bcf361e..b170c6988 100644 --- a/Zip/testsuite/src/CompressTest.h +++ b/Zip/testsuite/src/CompressTest.h @@ -51,7 +51,7 @@ public: void testManipulator(); void testManipulatorDel(); void testManipulatorReplace(); - void testSetZipComment(); + void testSetZipComment(); void setUp(); void tearDown(); From 225401743fcc6cd2e5616731a4843d74e1e1fcff Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Sun, 21 Apr 2013 21:38:55 -0500 Subject: [PATCH 2/2] case-insensitivity for SessionPool --- Data/ODBC/src/Unicode_WIN32.cpp | 4 +- .../ODBC/testsuite/src/ODBCPostgreSQLTest.cpp | 20 +++++----- Data/include/Poco/Data/SessionFactory.h | 10 +---- Data/include/Poco/Data/SessionPoolContainer.h | 4 +- Data/src/SessionPoolContainer.cpp | 14 +++---- Data/testsuite/src/SessionPoolTest.cpp | 14 +++++-- Foundation/include/Poco/String.h | 21 +++++++++-- Foundation/src/TextEncoding.cpp | 10 +---- Foundation/testsuite/src/StringTest.cpp | 37 +++++++++++++++++++ Foundation/testsuite/src/StringTest.h | 1 + Foundation/testsuite/src/TextEncodingTest.cpp | 5 +++ 11 files changed, 96 insertions(+), 44 deletions(-) diff --git a/Data/ODBC/src/Unicode_WIN32.cpp b/Data/ODBC/src/Unicode_WIN32.cpp index 2513e7e16..ac075d21f 100644 --- a/Data/ODBC/src/Unicode_WIN32.cpp +++ b/Data/ODBC/src/Unicode_WIN32.cpp @@ -35,6 +35,7 @@ #include "Poco/Data/ODBC/ODBC.h" +#include "Poco/Data/ODBC/Utility.h" #include "Poco/Data/ODBC/Unicode_WIN32.h" #include "Poco/Buffer.h" #include "Poco/Exception.h" @@ -612,7 +613,8 @@ SQLRETURN SQLDriverConnect(SQLHDBC hdbc, pcbConnStrOut, fDriverCompletion); - makeUTF8(bufOut, *pcbConnStrOut * sizeof(wchar_t), szConnStrOut, cbConnStrOutMax); + if (!Utility::isError(rc)) + makeUTF8(bufOut, *pcbConnStrOut * sizeof(wchar_t), szConnStrOut, cbConnStrOutMax); return rc; } diff --git a/Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp b/Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp index ddb247143..93c9b8b75 100644 --- a/Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp +++ b/Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp @@ -58,20 +58,22 @@ using Poco::DateTime; #ifdef POCO_ODBC_USE_MAMMOTH_NG #define POSTGRESQL_ODBC_DRIVER "Mammoth ODBCng Beta" #elif defined (POCO_ODBC_UNICODE) - #define POSTGRESQL_ODBC_DRIVER "PostgreSQL Unicode" + #define POSTGRESQL_ODBC_DRIVER "PostgreSQL ODBC Driver(UNICODE)" + #define POSTGRESQL_DSN "PocoDataPgSQLTestW" #else - #define POSTGRESQL_ODBC_DRIVER "PostgreSQL ANSI" + #define POSTGRESQL_ODBC_DRIVER "PostgreSQL ODBC Driver(ANSI)" + #define POSTGRESQL_DSN "PocoDataPgSQLTest" #endif -#define POSTGRESQL_DSN "PocoDataPgSQLTest" -#define POSTGRESQL_SERVER POCO_ODBC_TEST_DATABASE_SERVER -#define POSTGRESQL_PORT "5432" -#define POSTGRESQL_DB "postgres" -#define POSTGRESQL_UID "postgres" -#define POSTGRESQL_PWD "postgres" +#define POSTGRESQL_SERVER POCO_ODBC_TEST_DATABASE_SERVER +#define POSTGRESQL_PORT "5432" +#define POSTGRESQL_DB "postgres" +#define POSTGRESQL_UID "postgres" +#define POSTGRESQL_PWD "postgres" +#define POSTGRESQL_VERSION "9.2" #ifdef POCO_OS_FAMILY_WINDOWS -const std::string ODBCPostgreSQLTest::_libDir = "C:\\\\Program Files\\\\PostgreSQL\\\\8.2\\\\lib\\\\"; +const std::string ODBCPostgreSQLTest::_libDir = "C:\\\\Program Files\\\\PostgreSQL\\\\" POSTGRESQL_VERSION "\\\\lib\\\\"; #else const std::string ODBCPostgreSQLTest::_libDir = "/usr/local/pgsql/lib/"; #endif diff --git a/Data/include/Poco/Data/SessionFactory.h b/Data/include/Poco/Data/SessionFactory.h index 680ebe008..7865d679a 100644 --- a/Data/include/Poco/Data/SessionFactory.h +++ b/Data/include/Poco/Data/SessionFactory.h @@ -108,16 +108,8 @@ private: Poco::SharedPtr ptrSI; SessionInfo(Connector* pSI); }; - - struct ILT - { - bool operator() (const std::string& s1, const std::string& s2) const - { - return Poco::icompare(s1, s2) < 0; - } - }; - typedef std::map Connectors; + typedef std::map Connectors; Connectors _connectors; Poco::FastMutex _mutex; }; diff --git a/Data/include/Poco/Data/SessionPoolContainer.h b/Data/include/Poco/Data/SessionPoolContainer.h index 72fe7e83e..7aa689901 100644 --- a/Data/include/Poco/Data/SessionPoolContainer.h +++ b/Data/include/Poco/Data/SessionPoolContainer.h @@ -43,7 +43,7 @@ #include "Poco/Data/Data.h" #include "Poco/Data/Session.h" #include "Poco/Data/SessionPool.h" -#include "Poco/HashMap.h" +#include "Poco/String.h" #include "Poco/Mutex.h" @@ -92,7 +92,7 @@ public: /// Shuts down all the held pools. private: - typedef HashMap > SessionPoolMap; + typedef std::map, Poco::CILess> SessionPoolMap; SessionPoolContainer(const SessionPoolContainer&); SessionPoolContainer& operator = (const SessionPoolContainer&); diff --git a/Data/src/SessionPoolContainer.cpp b/Data/src/SessionPoolContainer.cpp index c85bb126d..ebebb40f9 100644 --- a/Data/src/SessionPoolContainer.cpp +++ b/Data/src/SessionPoolContainer.cpp @@ -69,7 +69,7 @@ void SessionPoolContainer::add(SessionPool* pPool) throw SessionPoolExistsException("Session pool already exists: " + pPool->name()); pPool->duplicate(); - _sessionPools.insert(SessionPoolMap::ValueType(pPool->name(), pPool)); + _sessionPools.insert(SessionPoolMap::value_type(pPool->name(), pPool)); } @@ -82,7 +82,7 @@ Session SessionPoolContainer::add(const std::string& sessionKey, std::string name = SessionPool::name(sessionKey, connectionString); FastMutex::ScopedLock lock(_mutex); - SessionPoolMap::Iterator it = _sessionPools.find(name); + SessionPoolMap::iterator it = _sessionPools.find(name); // pool already exists, silently return a session from it if (it != _sessionPools.end()) return it->second->get(); @@ -90,8 +90,8 @@ Session SessionPoolContainer::add(const std::string& sessionKey, SessionPool* pSP = new SessionPool(sessionKey, connectionString, minSessions, maxSessions, idleTime); - std::pair ins = - _sessionPools.insert(SessionPoolMap::ValueType(name, pSP)); + std::pair ins = + _sessionPools.insert(SessionPoolMap::value_type(name, pSP)); return ins.first->second->get(); } @@ -111,7 +111,7 @@ SessionPool& SessionPoolContainer::getPool(const std::string& name) std::string n = Session::uri(uri.getScheme(), path.substr(1)); FastMutex::ScopedLock lock(_mutex); - SessionPoolMap::Iterator it = _sessionPools.find(n); + SessionPoolMap::iterator it = _sessionPools.find(n); if (_sessionPools.end() == it) throw NotFoundException(n); return *it->second; } @@ -119,8 +119,8 @@ SessionPool& SessionPoolContainer::getPool(const std::string& name) void SessionPoolContainer::shutdown() { - SessionPoolMap::Iterator it = _sessionPools.begin(); - SessionPoolMap::Iterator end = _sessionPools.end(); + SessionPoolMap::iterator it = _sessionPools.begin(); + SessionPoolMap::iterator end = _sessionPools.end(); for (; it != end; ++it) it->second->shutdown(); } diff --git a/Data/testsuite/src/SessionPoolTest.cpp b/Data/testsuite/src/SessionPoolTest.cpp index 077384863..2b353c290 100644 --- a/Data/testsuite/src/SessionPoolTest.cpp +++ b/Data/testsuite/src/SessionPoolTest.cpp @@ -234,9 +234,15 @@ void SessionPoolTest::testSessionPool() void SessionPoolTest::testSessionPoolContainer() { SessionPoolContainer spc; - AutoPtr pPool = new SessionPool("test", "cs"); + AutoPtr pPool = new SessionPool("TeSt", "Cs"); spc.add(pPool); assert (1 == spc.count()); + + Poco::Data::Session sess = spc.get("test:///cs"); + assert ("test" == sess.impl()->connectorName()); + assert ("Cs" == sess.impl()->connectionString()); + assert ("test:///Cs" == sess.uri()); + try { spc.add(pPool); fail ("must fail"); } catch (SessionPoolExistsException&) { } spc.remove(pPool->name()); @@ -244,10 +250,10 @@ void SessionPoolTest::testSessionPoolContainer() try { spc.get("test"); fail ("must fail"); } catch (NotFoundException&) { } - spc.add("test", "cs"); - spc.add("test", "cs");//duplicate request, must be silently ignored + spc.add("tEsT", "cs"); + spc.add("TeSt", "cs");//duplicate request, must be silently ignored assert (1 == spc.count()); - spc.remove("test:///cs"); + spc.remove("TesT:///cs"); assert (0 == spc.count()); try { spc.get("test"); fail ("must fail"); } catch (NotFoundException&) { } diff --git a/Foundation/include/Poco/String.h b/Foundation/include/Poco/String.h index ace024aa6..420b2b761 100644 --- a/Foundation/include/Poco/String.h +++ b/Foundation/include/Poco/String.h @@ -652,17 +652,17 @@ S cat(const S& delim, const It& begin, const It& end) template struct i_char_traits : public std::char_traits { - static bool eq(charT c1, charT c2) + inline static bool eq(charT c1, charT c2) { return Ascii::toLower(c1) == Ascii::toLower(c2); } - static bool ne(charT c1, charT c2) + inline static bool ne(charT c1, charT c2) { return !eq(c1, c2); } - static bool lt(charT c1, charT c2) + inline static bool lt(charT c1, charT c2) { return Ascii::toLower(c1) < Ascii::toLower(c2); } @@ -688,10 +688,13 @@ struct i_char_traits : public std::char_traits typedef std::basic_string > istring; + /// Case-insensitive std::string counterpart. template std::size_t isubstr(const T& str, const T& sought) + /// Case-insensitive substring; searches for a substring + /// without regards to case. { typename T::const_iterator it = std::search(str.begin(), str.end(), sought.begin(), sought.end(), @@ -702,6 +705,18 @@ std::size_t isubstr(const T& str, const T& sought) } +struct CILess + /// Case-insensitive less-than functor; useful for standard maps + /// and sets with std::strings keys and case-insensitive ordering + /// requirement. +{ + inline bool operator() (const std::string& s1, const std::string& s2) const + { + return icompare(s1, s2) < 0; + } +}; + + } // namespace Poco diff --git a/Foundation/src/TextEncoding.cpp b/Foundation/src/TextEncoding.cpp index 195e12ea0..467b2dd98 100644 --- a/Foundation/src/TextEncoding.cpp +++ b/Foundation/src/TextEncoding.cpp @@ -123,15 +123,7 @@ private: TextEncodingManager(const TextEncodingManager&); TextEncodingManager& operator = (const TextEncodingManager&); - struct ILT - { - bool operator() (const std::string& s1, const std::string& s2) const - { - return Poco::icompare(s1, s2) < 0; - } - }; - - typedef std::map EncodingMap; + typedef std::map EncodingMap; EncodingMap _encodings; mutable RWLock _lock; diff --git a/Foundation/testsuite/src/StringTest.cpp b/Foundation/testsuite/src/StringTest.cpp index b53670764..d26808d78 100644 --- a/Foundation/testsuite/src/StringTest.cpp +++ b/Foundation/testsuite/src/StringTest.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include using Poco::trimLeft; @@ -73,6 +75,7 @@ using Poco::doubleToStr; using Poco::thousandSeparator; using Poco::decimalSeparator; using Poco::format; +using Poco::CILess; using Poco::MemoryInputStream; using Poco::Stopwatch; using Poco::RangeException; @@ -305,6 +308,39 @@ void StringTest::testIcompare() } +void StringTest::testCILessThan() +{ + typedef std::map CIMapType; + CIMapType ciMap; + + ciMap["z"] = 1; + ciMap["b"] = 2; + ciMap["A"] = 3; + ciMap["Z"] = 4; + + assert (ciMap.size() == 3); + CIMapType::iterator it = ciMap.begin(); + assert (it->first == "A"); ++it; + assert (it->first == "b"); ++it; + assert (it->first == "z"); + assert (it->second == 4); + + typedef std::set CISetType; + + CISetType ciSet; + ciSet.insert("z"); + ciSet.insert("b"); + ciSet.insert("A"); + ciSet.insert("Z"); + + assert (ciSet.size() == 3); + CISetType::iterator sIt = ciSet.begin(); + assert (*sIt == "A"); ++sIt; + assert (*sIt == "b"); ++sIt; + assert (*sIt == "z"); +} + + void StringTest::testTranslate() { std::string s = "aabbccdd"; @@ -1080,6 +1116,7 @@ CppUnit::Test* StringTest::suite() CppUnit_addTest(pSuite, StringTest, testToLower); CppUnit_addTest(pSuite, StringTest, testIstring); CppUnit_addTest(pSuite, StringTest, testIcompare); + CppUnit_addTest(pSuite, StringTest, testCILessThan); CppUnit_addTest(pSuite, StringTest, testTranslate); CppUnit_addTest(pSuite, StringTest, testTranslateInPlace); CppUnit_addTest(pSuite, StringTest, testReplace); diff --git a/Foundation/testsuite/src/StringTest.h b/Foundation/testsuite/src/StringTest.h index 5a0e7d26c..a47c5f590 100644 --- a/Foundation/testsuite/src/StringTest.h +++ b/Foundation/testsuite/src/StringTest.h @@ -58,6 +58,7 @@ public: void testToLower(); void testIstring(); void testIcompare(); + void testCILessThan(); void testTranslate(); void testTranslateInPlace(); void testReplace(); diff --git a/Foundation/testsuite/src/TextEncodingTest.cpp b/Foundation/testsuite/src/TextEncodingTest.cpp index a43e861a8..915d71ef4 100644 --- a/Foundation/testsuite/src/TextEncodingTest.cpp +++ b/Foundation/testsuite/src/TextEncodingTest.cpp @@ -40,6 +40,7 @@ #include "Poco/Windows1250Encoding.h" #include "Poco/Windows1251Encoding.h" #include "Poco/Windows1252Encoding.h" +#include "Poco/UTF8Encoding.h" using namespace Poco; @@ -105,6 +106,10 @@ void TextEncodingTest::testTextEncoding() TextEncoding::global(new Windows1252Encoding); TextEncoding& glob7 = TextEncoding::global(); assert (std::string("Windows-1252") == glob7.canonicalName()); + + TextEncoding::global(new UTF8Encoding); + TextEncoding& glob8 = TextEncoding::global(); + assert (std::string("UTF-8") == glob8.canonicalName()); }