summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-10-02 13:06:20 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-10-04 19:15:22 -0400
commit2c96a2887360f3b152b369a745440d4b503aa70d (patch)
treeb84fc339e9e77c8ac2fdd43b194b4fdb49648365 /svl
parentb3674c9291a09c4e278a0875b691fc7aaf3f38cd (diff)
Correct way to get case-insensitive string identifiers.
Change-Id: Ia343165941231fab34c4904b7a2fa10b07fa32bb
Diffstat (limited to 'svl')
-rw-r--r--svl/qa/unit/svl.cxx4
-rw-r--r--svl/source/misc/stringpool.cxx16
2 files changed, 15 insertions, 5 deletions
diff --git a/svl/qa/unit/svl.cxx b/svl/qa/unit/svl.cxx
index 003a1523b163..58882bb734c2 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 c0030fefa2cd..76dc4aaf34e2 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