From 5200a73627d13e2997f81b53f61e143e77e328ee Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 29 Apr 2022 11:06:33 +0200 Subject: use more string_view in various found by examining uses of OUString::copy() for likely places Change-Id: I6ff20e7b273ad6005410b82719183c1122f8c018 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133617 Tested-by: Jenkins Reviewed-by: Noel Grandin --- ucb/source/ucp/ext/ucpext_content.cxx | 6 +++--- ucb/source/ucp/ext/ucpext_provider.cxx | 12 ++++++------ ucb/source/ucp/tdoc/tdoc_uri.hxx | 2 +- ucb/source/ucp/webdav-curl/CurlUri.cxx | 7 ++++--- 4 files changed, 14 insertions(+), 13 deletions(-) (limited to 'ucb') diff --git a/ucb/source/ucp/ext/ucpext_content.cxx b/ucb/source/ucp/ext/ucpext_content.cxx index 6bcfedd37c78..8dd120080133 100644 --- a/ucb/source/ucp/ext/ucpext_content.cxx +++ b/ucb/source/ucp/ext/ucpext_content.cxx @@ -119,9 +119,9 @@ namespace ucb::ucp::ext } else { - const OUString sRelativeURL( sURL.copy( ContentProvider::getRootURL().getLength() ) ); - const sal_Int32 nSepPos = sRelativeURL.indexOf( '/' ); - if ( ( nSepPos == -1 ) || ( nSepPos == sRelativeURL.getLength() - 1 ) ) + const std::u16string_view sRelativeURL( sURL.subView( ContentProvider::getRootURL().getLength() ) ); + const size_t nSepPos = sRelativeURL.find( '/' ); + if ( ( nSepPos == std::u16string_view::npos ) || ( nSepPos == sRelativeURL.size() - 1 ) ) { m_eExtContentType = E_EXTENSION_ROOT; } diff --git a/ucb/source/ucp/ext/ucpext_provider.cxx b/ucb/source/ucp/ext/ucpext_provider.cxx index eac919e4099b..765ea7856517 100644 --- a/ucb/source/ucp/ext/ucpext_provider.cxx +++ b/ucb/source/ucp/ext/ucpext_provider.cxx @@ -80,11 +80,11 @@ namespace ucb::ucp::ext namespace { - void lcl_ensureAndTransfer( OUString& io_rIdentifierFragment, OUStringBuffer& o_rNormalization, const sal_Unicode i_nLeadingChar ) + void lcl_ensureAndTransfer( std::u16string_view& io_rIdentifierFragment, OUStringBuffer& o_rNormalization, const sal_Unicode i_nLeadingChar ) { - if ( ( io_rIdentifierFragment.isEmpty() ) || ( io_rIdentifierFragment[0] != i_nLeadingChar ) ) + if ( ( io_rIdentifierFragment.empty() ) || ( io_rIdentifierFragment[0] != i_nLeadingChar ) ) throw IllegalIdentifierException(); - io_rIdentifierFragment = io_rIdentifierFragment.copy( 1 ); + io_rIdentifierFragment = io_rIdentifierFragment.substr( 1 ); o_rNormalization.append( i_nLeadingChar ); } } @@ -105,14 +105,14 @@ namespace ucb::ucp::ext aComposer.append( sIdentifier.copy( 0, sScheme.getLength() ).toAsciiLowerCase() ); // one : is required after the scheme - OUString sRemaining( sIdentifier.copy( sScheme.getLength() ) ); + std::u16string_view sRemaining( sIdentifier.subView( sScheme.getLength() ) ); lcl_ensureAndTransfer( sRemaining, aComposer, ':' ); // and at least one / lcl_ensureAndTransfer( sRemaining, aComposer, '/' ); // the normalized form requires one additional /, but we also accept identifiers which don't have it - if ( sRemaining.isEmpty() ) + if ( sRemaining.empty() ) { // the root content is a special case, it requires / aComposer.append( "//" ); @@ -128,7 +128,7 @@ namespace ucb::ucp::ext { lcl_ensureAndTransfer( sRemaining, aComposer, '/' ); // by now, we moved "vnd.sun.star.extension://" from the URL to aComposer - if ( sRemaining.isEmpty() ) + if ( sRemaining.empty() ) { // again, it's the root content, but one / is missing aComposer.append( '/' ); diff --git a/ucb/source/ucp/tdoc/tdoc_uri.hxx b/ucb/source/ucp/tdoc/tdoc_uri.hxx index d54bac37c267..8a459c0aef12 100644 --- a/ucb/source/ucp/tdoc/tdoc_uri.hxx +++ b/ucb/source/ucp/tdoc/tdoc_uri.hxx @@ -99,7 +99,7 @@ inline bool Uri::isDocument() const { init(); return ( ( !m_aDocId.isEmpty() ) /* not root */ - && ( m_aPath.copy( m_aDocId.getLength() + 1 ).getLength() < 2 ) ); + && ( m_aPath.subView( m_aDocId.getLength() + 1 ).size() < 2 ) ); } } // namespace tdoc_ucp diff --git a/ucb/source/ucp/webdav-curl/CurlUri.cxx b/ucb/source/ucp/webdav-curl/CurlUri.cxx index fcd3b652063c..4dba6ac221b7 100644 --- a/ucb/source/ucp/webdav-curl/CurlUri.cxx +++ b/ucb/source/ucp/webdav-curl/CurlUri.cxx @@ -246,7 +246,7 @@ CurlUri CurlUri::CloneWithRelativeRefPathAbsolute(OUString const& rRelativeRef) CURLUcode uc; if (indexFragment != -1) { - OUString const fragment(rRelativeRef.copy(indexFragment + 1)); + std::u16string_view const fragment(rRelativeRef.subView(indexFragment + 1)); indexEnd = indexFragment; OString const utf8Fragment(OUStringToOString(fragment, RTL_TEXTENCODING_UTF8)); uc = curl_url_set(pUrl.get(), CURLUPART_FRAGMENT, utf8Fragment.getStr(), 0); @@ -262,7 +262,8 @@ CurlUri CurlUri::CloneWithRelativeRefPathAbsolute(OUString const& rRelativeRef) } if (indexQuery != -1 && (indexFragment == -1 || indexQuery < indexFragment)) { - OUString const query(rRelativeRef.copy(indexQuery + 1, indexEnd - indexQuery - 1)); + std::u16string_view const query( + rRelativeRef.subView(indexQuery + 1, indexEnd - indexQuery - 1)); indexEnd = indexQuery; OString const utf8Query(OUStringToOString(query, RTL_TEXTENCODING_UTF8)); uc = curl_url_set(pUrl.get(), CURLUPART_QUERY, utf8Query.getStr(), 0); @@ -276,7 +277,7 @@ CurlUri CurlUri::CloneWithRelativeRefPathAbsolute(OUString const& rRelativeRef) SAL_WARN("ucb.ucp.webdav.curl", "curl_url_set failed: " << uc); throw DAVException(DAVException::DAV_INVALID_ARG); } - OUString const path(rRelativeRef.copy(0, indexEnd)); + std::u16string_view const path(rRelativeRef.subView(0, indexEnd)); OString const utf8Path(OUStringToOString(path, RTL_TEXTENCODING_UTF8)); uc = curl_url_set(pUrl.get(), CURLUPART_PATH, utf8Path.getStr(), 0); if (uc != CURLUE_OK) -- cgit