[Libreoffice-commits] core.git: Branch 'private/kohei/calc-shared-string' - svl/qa svl/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed Oct 2 10:05:13 PDT 2013


 svl/qa/unit/svl.cxx            |    4 ++++
 svl/source/misc/stringpool.cxx |   16 +++++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

New commits:
commit 808c322d279ac815f6386643f3e00a6a817f2e96
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Oct 2 13:06:20 2013 -0400

    Correct way to get case-insensitive string identifiers.
    
    Change-Id: Ia343165941231fab34c4904b7a2fa10b07fa32bb

diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 003a152..58882bb 100644
--- a/svl/qa/unit/svl.cxx
+++ b/svl/qa/unit/svl.cxx
@@ -307,7 +307,11 @@ void Test::testStringPool()
     OUString aAndy("Andy");
     svl::StringPool::StrIdType si1 = aPool.getIdentifier("Andy");
     svl::StringPool::StrIdType si2 = aPool.getIdentifier(aAndy);
+    CPPUNIT_ASSERT_MESSAGE("Identifier shouldn't be 0.", si1);
+    CPPUNIT_ASSERT_MESSAGE("Identifier shouldn't be 0.", si2);
     CPPUNIT_ASSERT_EQUAL(si1, si2);
+    si1 = aPool.getIdentifierIgnoreCase(aAndy);
+    CPPUNIT_ASSERT_MESSAGE("Case insensitive identifier shouldn't be 0.", si1);
 
     // Test case insensitive string ID's.
     OUString aAndyLower("andy"), aAndyUpper("ANDY");
diff --git a/svl/source/misc/stringpool.cxx b/svl/source/misc/stringpool.cxx
index c0030fe..76dc4aa 100644
--- a/svl/source/misc/stringpool.cxx
+++ b/svl/source/misc/stringpool.cxx
@@ -48,18 +48,24 @@ rtl_uString* StringPool::intern( const OUString& rStr )
 
 StringPool::StrIdType StringPool::getIdentifier( const OUString& rStr ) const
 {
-    StrHashType::iterator it = maStrPool.find(rStr);
+    StrHashType::const_iterator it = maStrPool.find(rStr);
     return (it == maStrPool.end()) ? 0 : reinterpret_cast<StrIdType>(it->pData);
 }
 
 StringPool::StrIdType StringPool::getIdentifierIgnoreCase( const OUString& rStr ) const
 {
-    if (!mpCharClass)
+    StrHashType::const_iterator itOrig = maStrPool.find(rStr);
+    if (itOrig == maStrPool.end())
+        // Not in the pool.
         return 0;
 
-    OUString aUpper = mpCharClass->uppercase(rStr);
-    StrHashType::iterator it = maStrPoolUpper.find(aUpper);
-    return (it == maStrPool.end()) ? 0 : reinterpret_cast<StrIdType>(it->pData);
+    StrIdMapType::const_iterator itUpper = maToUpperMap.find(itOrig->pData);
+    if (itUpper == maToUpperMap.end())
+        // Passed string is not in the pool.
+        return 0;
+
+    const rtl_uString* pUpper = itUpper->second;
+    return reinterpret_cast<StrIdType>(pUpper);
 }
 
 StringPool::InsertResultType StringPool::findOrInsert( StrHashType& rPool, const OUString& rStr ) const


More information about the Libreoffice-commits mailing list