diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-03-01 12:07:47 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-03-01 21:32:11 +0100 |
commit | b871d057c45fdd231aa5e1d2b94e7d0a039f4292 (patch) | |
tree | 31ed7faa9558a171c6bcf0c2ed5a60a6fd5240ca /svtools | |
parent | 2960d4128710afd3e0c090960d281e69b44e69eb (diff) |
use OUStringBuffer for a string that's modified often (tdf#145862)
SvParser::aToken was OUString despite being a buffer where the parsed
result is collected.
Change-Id: Id24c842738ea0f6f1836f77d855069963ac5ae55
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130763
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/svhtml/htmlkywd.cxx | 13 | ||||
-rw-r--r-- | svtools/source/svhtml/parhtml.cxx | 57 | ||||
-rw-r--r-- | svtools/source/svrtf/parrtf.cxx | 10 | ||||
-rw-r--r-- | svtools/source/svrtf/rtfkeywd.cxx | 9 | ||||
-rw-r--r-- | svtools/source/svrtf/svparser.cxx | 2 |
5 files changed, 47 insertions, 44 deletions
diff --git a/svtools/source/svhtml/htmlkywd.cxx b/svtools/source/svhtml/htmlkywd.cxx index 1873b8ee186a..2d51910d85e9 100644 --- a/svtools/source/svhtml/htmlkywd.cxx +++ b/svtools/source/svhtml/htmlkywd.cxx @@ -21,6 +21,7 @@ #include <algorithm> #include <string_view> +#include <o3tl/string_view.hxx> #include <sal/types.h> #include <rtl/ustring.hxx> #include <svtools/htmltokn.h> @@ -43,12 +44,12 @@ static bool sortCompare(const TokenEntry<T> & lhs, const TokenEntry<T> & rhs) return lhs.sToken < rhs.sToken; } template<typename T> -static bool findCompare(const TokenEntry<T> & lhs, const OUString & rhs) +static bool findCompare(const TokenEntry<T> & lhs, std::u16string_view rhs) { return lhs.sToken < rhs; } template<typename T, size_t LEN> -static T search(TokenEntry<T> const (&dataTable)[LEN], const OUString & key, T notFoundValue) +static T search(TokenEntry<T> const (&dataTable)[LEN], std::u16string_view key, T notFoundValue) { auto findIt = std::lower_bound( std::begin(dataTable), std::end(dataTable), key, findCompare<T> ); @@ -174,7 +175,7 @@ HTML_TokenEntry const aHTMLTokenTab[] = { }; -HtmlTokenId GetHTMLToken( const OUString& rName ) +HtmlTokenId GetHTMLToken( std::u16string_view rName ) { static bool bSortKeyWords = false; if( !bSortKeyWords ) @@ -183,7 +184,7 @@ HtmlTokenId GetHTMLToken( const OUString& rName ) bSortKeyWords = true; } - if( rName.startsWith( OOO_STRING_SVTOOLS_HTML_comment )) + if( o3tl::starts_with( rName, u"" OOO_STRING_SVTOOLS_HTML_comment )) return HtmlTokenId::COMMENT; return search( aHTMLTokenTab, rName, HtmlTokenId::NONE); @@ -459,7 +460,7 @@ static HTML_CharEntry aHTMLCharNameTab[] = { {std::u16string_view(u"" OOO_STRING_SVTOOLS_HTML_S_diams), 9830} }; -sal_Unicode GetHTMLCharName( const OUString& rName ) +sal_Unicode GetHTMLCharName( std::u16string_view rName ) { if( !bSortCharKeyWords ) { @@ -631,7 +632,7 @@ static HTML_OptionEntry aHTMLOptionTab[] = { {std::u16string_view(u"" OOO_STRING_SVTOOLS_HTML_O_start), HtmlOptionId::START}, // Netscape 2.0 vs IExplorer 2.0 }; -HtmlOptionId GetHTMLOption( const OUString& rName ) +HtmlOptionId GetHTMLOption( std::u16string_view rName ) { if( !bSortOptionKeyWords ) { diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx index 6c3a2c070d2b..f8abfa7c694e 100644 --- a/svtools/source/svhtml/parhtml.cxx +++ b/svtools/source/svhtml/parhtml.cxx @@ -19,6 +19,7 @@ #include <comphelper/string.hxx> #include <o3tl/safeint.hxx> +#include <o3tl/string_view.hxx> #include <tools/stream.hxx> #include <tools/debug.hxx> #include <tools/color.hxx> @@ -542,7 +543,7 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak ) else { // If not scanning a tag return token - aToken += sTmpBuffer; + aToken.append( sTmpBuffer ); sTmpBuffer.setLength(0); if( !aToken.isEmpty() ) @@ -564,7 +565,7 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak ) // Hack: _GetNextChar shall not read the // next character if( ';' != nNextCh ) - aToken += " "; + aToken.append( " " ); if( 1U == cChar ) return HtmlTokenId::NONBREAKSPACE; else //2U @@ -719,7 +720,7 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak ) if( !aToken.isEmpty() || sTmpBuffer.getLength() > 1 ) { // Have seen s.th. aside from blanks? - aToken += sTmpBuffer; + aToken.append( sTmpBuffer ); sTmpBuffer.setLength(0); return HtmlTokenId::TEXTTOKEN; } @@ -753,7 +754,7 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak ) !IsParserWorking() ) { if( !sTmpBuffer.isEmpty() ) - aToken += sTmpBuffer; + aToken.append( sTmpBuffer ); return HtmlTokenId::TEXTTOKEN; } } while( rtl::isAsciiAlpha( nNextCh ) || rtl::isAsciiDigit( nNextCh ) ); @@ -766,7 +767,7 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak ) } if( !sTmpBuffer.isEmpty() ) - aToken += sTmpBuffer; + aToken.append( sTmpBuffer ); return HtmlTokenId::TEXTTOKEN; } @@ -801,7 +802,7 @@ HtmlTokenId HTMLParser::GetNextRawToken() // Maybe we've reached the end. // Save what we have read previously... - aToken += sTmpBuffer; + aToken.append( sTmpBuffer ); sTmpBuffer.setLength(0); // and remember position in stream. @@ -904,9 +905,9 @@ HtmlTokenId HTMLParser::GetNextRawToken() else { // remember "</" , everything else we find in the buffer - aToken += "<"; + aToken.append( "<" ); if( bOffState ) - aToken += "/"; + aToken.append( "/" ); bNextCh = false; } @@ -974,7 +975,7 @@ HtmlTokenId HTMLParser::GetNextRawToken() if( !bContinue && !sTmpBuffer.isEmpty() ) { - aToken += sTmpBuffer; + aToken.append( sTmpBuffer ); sTmpBuffer.setLength(0); } @@ -1001,7 +1002,7 @@ HtmlTokenId HTMLParser::GetNextToken_() // HtmlTokenId::<TOKEN>_OFF generated for HtmlTokenId::<TOKEN>_ON nRet = mnPendingOffToken; mnPendingOffToken = HtmlTokenId::NONE; - aToken.clear(); + aToken.setLength( 0 ); return nRet; } @@ -1058,7 +1059,7 @@ HtmlTokenId HTMLParser::GetNextToken_() if( !sTmpBuffer.isEmpty() ) { - aToken += sTmpBuffer; + aToken.append( sTmpBuffer ); sTmpBuffer.setLength(0); } @@ -1075,10 +1076,10 @@ HtmlTokenId HTMLParser::GetNextToken_() // Search token in table: sSaveToken = aToken; - aToken = aToken.toAsciiLowerCase(); + aToken = aToken.toString().toAsciiLowerCase(); - if (!maNamespace.isEmpty() && aToken.startsWith(maNamespace)) - aToken = aToken.copy(maNamespace.getLength()); + if (!maNamespace.isEmpty() && o3tl::starts_with(aToken, maNamespace)) + aToken = aToken.remove( 0, maNamespace.getLength()); if( HtmlTokenId::NONE == (nRet = GetHTMLToken( aToken )) ) // Unknown control @@ -1107,7 +1108,7 @@ HtmlTokenId HTMLParser::GetNextToken_() // and append a blank. aToken = sSaveToken; if( '>'!=nNextCh ) - aToken += " "; + aToken.append( " " ); sal_uInt64 nCStreamPos = 0; sal_uInt32 nCLineNr = 0; sal_uInt32 nCLinePos = 0; @@ -1146,14 +1147,14 @@ HtmlTokenId HTMLParser::GetNextToken_() SetLineNr( nCLineNr ); SetLinePos( nCLinePos ); ClearTxtConvContext(); - aToken = aToken.copy(0, nCStrLen); + aToken.truncate(nCStrLen); nNextCh = '>'; } } else { // TokenString not needed anymore - aToken.clear(); + aToken.setLength( 0 ); } // Read until closing '>' @@ -1165,10 +1166,10 @@ HtmlTokenId HTMLParser::GetNextToken_() // generate pending HtmlTokenId::<TOKEN>_OFF for HtmlTokenId::<TOKEN>_ON // Do not convert this to a single HtmlTokenId::<TOKEN>_OFF // which lead to fdo#56772. - if ((nRet >= HtmlTokenId::ONOFF_START) && aToken.endsWith("/")) + if ((nRet >= HtmlTokenId::ONOFF_START) && o3tl::ends_with(aToken, u"/")) { mnPendingOffToken = static_cast<HtmlTokenId>(static_cast<int>(nRet) + 1); // HtmlTokenId::<TOKEN>_ON -> HtmlTokenId::<TOKEN>_OFF - aToken = aToken.replaceAt( aToken.getLength()-1, 1, u""); // remove trailing '/' + aToken.setLength( aToken.getLength()-1 ); // remove trailing '/' } if( sal_Unicode(EOF) == nNextCh && rInput.eof() ) { @@ -1212,7 +1213,7 @@ HtmlTokenId HTMLParser::GetNextToken_() } if( SvParserState::Pending == eState ) bReadNextChar = bReadNextCharSave; - aToken.clear(); + aToken.setLength( 0 ); } else if( '%' == nNextCh ) { @@ -1249,7 +1250,7 @@ HtmlTokenId HTMLParser::GetNextToken_() if( IsParserWorking() ) { sSaveToken = aToken; - aToken.clear(); + aToken.setLength( 0 ); } } else @@ -1387,7 +1388,7 @@ void HTMLParser::UnescapeToken() bEscape = false; if( '\\'==aToken[nPos] && !bOldEscape ) { - aToken = aToken.replaceAt( nPos, 1, u"" ); + aToken.remove( nPos, 1 ); bEscape = true; } else @@ -1426,7 +1427,7 @@ const HTMLOptions& HTMLParser::GetOptions( HtmlOptionId const *pNoConvertToken ) nPos++; } - OUString sName( aToken.copy( nStt, nPos-nStt ) ); + OUString sName( aToken.subView( nStt, nPos-nStt ) ); // PlugIns require original token name. Convert to lower case only for searching. nToken = GetHTMLOption( sName.toAsciiLowerCase() ); // Name is ready @@ -1477,7 +1478,7 @@ const HTMLOptions& HTMLParser::GetOptions( HtmlOptionId const *pNoConvertToken ) case '\r': case '\n': if( bStripCRLF ) - aToken = aToken.replaceAt( nPos, 1, u"" ); + aToken.remove( nPos, 1 ); else { nPos++; @@ -1492,7 +1493,7 @@ const HTMLOptions& HTMLParser::GetOptions( HtmlOptionId const *pNoConvertToken ) } else { - aToken = aToken.replaceAt( nPos, 1, u"" ); + aToken.remove( nPos, 1 ); bEscape = true; } break; @@ -1549,7 +1550,7 @@ const HTMLOptions& HTMLParser::GetOptions( HtmlOptionId const *pNoConvertToken ) } else { - aToken = aToken.replaceAt( nPos, 1, u"" ); + aToken.remove( nPos, 1 ); bEscape = true; } break; @@ -1568,7 +1569,7 @@ const HTMLOptions& HTMLParser::GetOptions( HtmlOptionId const *pNoConvertToken ) } if( nLen ) - aValue = aToken.copy( nStt, nLen ); + aValue = aToken.subView( nStt, nLen ); } } @@ -1795,7 +1796,7 @@ HtmlTokenId HTMLParser::FilterXMP( HtmlTokenId nToken ) } else aToken = sSaveToken; - aToken += ">"; + aToken.append( ">" ); nToken = HtmlTokenId::TEXTTOKEN; } break; diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx index d16ac8cf0a1e..719401d342fe 100644 --- a/svtools/source/svrtf/parrtf.cxx +++ b/svtools/source/svrtf/parrtf.cxx @@ -106,7 +106,7 @@ int SvRTFParser::GetNextToken_() aStrBuffer.appendUtf32(nNextCh); nNextCh = GetNextChar(); } while( RTF_ISALPHA( nNextCh ) ); - aToken += aStrBuffer; + aToken.append( aStrBuffer ); } // minus before numeric parameters @@ -157,7 +157,7 @@ int SvRTFParser::GetNextToken_() aParserStates.top().nUCharOverread = nUCharOverread; } } - aToken.clear(); // #i47831# erase token to prevent the token from being treated as text + aToken.setLength( 0 ); // #i47831# erase token to prevent the token from being treated as text // read next token nRet = 0; break; @@ -183,7 +183,7 @@ int SvRTFParser::GetNextToken_() if( !bRTF_InTextRead ) { nRet = RTF_TEXTTOKEN; - aToken = OUString( static_cast<sal_Unicode>(nTokenValue) ); + aToken = OUStringChar( static_cast<sal_Unicode>(nTokenValue) ); // overread the next n "RTF" characters. This // can be also \{, \}, \'88 @@ -502,7 +502,7 @@ void SvRTFParser::ScanText() if (sal_Unicode(EOF) == (nNextCh = GetNextChar())) { if (!aStrBuffer.isEmpty()) - aToken += aStrBuffer; + aToken.append( aStrBuffer ); return; } } while @@ -519,7 +519,7 @@ void SvRTFParser::ScanText() } if (!aStrBuffer.isEmpty()) - aToken += aStrBuffer; + aToken.append( aStrBuffer ); } diff --git a/svtools/source/svrtf/rtfkeywd.cxx b/svtools/source/svrtf/rtfkeywd.cxx index 58c153634e69..e4864d7eddd2 100644 --- a/svtools/source/svrtf/rtfkeywd.cxx +++ b/svtools/source/svrtf/rtfkeywd.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <o3tl/string_view.hxx> #include <rtl/ustring.hxx> #include <svtools/rtfkeywd.hxx> #include <svtools/rtftoken.h> @@ -1175,7 +1176,7 @@ static RTF_TokenEntry aRTFTokenTab[] = { }; -int GetRTFToken( const OUString& rSearch ) +int GetRTFToken( std::u16string_view rSearch ) { if( !bSortKeyWords ) { @@ -1187,12 +1188,12 @@ int GetRTFToken( const OUString& rSearch ) bSortKeyWords = true; } - auto findCompare = [](const RTF_TokenEntry & lhs, const OUString & s) + auto findCompare = [](const RTF_TokenEntry & lhs, std::u16string_view s) { - return s.compareToIgnoreAsciiCase(lhs.sToken) > 0; + return o3tl::compareToIgnoreAsciiCase(s, lhs.sToken) > 0; }; auto findIt = std::lower_bound( std::begin(aRTFTokenTab), std::end(aRTFTokenTab), rSearch, findCompare); - if (findIt != std::end(aRTFTokenTab) && rSearch.compareToIgnoreAsciiCase(findIt->sToken)==0) + if (findIt != std::end(aRTFTokenTab) && o3tl::compareToIgnoreAsciiCase(rSearch, findIt->sToken)==0) return findIt->nToken; return 0; diff --git a/svtools/source/svrtf/svparser.cxx b/svtools/source/svrtf/svparser.cxx index ca0a8816851a..c003ebde3af6 100644 --- a/svtools/source/svrtf/svparser.cxx +++ b/svtools/source/svrtf/svparser.cxx @@ -444,7 +444,7 @@ T SvParser<T>::GetNextToken() if( !nTokenStackPos ) { - aToken.clear(); // empty token buffer + aToken.setLength( 0 ); // empty token buffer nTokenValue = -1; // marker for no value read bTokenHasValue = false; |