diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-10-02 10:47:28 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-10-04 19:15:22 -0400 |
commit | 5d3ea0cde3f4c61832c48281e75dabd22621a893 (patch) | |
tree | 17cd79135e43b45467048ce26102729144b5642c /svl/source | |
parent | 279ae5116119b96b25fa56b53ecde4d61878cad7 (diff) |
Establish mapping between original strings and upper strings.
This will be used to retrieve case insensitive string identifiers
later.
Change-Id: Ia34f57d0e8d0cb6bd4630f8d110853ed049770b5
Diffstat (limited to 'svl/source')
-rw-r--r-- | svl/source/misc/stringpool.cxx | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/svl/source/misc/stringpool.cxx b/svl/source/misc/stringpool.cxx index f8ddda9b0acd..46462d1e7a59 100644 --- a/svl/source/misc/stringpool.cxx +++ b/svl/source/misc/stringpool.cxx @@ -8,26 +8,67 @@ */ #include "svl/stringpool.hxx" +#include "unotools/charclass.hxx" namespace svl { -StringPool::StringPool() {} +StringPool::StringPool() : mpCharClass(NULL) {} +StringPool::StringPool( CharClass* pCharClass ) : mpCharClass(pCharClass) {} rtl_uString* StringPool::intern( const OUString& rStr ) { + InsertResultType aRes = findOrInsert(maStrPool, rStr); + if (aRes.first == maStrPool.end()) + // Insertion failed. + return NULL; + + rtl_uString* pOrig = aRes.first->pData; + + if (!aRes.second) + // No new string has been inserted. Return the existing string in the pool. + return pOrig; + + if (!mpCharClass) + return pOrig; + + // This is a new string insertion. Establish mapping to upper-case variant. + + OUString aUpper = mpCharClass->uppercase(rStr); + aRes = findOrInsert(maStrPoolUpper, aUpper); + if (aRes.first == maStrPoolUpper.end()) + // Failed to insert or fetch upper-case variant. Should never happen. + return pOrig; + + // Set mapping. + rtl_uString* pUpper = aRes.first->pData; + maToUpperMap.insert(StrIdMapType::value_type(pOrig, pUpper)); + + return pOrig; +} + +const rtl_uString* StringPool::getIdentifier( const OUString& rStr ) const +{ StrHashType::iterator it = maStrPool.find(rStr); - if (it == maStrPool.end()) + return (it == maStrPool.end()) ? NULL : it->pData; +} + +StringPool::InsertResultType StringPool::findOrInsert( StrHashType& rPool, const OUString& rStr ) const +{ + StrHashType::iterator it = rPool.find(rStr); + bool bInserted = false; + if (it == rPool.end()) { // Not yet in the pool. - std::pair<StrHashType::iterator, bool> r = maStrPool.insert(rStr.intern()); + std::pair<StrHashType::iterator, bool> r = rPool.insert(rStr.intern()); if (!r.second) // Insertion failed. - return NULL; + return InsertResultType(rPool.end(), false); it = r.first; + bInserted = true; } - return it->pData; + return InsertResultType(it, bInserted); } } |