diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-29 15:30:44 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-01 08:28:35 +0200 |
commit | b90d3d316dd9c720c83180b31f6bbd7003fead78 (patch) | |
tree | 44d2dcb67f7545d468ab636ded89266f9cf16349 | |
parent | 1ffd6897ddf15624e70585ab08e8af713114c938 (diff) |
use string_view in WhitespaceToSpace
Change-Id: I64c63418ca51a09312083dab2432bcca0ea262a3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133647
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/vcl/pdfwriter.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/pdf/pdfwriter_impl.hxx | 4 | ||||
-rw-r--r-- | vcl/inc/strhelper.hxx | 4 | ||||
-rw-r--r-- | vcl/inc/unx/printerjob.hxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter.cxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 4 | ||||
-rw-r--r-- | vcl/source/helper/strhelper.cxx | 36 | ||||
-rw-r--r-- | vcl/unx/generic/print/common_gfx.cxx | 5 | ||||
-rw-r--r-- | vcl/unx/generic/print/printerjob.cxx | 4 | ||||
-rw-r--r-- | vcl/unx/generic/printer/ppdparser.cxx | 2 |
10 files changed, 34 insertions, 31 deletions
diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx index 6e8d68cfcff9..3386086c732d 100644 --- a/include/vcl/pdfwriter.hxx +++ b/include/vcl/pdfwriter.hxx @@ -999,7 +999,7 @@ The following structure describes the permissions used in PDF security @returns the outline item id of the new item */ - sal_Int32 CreateOutlineItem( sal_Int32 nParent, const OUString& rText, sal_Int32 nDestID ); + sal_Int32 CreateOutlineItem( sal_Int32 nParent, std::u16string_view rText, sal_Int32 nDestID ); /** Create a new note on a page diff --git a/vcl/inc/pdf/pdfwriter_impl.hxx b/vcl/inc/pdf/pdfwriter_impl.hxx index 29d1f598c68d..6326f83755e0 100644 --- a/vcl/inc/pdf/pdfwriter_impl.hxx +++ b/vcl/inc/pdf/pdfwriter_impl.hxx @@ -1240,9 +1240,9 @@ public: void setScreenStream(sal_Int32 nScreenId, const OUString& rURL); // outline - sal_Int32 createOutlineItem( sal_Int32 nParent, const OUString& rText, sal_Int32 nDestID ); + sal_Int32 createOutlineItem( sal_Int32 nParent, std::u16string_view rText, sal_Int32 nDestID ); void setOutlineItemParent( sal_Int32 nItem, sal_Int32 nNewParent ); - void setOutlineItemText( sal_Int32 nItem, const OUString& rText ); + void setOutlineItemText( sal_Int32 nItem, std::u16string_view rText ); void setOutlineItemDest( sal_Int32 nItem, sal_Int32 nDestID ); // notes diff --git a/vcl/inc/strhelper.hxx b/vcl/inc/strhelper.hxx index e5141db475a9..c0cff31afc4f 100644 --- a/vcl/inc/strhelper.hxx +++ b/vcl/inc/strhelper.hxx @@ -35,8 +35,8 @@ namespace psp int GetCommandLineTokenCount(const OUString&); // returns number of tokens (zero if empty or whitespace only) - OUString WhitespaceToSpace( const OUString&, bool bProtect = true ); - OString WhitespaceToSpace(const OString&); + OUString WhitespaceToSpace( std::u16string_view, bool bProtect = true ); + OString WhitespaceToSpace(std::string_view); // returns a string with multiple adjacent occurrences of whitespace // converted to a single space. if bProtect is sal_True (nonzero), then // doublequote, singlequote and singleleftquote protect their respective diff --git a/vcl/inc/unx/printerjob.hxx b/vcl/inc/unx/printerjob.hxx index 4fd99b17b638..47d1c0ac9c96 100644 --- a/vcl/inc/unx/printerjob.hxx +++ b/vcl/inc/unx/printerjob.hxx @@ -111,7 +111,7 @@ public: bool StartJob (const OUString& rFileName, int nMode, const OUString& rJobName, - const OUString& rAppName, + std::u16string_view rAppName, const JobData& rSetupData, PrinterGfx* pGraphics, bool bIsQuickJob diff --git a/vcl/source/gdi/pdfwriter.cxx b/vcl/source/gdi/pdfwriter.cxx index f26f6c31705b..1a8d407c7247 100644 --- a/vcl/source/gdi/pdfwriter.cxx +++ b/vcl/source/gdi/pdfwriter.cxx @@ -378,7 +378,7 @@ void PDFWriter::SetLinkPropertyID( sal_Int32 nLinkId, sal_Int32 nPropertyId ) xImplementation->setLinkPropertyId( nLinkId, nPropertyId ); } -sal_Int32 PDFWriter::CreateOutlineItem( sal_Int32 nParent, const OUString& rText, sal_Int32 nDestID ) +sal_Int32 PDFWriter::CreateOutlineItem( sal_Int32 nParent, std::u16string_view rText, sal_Int32 nDestID ) { return xImplementation->createOutlineItem( nParent, rText, nDestID ); } diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index c80e5e1c4e81..e6c73d6b2c39 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -9844,7 +9844,7 @@ void PDFWriterImpl::setLinkPropertyId( sal_Int32 nLinkId, sal_Int32 nPropertyId m_aLinkPropertyMap[ nPropertyId ] = nLinkId; } -sal_Int32 PDFWriterImpl::createOutlineItem( sal_Int32 nParent, const OUString& rText, sal_Int32 nDestID ) +sal_Int32 PDFWriterImpl::createOutlineItem( sal_Int32 nParent, std::u16string_view rText, sal_Int32 nDestID ) { // create new item sal_Int32 nNewItem = m_aOutline.size(); @@ -9871,7 +9871,7 @@ void PDFWriterImpl::setOutlineItemParent( sal_Int32 nItem, sal_Int32 nNewParent m_aOutline[ nNewParent ].m_aChildren.push_back( nItem ); } -void PDFWriterImpl::setOutlineItemText( sal_Int32 nItem, const OUString& rText ) +void PDFWriterImpl::setOutlineItemText( sal_Int32 nItem, std::u16string_view rText ) { if( nItem < 1 || nItem >= static_cast<sal_Int32>(m_aOutline.size()) ) return; diff --git a/vcl/source/helper/strhelper.cxx b/vcl/source/helper/strhelper.cxx index 782c9ce123e1..3413d454d131 100644 --- a/vcl/source/helper/strhelper.cxx +++ b/vcl/source/helper/strhelper.cxx @@ -251,27 +251,28 @@ int GetCommandLineTokenCount(const OUString& rLine) return nTokenCount; } -OUString WhitespaceToSpace( const OUString& rLine, bool bProtect ) +OUString WhitespaceToSpace( std::u16string_view rLine, bool bProtect ) { - sal_Int32 nLen = rLine.getLength(); + size_t nLen = rLine.size(); if( ! nLen ) return OUString(); sal_Unicode *pBuffer = static_cast<sal_Unicode*>(alloca( sizeof(sal_Unicode)*(nLen + 1) )); - const sal_Unicode *pRun = rLine.getStr(); + const sal_Unicode *pRun = rLine.data(); + const sal_Unicode * const pEnd = rLine.data() + rLine.size(); sal_Unicode *pLeap = pBuffer; - while( *pRun ) + while( pRun != pEnd ) { - if( *pRun && isSpace( *pRun ) ) + if( pRun != pEnd && isSpace( *pRun ) ) { *pLeap = ' '; pLeap++; pRun++; } - while( *pRun && isSpace( *pRun ) ) + while( pRun != pEnd && isSpace( *pRun ) ) pRun++; - while( *pRun && ! isSpace( *pRun ) ) + while( pRun != pEnd && ! isSpace( *pRun ) ) { if( *pRun == '\\' ) { @@ -279,7 +280,7 @@ OUString WhitespaceToSpace( const OUString& rLine, bool bProtect ) pRun++; *pLeap = *pRun; pLeap++; - if( *pRun ) + if( pRun != pEnd ) pRun++; } else if( bProtect && *pRun == '`' ) @@ -310,27 +311,28 @@ OUString WhitespaceToSpace( const OUString& rLine, bool bProtect ) return OUString(*pBuffer == ' ' ? pBuffer+1 : pBuffer); } -OString WhitespaceToSpace(const OString& rLine) +OString WhitespaceToSpace(std::string_view rLine) { - sal_Int32 nLen = rLine.getLength(); + size_t nLen = rLine.size(); if (!nLen) - return rLine; + return OString(); char *pBuffer = static_cast<char*>(alloca( nLen + 1 )); - const char *pRun = rLine.getStr(); + const char *pRun = rLine.data(); + const char * const pEnd = rLine.data() + rLine.size(); char *pLeap = pBuffer; - while( *pRun ) + while( pRun != pEnd ) { - if( *pRun && isSpace( *pRun ) ) + if( pRun != pEnd && isSpace( *pRun ) ) { *pLeap = ' '; pLeap++; pRun++; } - while( *pRun && isSpace( *pRun ) ) + while( pRun != pEnd && isSpace( *pRun ) ) pRun++; - while( *pRun && ! isSpace( *pRun ) ) + while( pRun != pEnd && ! isSpace( *pRun ) ) { if( *pRun == '\\' ) { @@ -338,7 +340,7 @@ OString WhitespaceToSpace(const OString& rLine) pRun++; *pLeap = *pRun; pLeap++; - if( *pRun ) + if( pRun != pEnd ) pRun++; } else if( *pRun == '`' ) diff --git a/vcl/unx/generic/print/common_gfx.cxx b/vcl/unx/generic/print/common_gfx.cxx index 836677d77fa3..aba50ece2693 100644 --- a/vcl/unx/generic/print/common_gfx.cxx +++ b/vcl/unx/generic/print/common_gfx.cxx @@ -31,6 +31,7 @@ #include <tools/color.hxx> #include <tools/poly.hxx> #include <tools/stream.hxx> +#include <o3tl/string_view.hxx> using namespace psp ; @@ -1071,7 +1072,7 @@ PrinterGfx::DrawEPS( const tools::Rectangle& rBoundingBox, void* pPtr, sal_uInt3 { if( aLine.matchIgnoreAsciiCase( "%%BoundingBox:" ) ) { - aLine = WhitespaceToSpace( aLine.getToken(1, ':') ); + aLine = WhitespaceToSpace( o3tl::getToken(aLine, 1, ':') ); if( !aLine.isEmpty() && aLine.indexOf( "atend" ) == -1 ) { fLeft = StringToDouble( GetCommandLineToken( 0, aLine ) ); @@ -1081,7 +1082,7 @@ PrinterGfx::DrawEPS( const tools::Rectangle& rBoundingBox, void* pPtr, sal_uInt3 } } else if( aLine.matchIgnoreAsciiCase( "%%Title:" ) ) - aDocTitle = WhitespaceToSpace( aLine.copy( 8 ) ); + aDocTitle = WhitespaceToSpace( aLine.subView( 8 ) ); else if( aLine.matchIgnoreAsciiCase( "%%EndComments" ) ) bEndComments = true; } diff --git a/vcl/unx/generic/print/printerjob.cxx b/vcl/unx/generic/print/printerjob.cxx index f0ca4ebb002a..233bd2195a8e 100644 --- a/vcl/unx/generic/print/printerjob.cxx +++ b/vcl/unx/generic/print/printerjob.cxx @@ -277,7 +277,7 @@ PrinterJob::StartJob ( const OUString& rFileName, int nMode, const OUString& rJobName, - const OUString& rAppName, + std::u16string_view rAppName, const JobData& rSetupData, PrinterGfx* pGraphics, bool bIsQuickJob @@ -340,7 +340,7 @@ PrinterJob::StartJob ( OUString aTitle( aFilterWS ); if( ! isAscii( aTitle ) ) { - aTitle = WhitespaceToSpace( rFileName.copy(rFileName.lastIndexOf('/')+1), false ); + aTitle = WhitespaceToSpace( rFileName.subView(rFileName.lastIndexOf('/')+1), false ); if( ! isAscii( aTitle ) ) aTitle.clear(); } diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index 8191c98364e1..13fcf8daaf23 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -1244,7 +1244,7 @@ void PPDParser::parse( ::std::vector< OString >& rLines ) { aKey = aKey.copy(0, nPos); OUString aOption(OStringToOUString( - WhitespaceToSpace(aLine.copy(nPos+9)), + WhitespaceToSpace(aLine.subView(nPos+9)), RTL_TEXTENCODING_MS_1252)); keyit = m_aKeys.find( aKey ); if( keyit != m_aKeys.end() ) |