diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-04 14:26:53 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-05 08:39:23 +0200 |
commit | d15a6560bd445cd1931e9fded6ad8ecfdd54211b (patch) | |
tree | dc23fce7925c88620abe8cc032b27f25b0a888e0 | |
parent | c895edf3f67f19d8d2012674c084456a7851436e (diff) |
use more string_view
found by examining the call sites of OString::getToken
which means I needed to add a new o3tl::equalsAscii function
Change-Id: I7dc0ea1cf5ce8090a708d44f2cf7c938fa200c5f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133826
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | comphelper/source/misc/servicedecl.cxx | 11 | ||||
-rw-r--r-- | connectivity/source/drivers/hsqldb/HDriver.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx | 33 | ||||
-rw-r--r-- | cppuhelper/source/loadsharedlibcomponentfactory.hxx | 2 | ||||
-rw-r--r-- | cppuhelper/source/shlib.cxx | 13 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 52 | ||||
-rw-r--r-- | include/comphelper/servicedecl.hxx | 2 | ||||
-rw-r--r-- | include/o3tl/string_view.hxx | 7 | ||||
-rw-r--r-- | sfx2/source/bastyp/mieclip.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/layout/dbg_lay.cxx | 15 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtksalmenu.cxx | 11 |
11 files changed, 82 insertions, 68 deletions
diff --git a/comphelper/source/misc/servicedecl.cxx b/comphelper/source/misc/servicedecl.cxx index 1955f6b56251..2b16539d1a55 100644 --- a/comphelper/source/misc/servicedecl.cxx +++ b/comphelper/source/misc/servicedecl.cxx @@ -19,6 +19,7 @@ #include <comphelper/servicedecl.hxx> +#include <o3tl/string_view.hxx> #include <rtl/string.hxx> #include <cppuhelper/implbase.hxx> #include <comphelper/sequence.hxx> @@ -115,8 +116,8 @@ uno::Sequence<OUString> ServiceDecl::getSupportedServiceNames() const OString const str(m_pServiceNames); sal_Int32 nIndex = 0; do { - OString const token( str.getToken( 0, cDelim, nIndex ) ); - vec.emplace_back( token.getStr(), token.getLength(), + std::string_view const token( o3tl::getToken(str, 0, cDelim, nIndex ) ); + vec.emplace_back( token.data(), token.size(), RTL_TEXTENCODING_ASCII_US ); } while (nIndex >= 0); @@ -124,13 +125,13 @@ uno::Sequence<OUString> ServiceDecl::getSupportedServiceNames() const return comphelper::containerToSequence(vec); } -bool ServiceDecl::supportsService( OUString const& name ) const +bool ServiceDecl::supportsService( std::u16string_view name ) const { OString const str(m_pServiceNames); sal_Int32 nIndex = 0; do { - OString const token( str.getToken( 0, cDelim, nIndex ) ); - if (name.equalsAsciiL( token.getStr(), token.getLength() )) + std::string_view const token( o3tl::getToken(str, 0, cDelim, nIndex ) ); + if (o3tl::equalsAscii(name, token)) return true; } while (nIndex >= 0); diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx index e108406b7d04..39475e715e5d 100644 --- a/connectivity/source/drivers/hsqldb/HDriver.cxx +++ b/connectivity/source/drivers/hsqldb/HDriver.cxx @@ -259,7 +259,7 @@ namespace connectivity if ( sLine.isEmpty() ) continue; sal_Int32 nIdx {0}; - const OString sIniKey = sLine.getToken(0, '=', nIdx); + const std::string_view sIniKey = o3tl::getToken(sLine, 0, '=', nIdx); const OString sValue = sLine.getToken(0, '=', nIdx); if( sIniKey == "hsqldb.compatible_version" ) { diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx index 2feb2d2688d1..7410ad38e6fc 100644 --- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx +++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx @@ -30,6 +30,7 @@ #include <cppuhelper/supportsservice.hxx> #include <cppuhelper/typeprovider.hxx> #include <comphelper/seqstream.hxx> +#include <o3tl/safeint.hxx> #include <o3tl/string_view.hxx> using namespace rtl; @@ -292,24 +293,23 @@ Date SAL_CALL OResultSet::getDate(sal_Int32 column) if (checkNull(column)) return d; - OString dateStr = m_aRows[m_nRowPosition][column - 1]; + const OString& dateStr = m_aRows[m_nRowPosition][column - 1]; - OString dateString(dateStr); - OString token; + std::string_view dateString(dateStr); sal_Int32 nIndex = 0, i = 0; do { - token = dateString.getToken(0, '-', nIndex); + std::string_view token = o3tl::getToken(dateString, 0, '-', nIndex); switch (i) { case 0: - d.Year = static_cast<sal_uInt16>(token.toUInt32()); + d.Year = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; case 1: - d.Month = static_cast<sal_uInt16>(token.toUInt32()); + d.Month = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; case 2: - d.Day = static_cast<sal_uInt16>(token.toUInt32()); + d.Day = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; default:; } @@ -467,25 +467,28 @@ Time SAL_CALL OResultSet::getTime(sal_Int32 column) if (checkNull(column)) return t; - OString sVal = m_aRows[m_nRowPosition][column - 1]; - OString timeString{ sVal.getStr(), getDataLength(column) }; - OString token; + const OString& sVal = m_aRows[m_nRowPosition][column - 1]; + std::string_view timeString{ sVal.getStr(), o3tl::make_unsigned(getDataLength(column)) }; sal_Int32 nIndex, i = 0; - nIndex = timeString.indexOf(' ') + 1; + size_t idx = timeString.find(' '); + if (idx == std::string_view::npos) + nIndex = 0; + else + nIndex = idx + 1; do { - token = timeString.getToken(0, ':', nIndex); + std::string_view token = o3tl::getToken(timeString, 0, ':', nIndex); switch (i) { case 0: - t.Hours = static_cast<sal_uInt16>(token.toUInt32()); + t.Hours = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; case 1: - t.Minutes = static_cast<sal_uInt16>(token.toUInt32()); + t.Minutes = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; case 2: - t.Seconds = static_cast<sal_uInt16>(token.toUInt32()); + t.Seconds = static_cast<sal_uInt16>(o3tl::toUInt32(token)); break; } i++; diff --git a/cppuhelper/source/loadsharedlibcomponentfactory.hxx b/cppuhelper/source/loadsharedlibcomponentfactory.hxx index 3678c32e76fb..d8c7bb55536b 100644 --- a/cppuhelper/source/loadsharedlibcomponentfactory.hxx +++ b/cppuhelper/source/loadsharedlibcomponentfactory.hxx @@ -26,7 +26,7 @@ namespace com::sun::star { namespace cppuhelper::detail { css::uno::Environment getEnvironment( - OUString const & name, OUString const & implementation); + OUString const & name, std::u16string_view implementation); void loadSharedLibComponentFactory( OUString const & uri, OUString const & environment, diff --git a/cppuhelper/source/shlib.cxx b/cppuhelper/source/shlib.cxx index 41af3dd80ebc..b270c62c5cb4 100644 --- a/cppuhelper/source/shlib.cxx +++ b/cppuhelper/source/shlib.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/registry/XRegistryKey.hpp> #include <cppuhelper/factory.hxx> #include <cppuhelper/shlib.hxx> +#include <o3tl/string_view.hxx> #include <osl/module.hxx> #include <sal/log.hxx> #include <uno/environment.hxx> @@ -46,17 +47,17 @@ #endif css::uno::Environment cppuhelper::detail::getEnvironment( - OUString const & name, OUString const & implementation) + OUString const & name, std::u16string_view implementation) { OUString n(name); - if (!implementation.isEmpty()) { + if (!implementation.empty()) { static char const * log = std::getenv("UNO_ENV_LOG"); if (log != nullptr && *log != 0) { OString imps(log); for (sal_Int32 i = 0; i != -1;) { - OString imp(imps.getToken(0, ';', i)); + std::string_view imp(o3tl::getToken(imps, 0, ';', i)); //TODO: this assumes UNO_ENV_LOG only contains ASCII characters: - if (implementation.equalsAsciiL(imp.getStr(), imp.getLength())) + if (o3tl::equalsAscii(implementation, imp)) { n += ":log"; break; @@ -73,7 +74,7 @@ namespace { css::uno::Environment getEnvironmentFromModule( osl::Module const & module, css::uno::Environment const & target, - OUString const & implementation, OUString const & prefix) + std::u16string_view implementation, OUString const & prefix) { char const * name = nullptr; css::uno::Environment env; @@ -402,7 +403,7 @@ void cppu::writeSharedLibComponentInfo( css::uno::Reference<css::uno::XInterface>()); } css::uno::Environment curEnv(css::uno::Environment::getCurrent()); - css::uno::Environment env(getEnvironmentFromModule(mod, curEnv, "", "")); + css::uno::Environment env(getEnvironmentFromModule(mod, curEnv, u"", "")); if (!(curEnv.is() && env.is())) { throw css::registry::CannotRegisterImplementationException( "cannot get environments", diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index d5713b8edbf7..50ae3a5da400 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -5219,7 +5219,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo SolarMutexGuard aGuard; SetLastExceptionMsg(); - OString aCommand(pCommand); + const std::string_view aCommand(pCommand); static constexpr OStringLiteral aViewRowColumnHeaders(".uno:ViewRowColumnHeaders"); static constexpr OStringLiteral aSheetGeometryData(".uno:SheetGeometryData"); static constexpr OStringLiteral aCellCursor(".uno:CellCursor"); @@ -5265,7 +5265,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo { return getRulerState(pThis); } - else if (aCommand.startsWith(aViewRowColumnHeaders)) + else if (o3tl::starts_with(aCommand, aViewRowColumnHeaders)) { ITiledRenderable* pDoc = getTiledRenderable(pThis); if (!pDoc) @@ -5275,38 +5275,38 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo } tools::Rectangle aRectangle; - if (aCommand.getLength() > aViewRowColumnHeaders.getLength()) + if (aCommand.size() > o3tl::make_unsigned(aViewRowColumnHeaders.getLength())) { // Command has parameters. int nX = 0; int nY = 0; int nWidth = 0; int nHeight = 0; - OString aArguments = aCommand.copy(aViewRowColumnHeaders.getLength() + 1); + std::string_view aArguments = aCommand.substr(aViewRowColumnHeaders.getLength() + 1); sal_Int32 nParamIndex = 0; do { - OString aParamToken = aArguments.getToken(0, '&', nParamIndex); + std::string_view aParamToken = o3tl::getToken(aArguments, 0, '&', nParamIndex); sal_Int32 nIndex = 0; - OString aKey; - OString aValue; + std::string_view aKey; + std::string_view aValue; do { - OString aToken = aParamToken.getToken(0, '=', nIndex); - if (!aKey.getLength()) + std::string_view aToken = o3tl::getToken(aParamToken, 0, '=', nIndex); + if (aKey.empty()) aKey = aToken; else aValue = aToken; } while (nIndex >= 0); if (aKey == "x") - nX = aValue.toInt32(); + nX = o3tl::toInt32(aValue); else if (aKey == "y") - nY = aValue.toInt32(); + nY = o3tl::toInt32(aValue); else if (aKey == "width") - nWidth = aValue.toInt32(); + nWidth = o3tl::toInt32(aValue); else if (aKey == "height") - nHeight = aValue.toInt32(); + nHeight = o3tl::toInt32(aValue); } while (nParamIndex >= 0); @@ -5317,7 +5317,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo pDoc->getRowColumnHeaders(aRectangle, aJsonWriter); return aJsonWriter.extractData(); } - else if (aCommand.startsWith(aSheetGeometryData)) + else if (o3tl::starts_with(aCommand, aSheetGeometryData)) { ITiledRenderable* pDoc = getTiledRenderable(pThis); if (!pDoc) @@ -5332,30 +5332,30 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo bool bHidden = true; bool bFiltered = true; bool bGroups = true; - if (aCommand.getLength() > aSheetGeometryData.getLength()) + if (aCommand.size() > o3tl::make_unsigned(aSheetGeometryData.getLength())) { bColumns = bRows = bSizes = bHidden = bFiltered = bGroups = false; - OString aArguments = aCommand.copy(aSheetGeometryData.getLength() + 1); + std::string_view aArguments = aCommand.substr(aSheetGeometryData.getLength() + 1); sal_Int32 nParamIndex = 0; do { - OString aParamToken = aArguments.getToken(0, '&', nParamIndex); + std::string_view aParamToken = o3tl::getToken(aArguments, 0, '&', nParamIndex); sal_Int32 nIndex = 0; - OString aKey; - OString aValue; + std::string_view aKey; + std::string_view aValue; do { - OString aToken = aParamToken.getToken(0, '=', nIndex); - if (!aKey.getLength()) + std::string_view aToken = o3tl::getToken(aParamToken, 0, '=', nIndex); + if (aKey.empty()) aKey = aToken; else aValue = aToken; } while (nIndex >= 0); - bool bEnableFlag = aValue.isEmpty() || - aValue.equalsIgnoreAsciiCase("true") || aValue.toInt32() > 0; + bool bEnableFlag = aValue.empty() || + o3tl::equalsIgnoreAsciiCase(aValue, "true") || o3tl::toInt32(aValue) > 0; if (!bEnableFlag) continue; @@ -5383,7 +5383,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo return convertOString(aGeomDataStr); } - else if (aCommand.startsWith(aCellCursor)) + else if (o3tl::starts_with(aCommand, aCellCursor)) { ITiledRenderable* pDoc = getTiledRenderable(pThis); if (!pDoc) @@ -5396,9 +5396,9 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo pDoc->getCellCursor(aJsonWriter); return aJsonWriter.extractData(); } - else if (aCommand.startsWith(aFontSubset)) + else if (o3tl::starts_with(aCommand, aFontSubset)) { - return getFontSubset(std::string_view(pCommand + aFontSubset.getLength())); + return getFontSubset(aCommand.substr(aFontSubset.getLength())); } else { diff --git a/include/comphelper/servicedecl.hxx b/include/comphelper/servicedecl.hxx index 94f5db000753..57da446e68b5 100644 --- a/include/comphelper/servicedecl.hxx +++ b/include/comphelper/servicedecl.hxx @@ -118,7 +118,7 @@ public: css::uno::Sequence< OUString> getSupportedServiceNames() const; /// @return whether name is in set of supported service names - bool supportsService( OUString const& name ) const; + bool supportsService( std::u16string_view name ) const; /// @return implementation name OUString getImplementationName() const; diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx index 026dc5e167ae..cea4f272b947 100644 --- a/include/o3tl/string_view.hxx +++ b/include/o3tl/string_view.hxx @@ -27,6 +27,13 @@ inline bool equalsAscii(std::u16string_view s1, const char* s2) return rtl_ustr_ascii_compare_WithLength(s1.data(), s1.size(), s2) == 0; } +// Like OUString::equalsAsciiL +inline bool equalsAscii(std::u16string_view s1, std::string_view s2) +{ + return rtl_ustr_ascii_shortenedCompare_WithLength(s1.data(), s1.size(), s2.data(), s2.size()) + == 0; +} + // Like OUString::equalsIgnoreAsciiCase, but for two std::u16string_view: inline bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2) { diff --git a/sfx2/source/bastyp/mieclip.cxx b/sfx2/source/bastyp/mieclip.cxx index 3036b4eb488e..580c6444d326 100644 --- a/sfx2/source/bastyp/mieclip.cxx +++ b/sfx2/source/bastyp/mieclip.cxx @@ -48,7 +48,7 @@ SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream ) while( rStream.ReadLine( sLine ) ) { nIndex = 0; - OString sTmp(sLine.getToken(0, ':', nIndex)); + std::string_view sTmp(o3tl::getToken(sLine, 0, ':', nIndex)); if (sTmp == "StartHTML") nStt = o3tl::toInt32(sLine.subView(nIndex)); else if (sTmp == "EndHTML") diff --git a/sw/source/core/layout/dbg_lay.cxx b/sw/source/core/layout/dbg_lay.cxx index d6e582b0ed03..cd17293ac048 100644 --- a/sw/source/core/layout/dbg_lay.cxx +++ b/sw/source/core/layout/dbg_lay.cxx @@ -106,6 +106,7 @@ #include <frame.hxx> #include <swtable.hxx> #include <ndtxt.hxx> +#include <o3tl/string_view.hxx> #include <rtl/strbuf.hxx> #include <sal/log.hxx> #include <tools/stream.hxx> @@ -330,7 +331,7 @@ void SwImplProtocol::CheckLine( OString& rLine ) return; if( '[' == rLine[0] ) // section: FrameIds, type or function { - OString aTmp = rLine.getToken(0, ']'); + std::string_view aTmp = o3tl::getToken(rLine, 0, ']'); if (aTmp == "[frmid") // section FrameIds { m_nInitFile = 1; @@ -362,23 +363,23 @@ void SwImplProtocol::CheckLine( OString& rLine ) } else m_nInitFile = 0; // oops: unknown section? - rLine = rLine.copy(aTmp.getLength() + 1); + rLine = rLine.copy(aTmp.size() + 1); } // spaces (or tabs) are the delimiter sal_Int32 nIndex = 0; do { - OString aTok = rLine.getToken( 0, ' ', nIndex ); + std::string_view aTok = o3tl::getToken(rLine, 0, ' ', nIndex ); bool bNo = false; - if( !aTok.isEmpty() && '!' == aTok[0] ) + if( !aTok.empty() && '!' == aTok[0] ) { bNo = true; // remove this function/type - aTok = aTok.copy(1); + aTok = aTok.substr(1); } - if( !aTok.isEmpty() ) + if( !aTok.empty() ) { - sal_Int64 nVal = aTok.toInt64(); + sal_Int64 nVal = o3tl::toInt64(aTok); switch (m_nInitFile) { case 1: InsertFrame( sal_uInt16( nVal ) ); // add FrameId diff --git a/vcl/unx/gtk3/gtksalmenu.cxx b/vcl/unx/gtk3/gtksalmenu.cxx index ac71e3390d87..619c24b20797 100644 --- a/vcl/unx/gtk3/gtksalmenu.cxx +++ b/vcl/unx/gtk3/gtksalmenu.cxx @@ -17,6 +17,7 @@ #include <vcl/pngwrite.hxx> #include <vcl/pdfwriter.hxx> // for escapeStringXML +#include <o3tl/string_view.hxx> #include <sal/log.hxx> #include <tools/stream.hxx> #include <window.h> @@ -76,16 +77,16 @@ namespace OString sCommand(action_name); sal_Int32 nIndex = 0; - OString sWindow = sCommand.getToken(0, '-', nIndex); - OString sGtkSalMenu = sCommand.getToken(0, '-', nIndex); - OString sItemId = sCommand.getToken(0, '-', nIndex); + std::string_view sWindow = o3tl::getToken(sCommand, 0, '-', nIndex); + std::string_view sGtkSalMenu = o3tl::getToken(sCommand, 0, '-', nIndex); + std::string_view sItemId = o3tl::getToken(sCommand, 0, '-', nIndex); - GtkSalMenu* pSalSubMenu = reinterpret_cast<GtkSalMenu*>(sGtkSalMenu.toInt64()); + GtkSalMenu* pSalSubMenu = reinterpret_cast<GtkSalMenu*>(o3tl::toInt64(sGtkSalMenu)); assert(sWindow == "window" && pSalSubMenu); (void) sWindow; - return MenuAndId(pSalSubMenu, sItemId.toInt32()); + return MenuAndId(pSalSubMenu, o3tl::toInt32(sItemId)); } } |