From 75a862b887fb0b7ff633a396ee7f7f34c2c82964 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 1 Aug 2022 18:58:55 +0200 Subject: use more string_view when dealing with attributes which means we don't need to call strlen on them, since we already know how long they are. Change-Id: Iefc76f38a23250e87a65c27df3634d562464a760 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137679 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/source/filter/inc/addressconverter.hxx | 6 +++--- sc/source/filter/oox/addressconverter.cxx | 9 +++++---- sc/source/filter/oox/sheetdatacontext.cxx | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'sc') diff --git a/sc/source/filter/inc/addressconverter.hxx b/sc/source/filter/inc/addressconverter.hxx index af1bc340c47b..e014167839d0 100644 --- a/sc/source/filter/inc/addressconverter.hxx +++ b/sc/source/filter/inc/addressconverter.hxx @@ -123,7 +123,7 @@ public: sal_Int32 nLength = SAL_MAX_INT32 ); static bool parseOoxAddress2d( - sal_Int32& ornColumn, sal_Int32& ornRow, const char* pStr ); + sal_Int32& ornColumn, sal_Int32& ornRow, std::string_view pStr ); /** Tries to parse the passed string for a 2d cell range in A1 notation. @@ -214,7 +214,7 @@ public: sal_Int16 nSheet ); static bool convertToCellAddressUnchecked( - ScAddress& orAddress, const char* pStr, sal_Int16 nSheet ); + ScAddress& orAddress, std::string_view pStr, sal_Int16 nSheet ); /** Tries to convert the passed string to a single cell address. @@ -233,7 +233,7 @@ public: bool convertToCellAddress( ScAddress& rAddress, - const char* pStr, sal_Int16 nSheet, bool bTrackOverflow ); + std::string_view pStr, sal_Int16 nSheet, bool bTrackOverflow ); /** Returns a valid cell address by moving it into allowed dimensions. diff --git a/sc/source/filter/oox/addressconverter.cxx b/sc/source/filter/oox/addressconverter.cxx index b3fc5b16722d..b13a4a5cd896 100644 --- a/sc/source/filter/oox/addressconverter.cxx +++ b/sc/source/filter/oox/addressconverter.cxx @@ -138,13 +138,14 @@ bool AddressConverter::parseOoxAddress2d( return (ornColumn >= 0) && (ornRow >= 0); } -bool AddressConverter::parseOoxAddress2d( sal_Int32& ornColumn, sal_Int32& ornRow, const char* pStr ) +bool AddressConverter::parseOoxAddress2d( sal_Int32& ornColumn, sal_Int32& ornRow, std::string_view aStr ) { ornColumn = ornRow = 0; enum { STATE_COL, STATE_ROW } eState = STATE_COL; - while (*pStr) + const char* pStr = aStr.data(); + while (pStr != aStr.data() + aStr.size()) { char cChar = *pStr; switch( eState ) @@ -267,7 +268,7 @@ bool AddressConverter::convertToCellAddressUnchecked( ScAddress& orAddress, } bool AddressConverter::convertToCellAddressUnchecked( - ScAddress& orAddress, const char* pStr, sal_Int16 nSheet ) + ScAddress& orAddress, std::string_view pStr, sal_Int16 nSheet ) { orAddress.SetTab(nSheet); sal_Int32 nCol = 0; @@ -289,7 +290,7 @@ bool AddressConverter::convertToCellAddress( ScAddress& orAddress, bool AddressConverter::convertToCellAddress( ScAddress& rAddress, - const char* pStr, sal_Int16 nSheet, bool bTrackOverflow ) + std::string_view pStr, sal_Int16 nSheet, bool bTrackOverflow ) { if (!convertToCellAddressUnchecked(rAddress, pStr, nSheet)) return false; diff --git a/sc/source/filter/oox/sheetdatacontext.cxx b/sc/source/filter/oox/sheetdatacontext.cxx index d6c4c7a266ba..c1a270afb41a 100644 --- a/sc/source/filter/oox/sheetdatacontext.cxx +++ b/sc/source/filter/oox/sheetdatacontext.cxx @@ -312,9 +312,9 @@ void SheetDataContext::importRow( const AttributeList& rAttribs ) bool SheetDataContext::importCell( const AttributeList& rAttribs ) { bool bValid = true; - const char* p = rAttribs.getChar(XML_r); + std::string_view p = rAttribs.getView(XML_r); - if (!p) + if (p.empty()) { ++mnCol; ScAddress aAddress( mnCol, mnRow, mnSheet ); -- cgit