use more string_view in editeng

Change-Id: I7e434076750ebdf4aeee621151fbe6dfc929c60f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140337
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2022-09-21 18:29:54 +02:00
parent 318a7961fc
commit f41868a5dc
15 changed files with 96 additions and 94 deletions
+1 -1
View File
@@ -773,7 +773,7 @@ public:
EditPaM Clear();
EditPaM RemoveText();
void RemoveChars( EditPaM aPaM, sal_Int32 nChars );
EditPaM InsertText( EditPaM aPaM, const OUString& rStr );
EditPaM InsertText( EditPaM aPaM, std::u16string_view rStr );
EditPaM InsertParaBreak( EditPaM aPaM, bool bKeepEndingAttribs );
EditPaM InsertFeature( EditPaM aPaM, const SfxPoolItem& rItem );
EditPaM ConnectParagraphs( ContentNode* pLeft, ContentNode* pRight );
+24 -24
View File
@@ -44,69 +44,69 @@ void LookupTreeTest::testTrie()
editeng::Trie trie;
std::vector<OUString> suggestions;
trie.findSuggestions( OUString(), suggestions);
trie.findSuggestions( u"", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
trie.insert( OUString() );
trie.findSuggestions( OUString(), suggestions);
trie.insert( u"" );
trie.findSuggestions( u"", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
trie.findSuggestions( "a", suggestions);
trie.findSuggestions( u"a", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
trie.insert( "abc" );
trie.insert( "abcdefghijklmnopqrstuvwxyz" );
trie.findSuggestions( "a", suggestions);
trie.insert( u"abc" );
trie.insert( u"abcdefghijklmnopqrstuvwxyz" );
trie.findSuggestions( u"a", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(2), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("abc"), suggestions[0] );
CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions[1] );
suggestions.clear();
trie.findSuggestions( "abc", suggestions);
trie.findSuggestions( u"abc", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions[0] );
suggestions.clear();
trie.findSuggestions( "abe", suggestions);
trie.findSuggestions( u"abe", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(0), suggestions.size() );
suggestions.clear();
trie.insert( "abe" );
trie.findSuggestions( "", suggestions);
trie.insert( u"abe" );
trie.findSuggestions( u"", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(3), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("abc"), suggestions[0] );
CPPUNIT_ASSERT_EQUAL( OUString("abcdefghijklmnopqrstuvwxyz"), suggestions[1] );
CPPUNIT_ASSERT_EQUAL( OUString("abe"), suggestions[2] );
suggestions.clear();
trie.insert( "H31l0" );
trie.findSuggestions( "H", suggestions);
trie.insert( u"H31l0" );
trie.findSuggestions( u"H", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
suggestions.clear();
trie.insert( "H1" );
trie.findSuggestions( "H", suggestions);
trie.insert( u"H1" );
trie.findSuggestions( u"H", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(2), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
CPPUNIT_ASSERT_EQUAL( OUString("H1"), suggestions[1] );
suggestions.clear();
trie.findSuggestions( "H3", suggestions);
trie.findSuggestions( u"H3", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
suggestions.clear();
trie.insert( OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8 ) );
trie.findSuggestions( "H", suggestions );
trie.findSuggestions( u"H", suggestions );
CPPUNIT_ASSERT_EQUAL( size_t(3), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
CPPUNIT_ASSERT_EQUAL( OUString("H1"), suggestions[1] );
CPPUNIT_ASSERT_EQUAL( OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8 ), suggestions[2] );
suggestions.clear();
trie.findSuggestions( "H3", suggestions );
trie.findSuggestions( u"H3", suggestions );
CPPUNIT_ASSERT_EQUAL( size_t(1), suggestions.size() );
CPPUNIT_ASSERT_EQUAL( OUString("H31l0"), suggestions[0] );
suggestions.clear();
@@ -116,7 +116,7 @@ void LookupTreeTest::testTrie()
CPPUNIT_ASSERT_EQUAL( OStringToOUString("H\xC3\xA4llo", RTL_TEXTENCODING_UTF8), suggestions[0] );
suggestions.clear();
trie.findSuggestions( "", suggestions);
trie.findSuggestions( u"", suggestions);
CPPUNIT_ASSERT_EQUAL( size_t(6), suggestions.size() );
suggestions.clear();
}
@@ -127,15 +127,15 @@ void LookupTreeTest::testTrieGetAllEntries()
CPPUNIT_ASSERT_EQUAL( size_t(0), trie.size() );
trie.insert("A");
trie.insert(u"A");
CPPUNIT_ASSERT_EQUAL( size_t(1), trie.size() );
trie.insert("B");
trie.insert("C");
trie.insert(u"B");
trie.insert(u"C");
CPPUNIT_ASSERT_EQUAL( size_t(3), trie.size() );
trie.insert("AA");
trie.insert("AAA");
trie.insert(u"AA");
trie.insert(u"AAA");
CPPUNIT_ASSERT_EQUAL( size_t(5), trie.size() );
}
+6 -6
View File
@@ -2254,16 +2254,16 @@ EditPaM EditDoc::RemoveText()
return EditPaM( pNode, 0 );
}
EditPaM EditDoc::InsertText( EditPaM aPaM, const OUString& rStr )
EditPaM EditDoc::InsertText( EditPaM aPaM, std::u16string_view rStr )
{
DBG_ASSERT( rStr.indexOf( 0x0A ) == -1, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
DBG_ASSERT( rStr.indexOf( 0x0D ) == -1, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
DBG_ASSERT( rStr.indexOf( '\t' ) == -1, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
DBG_ASSERT( rStr.find( 0x0A ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
DBG_ASSERT( rStr.find( 0x0D ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
DBG_ASSERT( rStr.find( '\t' ) == std::u16string_view::npos, "EditDoc::InsertText: Newlines prohibited in paragraph!" );
assert(aPaM.GetNode());
aPaM.GetNode()->Insert( rStr, aPaM.GetIndex() );
aPaM.GetNode()->ExpandAttribs( aPaM.GetIndex(), rStr.getLength(), GetItemPool() );
aPaM.SetIndex( aPaM.GetIndex() + rStr.getLength() );
aPaM.GetNode()->ExpandAttribs( aPaM.GetIndex(), rStr.size(), GetItemPool() );
aPaM.SetIndex( aPaM.GetIndex() + rStr.size() );
SetModified( true );
+2 -2
View File
@@ -2687,7 +2687,7 @@ EditPaM ImpEditEngine::InsertTextUserInput( const EditSelection& rCurSel,
InsertUndo( std::move(pNewUndo), bTryMerge );
}
aEditDoc.InsertText( aPaM, OUString(c) );
aEditDoc.InsertText( aPaM, OUStringChar(c) );
ParaPortion* pPortion = FindParaPortion( aPaM.GetNode() );
assert(pPortion);
pPortion->MarkInvalid( aPaM.GetIndex(), 1 );
@@ -2813,7 +2813,7 @@ EditPaM ImpEditEngine::ImpInsertText(const EditSelection& aCurSel, const OUStrin
nEnd2 = aLine.getLength(); // not dereference!
if ( nEnd2 > nStart2 )
aPaM = aEditDoc.InsertText( aPaM, aLine.copy( nStart2, nEnd2-nStart2 ) );
aPaM = aEditDoc.InsertText( aPaM, aLine.subView( nStart2, nEnd2-nStart2 ) );
if ( nEnd2 < aLine.getLength() )
{
aPaM = aEditDoc.InsertFeature( aPaM, aTabItem );
+1 -1
View File
@@ -3030,7 +3030,7 @@ short ImpEditEngine::ReplaceTextOnly(
else
{
DBG_ASSERT( nDiff == 1, "TransliterateText - Diff other than expected! But should work..." );
GetEditDoc().InsertText( EditPaM( pNode, nCurrentPos ), OUString(rNewText[n]) );
GetEditDoc().InsertText( EditPaM( pNode, nCurrentPos ), OUStringChar(rNewText[n]) );
}
nDiffs = sal::static_int_cast< short >(nDiffs + nDiff);
+2 -2
View File
@@ -401,7 +401,7 @@ void TextConvWrapper::ReplaceUnit(
void TextConvWrapper::ChangeText( const OUString &rNewText,
const OUString& rOrigText,
std::u16string_view rOrigText,
const uno::Sequence< sal_Int32 > *pOffsets,
ESelection *pESelection )
{
@@ -443,7 +443,7 @@ void TextConvWrapper::ChangeText( const OUString &rNewText,
else
{
nPos = nConvTextLen;
nIndex = rOrigText.getLength();
nIndex = rOrigText.size();
}
// end of string also terminates non-matching char sequence
+1 -1
View File
@@ -61,7 +61,7 @@ class TextConvWrapper final : public editeng::HangulHanjaConversion
const sal_Int32 nUnitEnd );
void ChangeText( const OUString &rNewText,
const OUString& rOrigText,
std::u16string_view rOrigText,
const css::uno::Sequence< sal_Int32 > *pOffsets,
ESelection *pESelection );
void ChangeText_impl( const OUString &rNewText, bool bKeepAttributes );
+7 -7
View File
@@ -31,7 +31,7 @@ struct TrieNode final
void markWord();
TrieNode* findChild(sal_Unicode aCharacter);
TrieNode* traversePath(const OUString& sPath);
TrieNode* traversePath(std::u16string_view sPath);
void addNewChild(TrieNode* pChild);
void collectSuggestions(std::u16string_view sPath, std::vector<OUString>& rSuggestionList);
static void collectSuggestionsForCurrentNode(TrieNode* pCurrent, std::u16string_view sPath, std::vector<OUString>& rSuggestionList);
@@ -110,11 +110,11 @@ void TrieNode::collectSuggestionsForCurrentNode(TrieNode* pCurrent, std::u16stri
pCurrent->collectSuggestions(aStringPath, rSuggestionList);
}
TrieNode* TrieNode::traversePath(const OUString& sPath)
TrieNode* TrieNode::traversePath(std::u16string_view sPath)
{
TrieNode* pCurrent = this;
for ( sal_Int32 i = 0; i < sPath.getLength(); i++ )
for ( size_t i = 0; i < sPath.size(); i++ )
{
sal_Unicode aCurrentChar = sPath[i];
pCurrent = pCurrent->findChild(aCurrentChar);
@@ -134,10 +134,10 @@ Trie::Trie() :
Trie::~Trie()
{}
void Trie::insert(const OUString& sInputString) const
void Trie::insert(std::u16string_view sInputString) const
{
// adding an empty word is not allowed
if ( sInputString.isEmpty() )
if ( sInputString.empty() )
{
return;
}
@@ -147,7 +147,7 @@ void Trie::insert(const OUString& sInputString) const
TrieNode* pCurrent = mRoot.get();
sal_Unicode aCurrentChar;
for ( sal_Int32 i = 0; i < sInputString.getLength(); i++ )
for ( size_t i = 0; i < sInputString.size(); i++ )
{
aCurrentChar = sInputString[i];
TrieNode* pChild = pCurrent->findChild(aCurrentChar);
@@ -166,7 +166,7 @@ void Trie::insert(const OUString& sInputString) const
pCurrent->markWord();
}
void Trie::findSuggestions(const OUString& sWordPart, std::vector<OUString>& rSuggestionList) const
void Trie::findSuggestions(std::u16string_view sWordPart, std::vector<OUString>& rSuggestionList) const
{
TrieNode* pNode = mRoot->traversePath(sWordPart);
+2 -2
View File
@@ -52,7 +52,7 @@ using namespace ::com::sun::star::linguistic2;
// misc functions ---------------------------------------------
void SvxPrepareAutoCorrect( OUString &rOldText, const OUString &rNewText )
void SvxPrepareAutoCorrect( OUString &rOldText, std::u16string_view rNewText )
{
// This function should be used to strip (or add) trailing '.' from
// the strings before passing them on to the autocorrect function in
@@ -64,7 +64,7 @@ void SvxPrepareAutoCorrect( OUString &rOldText, const OUString &rNewText )
// rNewText: replacement text
sal_Int32 nOldLen = rOldText.getLength();
sal_Int32 nNewLen = rNewText.getLength();
sal_Int32 nNewLen = rNewText.size();
if (nOldLen && nNewLen)
{
bool bOldHasDot = '.' == rOldText[ nOldLen - 1 ],
+39 -38
View File
@@ -106,7 +106,7 @@ const char
/* also at these ends - Brackets and all kinds of begin characters */
sImplEndSkipChars[] = "\"\')]}\x83\x84\x89\x91\x92\x93\x94";
static OUString EncryptBlockName_Imp(const OUString& rName);
static OUString EncryptBlockName_Imp(std::u16string_view rName);
static bool NonFieldWordDelim( const sal_Unicode c )
{
@@ -651,7 +651,7 @@ bool SvxAutoCorrect::FnChgToEnEmDash(
// Add non-breaking space before specific punctuation marks in French text
bool SvxAutoCorrect::FnAddNonBrkSpace(
SvxAutoCorrDoc& rDoc, const OUString& rTxt,
SvxAutoCorrDoc& rDoc, std::u16string_view rTxt,
sal_Int32 nEndPos,
LanguageType eLang, bool& io_bNbspRunNext )
{
@@ -684,17 +684,17 @@ bool SvxAutoCorrect::FnAddNonBrkSpace(
//See if the text is the start of a protocol string, e.g. have text of
//"http" see if it is the start of "http:" and if so leave it alone
sal_Int32 nIndex = nSttWdPos + (bWasWordDelim ? 1 : 0);
sal_Int32 nProtocolLen = nEndPos - nSttWdPos + 1;
if (nIndex + nProtocolLen <= rTxt.getLength())
size_t nIndex = nSttWdPos + (bWasWordDelim ? 1 : 0);
size_t nProtocolLen = nEndPos - nSttWdPos + 1;
if (nIndex + nProtocolLen <= rTxt.size())
{
if (INetURLObject::CompareProtocolScheme(rTxt.subView(nIndex, nProtocolLen)) != INetProtocol::NotValid)
if (INetURLObject::CompareProtocolScheme(rTxt.substr(nIndex, nProtocolLen)) != INetProtocol::NotValid)
return false;
}
// Check the presence of "://" in the word
sal_Int32 nStrPos = rTxt.indexOf( "://", nSttWdPos + 1 );
if ( nStrPos == -1 && nEndPos > 0 )
size_t nStrPos = rTxt.find( u"://", nSttWdPos + 1 );
if ( nStrPos == std::u16string_view::npos && nEndPos > 0 )
{
// Check the previous char
sal_Unicode cPrevChar = rTxt[ nEndPos - 1 ];
@@ -723,7 +723,7 @@ bool SvxAutoCorrect::FnAddNonBrkSpace(
io_bNbspRunNext = true;
}
}
else if ( cChar == '/' && nEndPos > 1 && rTxt.getLength() > (nEndPos - 1) )
else if ( cChar == '/' && nEndPos > 1 && static_cast<sal_Int32>(rTxt.size()) > (nEndPos - 1) )
{
// Remove the hardspace right before to avoid formatting URLs
sal_Unicode cPrevChar = rTxt[ nEndPos - 1 ];
@@ -1876,11 +1876,11 @@ bool SvxAutoCorrect::PutText( const css::uno::Reference < css::embed::XStorage >
return false;
}
OUString EncryptBlockName_Imp(const OUString& rName)
OUString EncryptBlockName_Imp(std::u16string_view rName)
{
OUStringBuffer aName;
aName.append('#').append(rName);
for (sal_Int32 nLen = rName.getLength(), nPos = 1; nPos < nLen; ++nPos)
for (size_t nLen = rName.size(), nPos = 1; nPos < nLen; ++nPos)
{
if (lcl_IsInAsciiArr( "!/:.\\", aName[nPos]))
aName[nPos] &= 0x0f;
@@ -1914,7 +1914,7 @@ static void GeneratePackageName ( std::u16string_view rShort, OUString& rPackage
}
static const SvxAutocorrWord* lcl_SearchWordsInList(
SvxAutoCorrectLanguageLists* pList, const OUString& rTxt,
SvxAutoCorrectLanguageLists* pList, std::u16string_view rTxt,
sal_Int32& rStt, sal_Int32 nEndPos)
{
const SvxAutocorrWordList* pAutoCorrWordList = pList->GetAutocorrWordList();
@@ -1923,7 +1923,7 @@ static const SvxAutocorrWord* lcl_SearchWordsInList(
// the search for the words in the substitution table
const SvxAutocorrWord* SvxAutoCorrect::SearchWordsInList(
const OUString& rTxt, sal_Int32& rStt, sal_Int32 nEndPos,
std::u16string_view rTxt, sal_Int32& rStt, sal_Int32 nEndPos,
SvxAutoCorrDoc&, LanguageTag& rLang )
{
const SvxAutocorrWord* pRet = nullptr;
@@ -2932,7 +2932,7 @@ const SvxAutocorrWordList::AutocorrWordSetType& SvxAutocorrWordList::getSortedCo
}
const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *pFnd,
const OUString &rTxt,
std::u16string_view rTxt,
sal_Int32 &rStt,
sal_Int32 nEndPos) const
{
@@ -2940,10 +2940,11 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p
sal_Int32 left_wildcard = rChk.startsWith( ".*" ) ? 2 : 0; // ".*word" pattern?
sal_Int32 right_wildcard = rChk.endsWith( ".*" ) ? 2 : 0; // "word.*" pattern?
sal_Int32 nSttWdPos = nEndPos;
assert(nEndPos >= 0);
size_t nSttWdPos = nEndPos;
// direct replacement of keywords surrounded by colons (for example, ":name:")
bool bColonNameColon = rTxt.getLength() > nEndPos &&
bool bColonNameColon = static_cast<sal_Int32>(rTxt.size()) > nEndPos &&
rTxt[nEndPos] == ':' && rChk[0] == ':' && rChk.endsWith(":");
if ( nEndPos + (bColonNameColon ? 1 : 0) < rChk.getLength() - left_wildcard - right_wildcard )
return nullptr;
@@ -2957,14 +2958,14 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p
IsWordDelim( rTxt[ nCalcStt - 1 ] ))) )
{
TransliterationWrapper& rCmp = GetIgnoreTranslWrapper();
OUString sWord = rTxt.copy(nCalcStt, rChk.getLength() - left_wildcard);
OUString sWord( rTxt.substr(nCalcStt, rChk.getLength() - left_wildcard) );
if( (!left_wildcard && rCmp.isEqual( rChk, sWord )) || (left_wildcard && rCmp.isEqual( rChk.copy(left_wildcard), sWord) ))
{
rStt = nCalcStt;
if (!left_wildcard)
{
// fdo#33899 avoid "1/2", "1/3".. to be replaced by fractions in dates, eg. 1/2/14
if (rTxt.getLength() > nEndPos && rTxt[nEndPos] == '/' && rChk.indexOf('/') != -1)
if (static_cast<sal_Int32>(rTxt.size()) > nEndPos && rTxt[nEndPos] == '/' && rChk.indexOf('/') != -1)
return nullptr;
return pFnd;
}
@@ -2972,10 +2973,10 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p
while( rStt && !(bWasWordDelim = IsWordDelim( rTxt[ --rStt ])))
;
if (bWasWordDelim) rStt++;
OUString left_pattern = rTxt.copy(rStt, nEndPos - rStt - rChk.getLength() + left_wildcard);
OUString left_pattern( rTxt.substr(rStt, nEndPos - rStt - rChk.getLength() + left_wildcard) );
// avoid double spaces before simple "word" replacement
left_pattern += (left_pattern.getLength() == 0 && pFnd->GetLong()[0] == 0x20) ? pFnd->GetLong().subView(1) : pFnd->GetLong();
if( const SvxAutocorrWord* pNew = Insert( SvxAutocorrWord(rTxt.copy(rStt, nEndPos - rStt), left_pattern) ) )
if( const SvxAutocorrWord* pNew = Insert( SvxAutocorrWord(OUString(rTxt.substr(rStt, nEndPos - rStt)), left_pattern) ) )
return pNew;
}
} else
@@ -2990,17 +2991,17 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p
while( nSttWdPos && !(bWasWordDelim = IsWordDelim( rTxt[ --nSttWdPos ])))
;
// search the first occurrence (with a left word delimitation, if needed)
sal_Int32 nFndPos = -1;
size_t nFndPos = std::u16string_view::npos;
do {
nFndPos = rTxt.indexOf( sTmp, nFndPos + 1);
if (nFndPos == -1)
nFndPos = rTxt.find( sTmp, nFndPos + 1);
if (nFndPos == std::u16string_view::npos)
break;
not_suffix = bWasWordDelim && (nSttWdPos >= (nFndPos + sTmp.getLength()));
} while ( (!left_wildcard && nFndPos && !IsWordDelim( rTxt[ nFndPos - 1 ])) || not_suffix );
if ( nFndPos != -1 )
if ( nFndPos != std::u16string_view::npos )
{
sal_Int32 extra_repl = nFndPos + sTmp.getLength() > nEndPos ? 1: 0; // for patterns with terminating characters, eg. "a:"
sal_Int32 extra_repl = static_cast<sal_Int32>(nFndPos) + sTmp.getLength() > nEndPos ? 1: 0; // for patterns with terminating characters, eg. "a:"
if ( left_wildcard )
{
@@ -3009,41 +3010,41 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p
;
if (bWasWordDelim) nFndPos++;
}
if (nEndPos + extra_repl <= nFndPos)
if (nEndPos + extra_repl <= static_cast<sal_Int32>(nFndPos))
{
return nullptr;
}
// store matching pattern and its replacement as a new list item, eg. "i18ns" -> "internationalizations"
OUString aShort = rTxt.copy(nFndPos, nEndPos - nFndPos + extra_repl);
OUString aShort( rTxt.substr(nFndPos, nEndPos - nFndPos + extra_repl) );
OUString aLong;
rStt = nFndPos;
if ( !left_wildcard )
{
sal_Int32 siz = nEndPos - nFndPos - sTmp.getLength();
aLong = pFnd->GetLong() + (siz > 0 ? rTxt.subView(nFndPos + sTmp.getLength(), siz) : u"");
aLong = pFnd->GetLong() + (siz > 0 ? rTxt.substr(nFndPos + sTmp.getLength(), siz) : u"");
} else {
OUStringBuffer buf;
do {
nSttWdPos = rTxt.indexOf( sTmp, nFndPos);
if (nSttWdPos != -1)
nSttWdPos = rTxt.find( sTmp, nFndPos);
if (nSttWdPos != std::u16string_view::npos)
{
sal_Int32 nTmp(nFndPos);
while (nTmp < nSttWdPos && !IsWordDelim(rTxt[nTmp]))
while (nTmp < static_cast<sal_Int32>(nSttWdPos) && !IsWordDelim(rTxt[nTmp]))
nTmp++;
if (nTmp < nSttWdPos)
if (nTmp < static_cast<sal_Int32>(nSttWdPos))
break; // word delimiter found
buf.append(rTxt.subView(nFndPos, nSttWdPos - nFndPos)).append(pFnd->GetLong());
buf.append(rTxt.substr(nFndPos, nSttWdPos - nFndPos)).append(pFnd->GetLong());
nFndPos = nSttWdPos + sTmp.getLength();
}
} while (nSttWdPos != -1);
if (nEndPos - nFndPos > extra_repl)
buf.append(rTxt.subView(nFndPos, nEndPos - nFndPos));
} while (nSttWdPos != std::u16string_view::npos);
if (static_cast<sal_Int32>(nEndPos - nFndPos) > extra_repl)
buf.append(rTxt.substr(nFndPos, nEndPos - nFndPos));
aLong = buf.makeStringAndClear();
}
if ( const SvxAutocorrWord* pNew = Insert( SvxAutocorrWord(aShort, aLong) ) )
{
if ( (rTxt.getLength() > nEndPos && IsWordDelim(rTxt[nEndPos])) || rTxt.getLength() == nEndPos )
if ( (static_cast<sal_Int32>(rTxt.size()) > nEndPos && IsWordDelim(rTxt[nEndPos])) || static_cast<sal_Int32>(rTxt.size()) == nEndPos )
return pNew;
}
}
@@ -3051,7 +3052,7 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p
return nullptr;
}
const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(const OUString& rTxt, sal_Int32& rStt,
const SvxAutocorrWord* SvxAutocorrWordList::SearchWordsInList(std::u16string_view rTxt, sal_Int32& rStt,
sal_Int32 nEndPos) const
{
for (auto const& elem : mpImpl->maHash)
+3 -2
View File
@@ -28,8 +28,9 @@ public:
Trie();
~Trie();
void insert(const OUString& sInputString) const;
void findSuggestions(const OUString& sWordPart, std::vector<OUString>& rSuggestionList) const;
void insert(std::u16string_view sInputString) const;
void findSuggestions(std::u16string_view sWordPart,
std::vector<OUString>& rSuggestionList) const;
size_t size() const;
};
}
+1 -1
View File
@@ -36,7 +36,7 @@ namespace com::sun::star::linguistic2 {
// misc functions ---------------------------------------------------------------
void EDITENG_DLLPUBLIC SvxPrepareAutoCorrect( OUString &rOldText, const OUString &rNewText );
void EDITENG_DLLPUBLIC SvxPrepareAutoCorrect( OUString &rOldText, std::u16string_view rNewText );
/*--------------------------------------------------------------------
Description: The SpellWrapper
+4 -4
View File
@@ -162,7 +162,7 @@ class EDITENG_DLLPUBLIC SvxAutocorrWordList
const SvxAutocorrWordList& operator= ( const SvxAutocorrWordList& ) = delete;
const SvxAutocorrWord* WordMatches(const SvxAutocorrWord *pFnd,
const OUString &rTxt,
std::u16string_view rTxt,
sal_Int32 &rStt,
sal_Int32 nEndPos) const;
public:
@@ -179,7 +179,7 @@ public:
typedef std::vector<SvxAutocorrWord> AutocorrWordSetType;
const AutocorrWordSetType & getSortedContent() const;
const SvxAutocorrWord* SearchWordsInList(const OUString& rTxt, sal_Int32& rStt, sal_Int32 nEndPos) const;
const SvxAutocorrWord* SearchWordsInList(std::u16string_view rTxt, sal_Int32& rStt, sal_Int32 nEndPos) const;
};
class EDITENG_DLLPUBLIC SvxAutoCorrectLanguageLists
@@ -321,7 +321,7 @@ public:
// nEnd - to check position - as of this item forward
// rLang - Input: in which language is searched
// Output: in which "language list" was it found
const SvxAutocorrWord* SearchWordsInList( const OUString& rTxt,
const SvxAutocorrWord* SearchWordsInList( std::u16string_view rTxt,
sal_Int32& rStt, sal_Int32 nEndPos,
SvxAutoCorrDoc& rDoc,
LanguageTag& rLang );
@@ -410,7 +410,7 @@ public:
bool FnChgToEnEmDash( SvxAutoCorrDoc&, std::u16string_view,
sal_Int32 nSttPos, sal_Int32 nEndPos,
LanguageType eLang );
bool FnAddNonBrkSpace( SvxAutoCorrDoc&, const OUString&,
bool FnAddNonBrkSpace( SvxAutoCorrDoc&, std::u16string_view,
sal_Int32 nEndPos,
LanguageType eLang, bool& io_bNbspRunNext );
bool FnSetINetAttr( SvxAutoCorrDoc&, const OUString&,
+1 -1
View File
@@ -70,7 +70,7 @@ public:
void CheckChangedList(const editeng::SortedAutoCompleteStrings& rNewLst);
// Returns all words matching a given prefix aMatch.
bool GetWordsMatching(const OUString& aMatch, std::vector<OUString>& aWords) const;
bool GetWordsMatching(std::u16string_view aMatch, std::vector<OUString>& aWords) const;
};
#endif
+2 -2
View File
@@ -244,7 +244,7 @@ bool SwAutoCompleteWord::InsertWord( const OUString& rWord, SwDoc& rDoc )
std::pair<editeng::SortedAutoCompleteStrings::const_iterator, bool>
aInsPair = m_WordList.insert(pNew);
m_LookupTree.insert( aNewWord.copy(0, nWrdLen) );
m_LookupTree.insert( aNewWord.subView(0, nWrdLen) );
if (aInsPair.second)
{
@@ -330,7 +330,7 @@ void SwAutoCompleteWord::SetMinWordLen( sal_uInt16 n )
* @param aMatch the prefix to search for
* @param rWords the words found matching
*/
bool SwAutoCompleteWord::GetWordsMatching(const OUString& aMatch, std::vector<OUString>& rWords) const
bool SwAutoCompleteWord::GetWordsMatching(std::u16string_view aMatch, std::vector<OUString>& rWords) const
{
assert(rWords.empty());
m_LookupTree.findSuggestions(aMatch, rWords);