diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2016-02-23 19:41:53 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-04-01 07:33:32 +0000 |
commit | 46b4634de93bdda2a8427c6c545dc6160d5201d0 (patch) | |
tree | 4c6245229f65d9a96bbc7f098767b392e86629ae /linguistic/source | |
parent | 9f6e6fabcd5718e0b65437c5ce398e520f47aae1 (diff) |
sequence->vector in linguistic
Change-Id: I28ed0b4bb2a140493fca693807011b91b3569986
Reviewed-on: https://gerrit.libreoffice.org/23695
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'linguistic/source')
-rw-r--r-- | linguistic/source/convdiclist.cxx | 57 | ||||
-rw-r--r-- | linguistic/source/dicimp.cxx | 87 | ||||
-rw-r--r-- | linguistic/source/dicimp.hxx | 5 | ||||
-rw-r--r-- | linguistic/source/dlistimp.cxx | 21 | ||||
-rw-r--r-- | linguistic/source/lngsvcmgr.cxx | 2 | ||||
-rw-r--r-- | linguistic/source/misc2.cxx | 21 | ||||
-rw-r--r-- | linguistic/source/spelldsp.cxx | 22 | ||||
-rw-r--r-- | linguistic/source/spelldta.cxx | 55 |
8 files changed, 100 insertions, 170 deletions
diff --git a/linguistic/source/convdiclist.cxx b/linguistic/source/convdiclist.cxx index a977062bce83..de7160f10a41 100644 --- a/linguistic/source/convdiclist.cxx +++ b/linguistic/source/convdiclist.cxx @@ -31,6 +31,7 @@ #include <cppuhelper/factory.hxx> #include <cppuhelper/implbase.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <cppuhelper/supportsservice.hxx> #include <rtl/instance.hxx> #include <tools/stream.hxx> @@ -79,7 +80,7 @@ class ConvDicNameContainer : public cppu::WeakImplHelper< css::container::XNameContainer >, private boost::noncopyable { - uno::Sequence< uno::Reference< XConversionDictionary > > aConvDics; + std::vector< uno::Reference< XConversionDictionary > > aConvDics; sal_Int32 GetIndexByName_Impl( const OUString& rName ); @@ -110,12 +111,12 @@ public: // calls Flush for the dictionaries that support XFlushable void FlushDics() const; - sal_Int32 GetCount() const { return aConvDics.getLength(); } + sal_Int32 GetCount() const { return aConvDics.size(); } uno::Reference< XConversionDictionary > GetByName( const OUString& rName ); - const uno::Reference< XConversionDictionary > GetByIndex( sal_Int32 nIdx ) + const uno::Reference< XConversionDictionary >& GetByIndex( sal_Int32 nIdx ) { - return aConvDics.getConstArray()[nIdx]; + return aConvDics[nIdx]; } }; @@ -129,11 +130,10 @@ ConvDicNameContainer::~ConvDicNameContainer() void ConvDicNameContainer::FlushDics() const { - sal_Int32 nLen = aConvDics.getLength(); - const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray(); + sal_Int32 nLen = aConvDics.size(); for (sal_Int32 i = 0; i < nLen; ++i) { - uno::Reference< util::XFlushable > xFlush( pDic[i] , UNO_QUERY ); + uno::Reference< util::XFlushable > xFlush( aConvDics[i] , UNO_QUERY ); if (xFlush.is()) { try @@ -152,11 +152,10 @@ sal_Int32 ConvDicNameContainer::GetIndexByName_Impl( const OUString& rName ) { sal_Int32 nRes = -1; - sal_Int32 nLen = aConvDics.getLength(); - const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray(); + sal_Int32 nLen = aConvDics.size(); for (sal_Int32 i = 0; i < nLen && nRes == -1; ++i) { - if (rName == pDic[i]->getName()) + if (rName == aConvDics[i]->getName()) nRes = i; } return nRes; @@ -168,7 +167,7 @@ uno::Reference< XConversionDictionary > ConvDicNameContainer::GetByName( uno::Reference< XConversionDictionary > xRes; sal_Int32 nIdx = GetIndexByName_Impl( rName ); if ( nIdx != -1) - xRes = aConvDics.getArray()[nIdx]; + xRes = aConvDics[nIdx]; return xRes; } @@ -183,7 +182,7 @@ sal_Bool SAL_CALL ConvDicNameContainer::hasElements( ) throw (RuntimeException, std::exception) { MutexGuard aGuard( GetLinguMutex() ); - return aConvDics.getLength() > 0; + return !aConvDics.empty(); } uno::Any SAL_CALL ConvDicNameContainer::getByName( const OUString& rName ) @@ -201,12 +200,11 @@ uno::Sequence< OUString > SAL_CALL ConvDicNameContainer::getElementNames( ) { MutexGuard aGuard( GetLinguMutex() ); - sal_Int32 nLen = aConvDics.getLength(); + sal_Int32 nLen = aConvDics.size(); uno::Sequence< OUString > aRes( nLen ); OUString *pName = aRes.getArray(); - const uno::Reference< XConversionDictionary > *pDic = aConvDics.getConstArray(); for (sal_Int32 i = 0; i < nLen; ++i) - pName[i] = pDic[i]->getName(); + pName[i] = aConvDics[i]->getName(); return aRes; } @@ -231,7 +229,7 @@ void SAL_CALL ConvDicNameContainer::replaceByName( rElement >>= xNew; if (!xNew.is() || xNew->getName() != rName) throw IllegalArgumentException(); - aConvDics.getArray()[ nRplcIdx ] = xNew; + aConvDics[ nRplcIdx ] = xNew; } void SAL_CALL ConvDicNameContainer::insertByName( @@ -248,9 +246,7 @@ void SAL_CALL ConvDicNameContainer::insertByName( if (!xNew.is() || xNew->getName() != rName) throw IllegalArgumentException(); - sal_Int32 nLen = aConvDics.getLength(); - aConvDics.realloc( nLen + 1 ); - aConvDics.getArray()[ nLen ] = xNew; + aConvDics.push_back(xNew); } void SAL_CALL ConvDicNameContainer::removeByName( const OUString& rName ) @@ -263,7 +259,7 @@ void SAL_CALL ConvDicNameContainer::removeByName( const OUString& rName ) throw NoSuchElementException(); // physically remove dictionary - uno::Reference< XConversionDictionary > xDel = aConvDics.getArray()[nRplcIdx]; + uno::Reference< XConversionDictionary > xDel = aConvDics[nRplcIdx]; OUString aName( xDel->getName() ); OUString aDicMainURL( GetConvDicMainURL( aName, GetDictionaryWriteablePath() ) ); INetURLObject aObj( aDicMainURL ); @@ -287,11 +283,7 @@ void SAL_CALL ConvDicNameContainer::removeByName( const OUString& rName ) } } - sal_Int32 nLen = aConvDics.getLength(); - uno::Reference< XConversionDictionary > *pDic = aConvDics.getArray(); - for (sal_Int32 i = nRplcIdx; i < nLen - 1; ++i) - pDic[i] = pDic[i + 1]; - aConvDics.realloc( nLen - 1 ); + aConvDics.erase(aConvDics.begin() + nRplcIdx); } void ConvDicNameContainer::AddConvDics( @@ -482,9 +474,7 @@ uno::Sequence< OUString > SAL_CALL ConvDicList::queryConversions( { MutexGuard aGuard( GetLinguMutex() ); - sal_Int32 nCount = 0; - uno::Sequence< OUString > aRes( 20 ); - OUString *pRes = aRes.getArray(); + std::vector< OUString > aRes; bool bSupported = false; sal_Int32 nLen = GetNameContainer().GetCount(); @@ -503,14 +493,8 @@ uno::Sequence< OUString > SAL_CALL ConvDicList::queryConversions( sal_Int32 nNewLen = aNewConv.getLength(); if (nNewLen > 0) { - if (nCount + nNewLen > aRes.getLength()) - { - aRes.realloc( nCount + nNewLen + 20 ); - pRes = aRes.getArray(); - } - const OUString *pNewConv = aNewConv.getConstArray(); for (sal_Int32 k = 0; k < nNewLen; ++k) - pRes[nCount++] = pNewConv[k]; + aRes.push_back(aNewConv[k]); } } } @@ -518,8 +502,7 @@ uno::Sequence< OUString > SAL_CALL ConvDicList::queryConversions( if (!bSupported) throw NoSupportException(); - aRes.realloc( nCount ); - return aRes; + return comphelper::containerToSequence(aRes); } sal_Int16 SAL_CALL ConvDicList::queryMaxCharCount( diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx index 51bce42697d9..c22894ce9518 100644 --- a/linguistic/source/dicimp.cxx +++ b/linguistic/source/dicimp.cxx @@ -29,6 +29,7 @@ #include <tools/urlobj.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/string.hxx> +#include <comphelper/sequence.hxx> #include <unotools/ucbstreamhelper.hxx> #include <com/sun/star/ucb/SimpleFileAccess.hpp> @@ -191,7 +192,6 @@ DictionaryNeo::DictionaryNeo(const OUString &rName, eDicType (eType), nLanguage (nLang) { - nCount = 0; nDicVersion = DIC_VERSION_DONTKNOW; bNeedEntries = true; bIsModified = bIsActive = false; @@ -274,7 +274,7 @@ sal_uLong DictionaryNeo::loadEntries(const OUString &rMainURL) rtl_TextEncoding eEnc = osl_getThreadTextEncoding(); if (nDicVersion >= DIC_VERSION_6) eEnc = RTL_TEXTENCODING_UTF8; - nCount = 0; + aEntries.clear(); if (DIC_VERSION_6 == nDicVersion || DIC_VERSION_5 == nDicVersion || @@ -470,10 +470,9 @@ sal_uLong DictionaryNeo::saveEntries(const OUString &rURL) pStream->WriteLine(OString("---")); if (0 != (nErr = pStream->GetError())) return nErr; - const uno::Reference< XDictionaryEntry > *pEntry = aEntries.getConstArray(); - for (sal_Int32 i = 0; i < nCount; i++) + for (size_t i = 0; i < aEntries.size(); i++) { - OString aOutStr = formatForSave(pEntry[i], eEnc); + OString aOutStr = formatForSave(aEntries[i], eEnc); pStream->WriteLine (aOutStr); if (0 != (nErr = pStream->GetError())) break; @@ -622,7 +621,6 @@ bool DictionaryNeo::seekEntry(const OUString &rWord, MutexGuard aGuard( GetLinguMutex() ); - const uno::Reference< XDictionaryEntry > *pEntry = aEntries.getConstArray(); sal_Int32 nUpperIdx = getCount(), nMidIdx, nLowerIdx = 0; @@ -632,9 +630,9 @@ bool DictionaryNeo::seekEntry(const OUString &rWord, while( nLowerIdx <= nUpperIdx ) { nMidIdx = (nLowerIdx + nUpperIdx) / 2; - DBG_ASSERT(pEntry[nMidIdx].is(), "lng : empty entry encountered"); + DBG_ASSERT(aEntries[nMidIdx].is(), "lng : empty entry encountered"); - int nCmp = - cmpDicEntry( pEntry[nMidIdx]->getDictionaryWord(), + int nCmp = - cmpDicEntry( aEntries[nMidIdx]->getDictionaryWord(), rWord, bSimilarOnly ); if(nCmp == 0) { @@ -660,13 +658,12 @@ bool DictionaryNeo::isSorted() { bool bRes = true; - const uno::Reference< XDictionaryEntry > *pEntry = aEntries.getConstArray(); sal_Int32 nEntries = getCount(); sal_Int32 i; for (i = 1; i < nEntries; i++) { - if (cmpDicEntry( pEntry[i-1]->getDictionaryWord(), - pEntry[i]->getDictionaryWord() ) > 0) + if (cmpDicEntry( aEntries[i-1]->getDictionaryWord(), + aEntries[i]->getDictionaryWord() ) > 0) { bRes = false; break; @@ -704,20 +701,10 @@ bool DictionaryNeo::addEntry_Impl(const uno::Reference< XDictionaryEntry >& xDic { DBG_ASSERT(!bNeedEntries, "lng : entries still not loaded"); - if (nCount >= aEntries.getLength()) - aEntries.realloc( std::max(2 * nCount, nCount + 32) ); - uno::Reference< XDictionaryEntry > *pEntry = aEntries.getArray(); - - // shift old entries right - sal_Int32 i; - for (i = nCount - 1; i >= nPos; i--) - pEntry[ i+1 ] = pEntry[ i ]; // insert new entry at specified position - pEntry[ nPos ] = xDicEntry; + aEntries.insert(aEntries.begin() + nPos, xDicEntry); SAL_WARN_IF(!isSorted(), "linguistic", "dictionary entries unsorted"); - nCount++; - bIsModified = true; bRes = true; @@ -770,15 +757,14 @@ void SAL_CALL DictionaryNeo::setActive( sal_Bool bActivate ) // remove entries from memory if dictionary is deactivated if (!bIsActive) { - bool bIsEmpty = nCount == 0; + bool bIsEmpty = aEntries.empty(); // save entries first if necessary if (bIsModified && hasLocation() && !isReadonly()) { store(); - aEntries.realloc( 0 ); - nCount = 0; + aEntries.clear(); bNeedEntries = !bIsEmpty; } DBG_ASSERT( !bIsModified || !hasLocation() || isReadonly(), @@ -803,7 +789,7 @@ sal_Int32 SAL_CALL DictionaryNeo::getCount( ) if (bNeedEntries) loadEntries( aMainURL ); - return nCount; + return (sal_Int32)aEntries.size(); } Locale SAL_CALL DictionaryNeo::getLocale( ) @@ -838,10 +824,9 @@ uno::Reference< XDictionaryEntry > SAL_CALL DictionaryNeo::getEntry( sal_Int32 nPos; bool bFound = seekEntry( aWord, &nPos, true ); - DBG_ASSERT( nCount <= aEntries.getLength(), "lng : wrong number of entries"); - DBG_ASSERT(!bFound || nPos < nCount, "lng : index out of range"); + DBG_ASSERT(!bFound || nPos < (sal_Int32)aEntries.size(), "lng : index out of range"); - return bFound ? aEntries.getConstArray()[ nPos ] + return bFound ? aEntries[ nPos ] : uno::Reference< XDictionaryEntry >(); } @@ -882,26 +867,6 @@ sal_Bool SAL_CALL return bRes; } -static void lcl_SequenceRemoveElementAt( - uno::Sequence< uno::Reference< XDictionaryEntry > >& rEntries, int nPos ) -{ - //TODO: helper for SequenceRemoveElementAt available? - if(nPos >= rEntries.getLength()) - return; - uno::Sequence< uno::Reference< XDictionaryEntry > > aTmp(rEntries.getLength() - 1); - uno::Reference< XDictionaryEntry > * pOrig = rEntries.getArray(); - uno::Reference< XDictionaryEntry > * pTemp = aTmp.getArray(); - int nOffset = 0; - for(int i = 0; i < aTmp.getLength(); i++) - { - if(nPos == i) - nOffset++; - pTemp[i] = pOrig[i + nOffset]; - } - - rEntries = aTmp; -} - sal_Bool SAL_CALL DictionaryNeo::remove( const OUString& aWord ) throw(RuntimeException, std::exception) { @@ -916,22 +881,18 @@ sal_Bool SAL_CALL DictionaryNeo::remove( const OUString& aWord ) sal_Int32 nPos; bool bFound = seekEntry( aWord, &nPos ); - DBG_ASSERT( nCount < aEntries.getLength(), - "lng : wrong number of entries"); - DBG_ASSERT(!bFound || nPos < nCount, "lng : index out of range"); + DBG_ASSERT(!bFound || nPos < (sal_Int32)aEntries.size(), "lng : index out of range"); // remove element if found if (bFound) { // entry to be removed uno::Reference< XDictionaryEntry > - xDicEntry( aEntries.getConstArray()[ nPos ] ); + xDicEntry( aEntries[ nPos ] ); DBG_ASSERT(xDicEntry.is(), "lng : dictionary entry is NULL"); - nCount--; + aEntries.erase(aEntries.begin() + nPos); - //! the following call reduces the length of the sequence by 1 also - lcl_SequenceRemoveElementAt( aEntries, nPos ); bRemoved = bIsModified = true; launchEvent( DictionaryEventFlags::DEL_ENTRY, xDicEntry ); @@ -948,7 +909,7 @@ sal_Bool SAL_CALL DictionaryNeo::isFull( ) if (bNeedEntries) loadEntries( aMainURL ); - return nCount >= DIC_MAX_ENTRIES; + return aEntries.size() >= DIC_MAX_ENTRIES; } uno::Sequence< uno::Reference< XDictionaryEntry > > @@ -959,10 +920,7 @@ uno::Sequence< uno::Reference< XDictionaryEntry > > if (bNeedEntries) loadEntries( aMainURL ); - //! return sequence with length equal to the number of dictionary entries - //! (internal used sequence may have additional unused elements.) - return uno::Sequence< uno::Reference< XDictionaryEntry > > - (aEntries.getConstArray(), nCount); + return comphelper::containerToSequence(aEntries); } @@ -971,12 +929,11 @@ void SAL_CALL DictionaryNeo::clear( ) { MutexGuard aGuard( GetLinguMutex() ); - if (!bIsReadonly && nCount) + if (!bIsReadonly && !aEntries.empty()) { - // release all references to old entries and provide space for new ones - aEntries = uno::Sequence< uno::Reference< XDictionaryEntry > > ( 32 ); + // release all references to old entries + aEntries.clear(); - nCount = 0; bNeedEntries = false; bIsModified = true; diff --git a/linguistic/source/dicimp.hxx b/linguistic/source/dicimp.hxx index 321a47bbcf28..e1bf14609d6d 100644 --- a/linguistic/source/dicimp.hxx +++ b/linguistic/source/dicimp.hxx @@ -43,13 +43,12 @@ class DictionaryNeo : > { - ::comphelper::OInterfaceContainerHelper2 aDicEvtListeners; - css::uno::Sequence< css::uno::Reference< css::linguistic2::XDictionaryEntry > > + ::comphelper::OInterfaceContainerHelper2 aDicEvtListeners; + std::vector< css::uno::Reference< css::linguistic2::XDictionaryEntry > > aEntries; OUString aDicName; OUString aMainURL; css::linguistic2::DictionaryType eDicType; - sal_Int16 nCount; sal_Int16 nLanguage; sal_Int16 nDicVersion; bool bNeedEntries; diff --git a/linguistic/source/dlistimp.cxx b/linguistic/source/dlistimp.cxx index 7aee242904ba..d648583ee62b 100644 --- a/linguistic/source/dlistimp.cxx +++ b/linguistic/source/dlistimp.cxx @@ -65,8 +65,8 @@ class DicEvtListenerHelper : XDictionaryEventListener > { - comphelper::OInterfaceContainerHelper2 aDicListEvtListeners; - uno::Sequence< DictionaryEvent > aCollectDicEvt; + comphelper::OInterfaceContainerHelper2 aDicListEvtListeners; + std::vector< DictionaryEvent > aCollectDicEvt; uno::Reference< XDictionaryList > xMyDicList; sal_Int16 nCondensedEvt; @@ -198,9 +198,7 @@ void SAL_CALL DicEvtListenerHelper::processDictionaryEvent( // update list of collected events if needs to be if (nNumVerboseListeners > 0) { - sal_Int32 nColEvts = aCollectDicEvt.getLength(); - aCollectDicEvt.realloc( nColEvts + 1 ); - aCollectDicEvt.getArray()[ nColEvts ] = rDicEvent; + aCollectDicEvt.push_back(rDicEvent); } if (nNumCollectEvtListeners == 0 && nCondensedEvt != 0) @@ -247,7 +245,7 @@ sal_Int16 DicEvtListenerHelper::FlushEvents() // build DictionaryListEvent to pass on to listeners uno::Sequence< DictionaryEvent > aDicEvents; if (nNumVerboseListeners > 0) - aDicEvents = aCollectDicEvt; + aDicEvents = comphelper::containerToSequence(aCollectDicEvt); DictionaryListEvent aEvent( xMyDicList, nCondensedEvt, aDicEvents ); // pass on event @@ -255,7 +253,7 @@ sal_Int16 DicEvtListenerHelper::FlushEvents() // clear "list" of events nCondensedEvt = 0; - aCollectDicEvt.realloc( 0 ); + aCollectDicEvt.clear(); } return nNumCollectEvtListeners; @@ -627,12 +625,11 @@ void DicList::_CreateDicList() // look for dictionaries const OUString aWriteablePath( GetDictionaryWriteablePath() ); - uno::Sequence< OUString > aPaths( GetDictionaryPaths() ); - const OUString *pPaths = aPaths.getConstArray(); - for (sal_Int32 i = 0; i < aPaths.getLength(); ++i) + std::vector< OUString > aPaths( GetDictionaryPaths() ); + for (size_t i = 0; i < aPaths.size(); ++i) { - const bool bIsWriteablePath = (pPaths[i] == aWriteablePath); - SearchForDictionaries( aDicList, pPaths[i], bIsWriteablePath ); + const bool bIsWriteablePath = (aPaths[i] == aWriteablePath); + SearchForDictionaries( aDicList, aPaths[i], bIsWriteablePath ); } // create IgnoreAllList dictionary with empty URL (non persistent) diff --git a/linguistic/source/lngsvcmgr.cxx b/linguistic/source/lngsvcmgr.cxx index 643c5a6cfb7c..d77a372a1cf1 100644 --- a/linguistic/source/lngsvcmgr.cxx +++ b/linguistic/source/lngsvcmgr.cxx @@ -1613,7 +1613,7 @@ uno::Sequence< lang::Locale > SAL_CALL } static bool IsEqSvcList( const uno::Sequence< OUString > &rList1, - const uno::Sequence< OUString > &rList2 ) + const uno::Sequence< OUString > &rList2 ) { // returns true iff both sequences are equal diff --git a/linguistic/source/misc2.cxx b/linguistic/source/misc2.cxx index c5f6a1f24ab2..bf99fdcb3c69 100644 --- a/linguistic/source/misc2.cxx +++ b/linguistic/source/misc2.cxx @@ -74,11 +74,11 @@ bool FileExists( const OUString &rMainURL ) return bExists; } -static uno::Sequence< OUString > GetMultiPaths_Impl( +static std::vector< OUString > GetMultiPaths_Impl( const OUString &rPathPrefix, DictionaryPathFlags nPathFlags ) { - uno::Sequence< OUString > aRes; + std::vector< OUString > aRes; uno::Sequence< OUString > aInternalPaths; uno::Sequence< OUString > aUserPaths; OUString aWritablePath; @@ -110,11 +110,10 @@ static uno::Sequence< OUString > GetMultiPaths_Impl( sal_Int32 nMaxEntries = aInternalPaths.getLength() + aUserPaths.getLength(); if (!aWritablePath.isEmpty()) ++nMaxEntries; - aRes.realloc( nMaxEntries ); - OUString *pRes = aRes.getArray(); + aRes.resize( nMaxEntries ); sal_Int32 nCount = 0; // number of actually added entries if ((nPathFlags & DictionaryPathFlags::WRITABLE) && !aWritablePath.isEmpty()) - pRes[ nCount++ ] = aWritablePath; + aRes[ nCount++ ] = aWritablePath; for (int i = 0; i < 2; ++i) { const uno::Sequence< OUString > &rPathSeq = i == 0 ? aUserPaths : aInternalPaths; @@ -124,10 +123,10 @@ static uno::Sequence< OUString > GetMultiPaths_Impl( const bool bAddUser = &rPathSeq == &aUserPaths && (nPathFlags & DictionaryPathFlags::USER); const bool bAddInternal = &rPathSeq == &aInternalPaths && (nPathFlags & DictionaryPathFlags::INTERNAL); if ((bAddUser || bAddInternal) && !pPathSeq[k].isEmpty()) - pRes[ nCount++ ] = pPathSeq[k]; + aRes[ nCount++ ] = pPathSeq[k]; } } - aRes.realloc( nCount ); + aRes.resize( nCount ); } return aRes; @@ -135,15 +134,15 @@ static uno::Sequence< OUString > GetMultiPaths_Impl( OUString GetDictionaryWriteablePath() { - uno::Sequence< OUString > aPaths( GetMultiPaths_Impl( "Dictionary", DictionaryPathFlags::WRITABLE ) ); - DBG_ASSERT( aPaths.getLength() == 1, "Dictionary_writable path corrupted?" ); + std::vector< OUString > aPaths( GetMultiPaths_Impl( "Dictionary", DictionaryPathFlags::WRITABLE ) ); + DBG_ASSERT( aPaths.size() == 1, "Dictionary_writable path corrupted?" ); OUString aRes; - if (aPaths.getLength() > 0) + if (aPaths.size() > 0) aRes = aPaths[0]; return aRes; } -uno::Sequence< OUString > GetDictionaryPaths() +std::vector< OUString > GetDictionaryPaths() { return GetMultiPaths_Impl( "Dictionary", PATH_FLAG_ALL ); } diff --git a/linguistic/source/spelldsp.cxx b/linguistic/source/spelldsp.cxx index 26010a1e8406..e1d86ba74ac9 100644 --- a/linguistic/source/spelldsp.cxx +++ b/linguistic/source/spelldsp.cxx @@ -28,6 +28,7 @@ #include <cppuhelper/factory.hxx> #include <unotools/localedatawrapper.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/sequence.hxx> #include <tools/debug.hxx> #include <svl/lngmisc.hxx> #include <osl/mutex.hxx> @@ -49,7 +50,7 @@ using namespace linguistic; // ProposalList: list of proposals for misspelled words -// The order of strings in the array should be left unchanged because the +// The order of strings in the array should be left unchanged because the // spellchecker should have put the more likely suggestions at the top. // New entries will be added to the end but duplicates are to be avoided. // Removing entries is done by assigning the empty string. @@ -69,7 +70,7 @@ public: void Append( const OUString &rNew ); void Append( const std::vector< OUString > &rNew ); void Append( const Sequence< OUString > &rNew ); - Sequence< OUString > GetSequence() const; + std::vector< OUString > GetVector() const; }; @@ -134,19 +135,18 @@ size_t ProposalList::Count() const return nRes; } -Sequence< OUString > ProposalList::GetSequence() const +std::vector< OUString > ProposalList::GetVector() const { sal_Int32 nCount = Count(); sal_Int32 nIdx = 0; - Sequence< OUString > aRes( nCount ); - OUString *pRes = aRes.getArray(); + std::vector< OUString > aRes( nCount ); sal_Int32 nLen = aVec.size(); for (sal_Int32 i = 0; i < nLen; ++i) { const OUString &rText = aVec[i]; - DBG_ASSERT( nIdx < nCount, "index our of range" ); + DBG_ASSERT( nIdx < nCount, "index out of range" ); if (nIdx < nCount && !rText.isEmpty()) - pRes[ nIdx++ ] = rText; + aRes[ nIdx++ ] = rText; } return aRes; } @@ -715,7 +715,7 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl( std::vector< OUString > aDicListProps; // list of proposals from user-dictionaries SearchSimilarText( aChkWord, nLanguage, xDList, aDicListProps ); aProposalList.Append( aDicListProps ); - Sequence< OUString > aProposals = aProposalList.GetSequence(); + std::vector< OUString > aProposals = aProposalList.GetVector(); // remove entries listed in negative dictionaries // (we don't want to display suggestions that will be regarded as misspelled later on) @@ -725,7 +725,7 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl( uno::Reference< linguistic2::XSetSpellAlternatives > xSetAlt( xRes, uno::UNO_QUERY ); if (xSetAlt.is()) { - xSetAlt->setAlternatives( aProposals ); + xSetAlt->setAlternatives( comphelper::containerToSequence(aProposals) ); xSetAlt->setFailureType( eFailureType ); } else @@ -734,12 +734,12 @@ Reference< XSpellAlternatives > SpellCheckerDispatcher::spell_Impl( { DBG_ASSERT( false, "XSetSpellAlternatives not implemented!" ); } - else if (aProposals.getLength() > 0) + else if (!aProposals.empty()) { // no xRes but Proposals found from the user-dictionaries. // Thus we need to create an xRes... xRes = new linguistic::SpellAlternatives( rWord, nLanguage, - SpellFailure::IS_NEGATIVE_WORD, aProposals ); + SpellFailure::IS_NEGATIVE_WORD, comphelper::containerToSequence(aProposals) ); } } } diff --git a/linguistic/source/spelldta.cxx b/linguistic/source/spelldta.cxx index 001fbe9ece69..6a0a93891581 100644 --- a/linguistic/source/spelldta.cxx +++ b/linguistic/source/spelldta.cxx @@ -46,15 +46,14 @@ namespace linguistic #define MAX_PROPOSALS 40 bool SeqHasEntry( - const Sequence< OUString > &rSeq, + const std::vector< OUString > &rSeq, const OUString &rTxt) { bool bRes = false; - sal_Int32 nLen = rSeq.getLength(); - const OUString *pEntry = rSeq.getConstArray(); - for (sal_Int32 i = 0; i < nLen && !bRes; ++i) + sal_Int32 nLen = rSeq.size(); + for (sal_Int32 i = 0; i < nLen && !bRes; ++i) { - if (rTxt == pEntry[i]) + if (rTxt == rSeq[i]) bRes = true; } return bRes; @@ -107,26 +106,25 @@ void SearchSimilarText( const OUString &rText, sal_Int16 nLanguage, } -void SeqRemoveNegEntries( Sequence< OUString > &rSeq, +void SeqRemoveNegEntries( std::vector< OUString > &rSeq, Reference< XSearchableDictionaryList > &rxDicList, sal_Int16 nLanguage ) { bool bSthRemoved = false; - sal_Int32 nLen = rSeq.getLength(); - OUString *pEntries = rSeq.getArray(); + sal_Int32 nLen = rSeq.size(); for (sal_Int32 i = 0; i < nLen; ++i) { Reference< XDictionaryEntry > xNegEntry( SearchDicList( rxDicList, - pEntries[i], nLanguage, false, true ) ); + rSeq[i], nLanguage, false, true ) ); if (xNegEntry.is()) { - pEntries[i].clear(); + rSeq[i].clear(); bSthRemoved = true; } } if (bSthRemoved) { - Sequence< OUString > aNew; + std::vector< OUString > aNew; // merge sequence without duplicates and empty strings in new empty sequence aNew = MergeProposalSeqs( aNew, rSeq, false ); rSeq = aNew; @@ -134,42 +132,39 @@ void SeqRemoveNegEntries( Sequence< OUString > &rSeq, } -Sequence< OUString > MergeProposalSeqs( - Sequence< OUString > &rAlt1, - Sequence< OUString > &rAlt2, +std::vector< OUString > MergeProposalSeqs( + std::vector< OUString > &rAlt1, + std::vector< OUString > &rAlt2, bool bAllowDuplicates ) { - Sequence< OUString > aMerged; + std::vector< OUString > aMerged; - if (0 == rAlt1.getLength() && bAllowDuplicates) + if (rAlt1.empty() && bAllowDuplicates) aMerged = rAlt2; - else if (0 == rAlt2.getLength() && bAllowDuplicates) + else if (rAlt2.empty() && bAllowDuplicates) aMerged = rAlt1; else { - sal_Int32 nAltCount1 = rAlt1.getLength(); - const OUString *pAlt1 = rAlt1.getConstArray(); - sal_Int32 nAltCount2 = rAlt2.getLength(); - const OUString *pAlt2 = rAlt2.getConstArray(); + size_t nAltCount1 = rAlt1.size(); + size_t nAltCount2 = rAlt2.size(); - sal_Int32 nCountNew = std::min( nAltCount1 + nAltCount2, (sal_Int32) MAX_PROPOSALS ); - aMerged.realloc( nCountNew ); - OUString *pMerged = aMerged.getArray(); + sal_Int32 nCountNew = std::min<sal_Int32>( nAltCount1 + nAltCount2, (sal_Int32) MAX_PROPOSALS ); + aMerged.resize( nCountNew ); sal_Int32 nIndex = 0; sal_Int32 i = 0; for (int j = 0; j < 2; j++) { - sal_Int32 nCount = j == 0 ? nAltCount1 : nAltCount2; - const OUString *pAlt = j == 0 ? pAlt1 : pAlt2; + sal_Int32 nCount = j == 0 ? nAltCount1 : nAltCount2; + std::vector< OUString >& rAlt = j == 0 ? rAlt1 : rAlt2; for (i = 0; i < nCount && nIndex < MAX_PROPOSALS; i++) { - if (!pAlt[i].isEmpty() && - (bAllowDuplicates || !SeqHasEntry(aMerged, pAlt[i] ))) - pMerged[ nIndex++ ] = pAlt[ i ]; + if (!rAlt[i].isEmpty() && + (bAllowDuplicates || !SeqHasEntry(aMerged, rAlt[i] ))) + aMerged[ nIndex++ ] = rAlt[ i ]; } } - aMerged.realloc( nIndex ); + aMerged.resize( nIndex ); } return aMerged; |