summaryrefslogtreecommitdiff
path: root/ucb/source/ucp/package
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-11-17 11:18:40 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-11-18 07:41:51 +0100
commit5e69b3619d3a2b05930c5b8b8521d7f2938c709d (patch)
tree2bcfb4244223b7fe570e9b0bcee2f7dd3928e226 /ucb/source/ucp/package
parent1d097883541b9d244e50ced7fe49a4d7a0f65cfd (diff)
loplugin:flatten in toolkit..writerfilter
Change-Id: I4da2a768b6b55869c3a3d6f8a8d50dc018709acd Reviewed-on: https://gerrit.libreoffice.org/44865 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'ucb/source/ucp/package')
-rw-r--r--ucb/source/ucp/package/pkguri.cxx277
1 files changed, 139 insertions, 138 deletions
diff --git a/ucb/source/ucp/package/pkguri.cxx b/ucb/source/ucp/package/pkguri.cxx
index 96c238d6758f..95cb0b7d8874 100644
--- a/ucb/source/ucp/package/pkguri.cxx
+++ b/ucb/source/ucp/package/pkguri.cxx
@@ -60,171 +60,172 @@ static void normalize( OUString& rURL )
void PackageUri::init() const
{
// Already inited?
- if ( !m_aUri.isEmpty() && m_aPath.isEmpty() )
+ if ( m_aUri.isEmpty() || !m_aPath.isEmpty() )
+ return;
+
+ // Note: Maybe it's a re-init, setUri only resets m_aPath!
+ m_aPackage.clear();
+ m_aParentUri.clear();
+ m_aName.clear();
+ m_aParam.clear();
+ m_aScheme.clear();
+
+ // URI must match at least: <sheme>://<non_empty_url_to_file>
+ if ( m_aUri.getLength() < PACKAGE_URL_SCHEME_LENGTH + 4 )
{
- // Note: Maybe it's a re-init, setUri only resets m_aPath!
- m_aPackage.clear();
- m_aParentUri.clear();
- m_aName.clear();
- m_aParam.clear();
- m_aScheme.clear();
-
- // URI must match at least: <sheme>://<non_empty_url_to_file>
- if ( m_aUri.getLength() < PACKAGE_URL_SCHEME_LENGTH + 4 )
+ // error, but remember that we did a init().
+ m_aPath = "/";
+ return;
+ }
+
+ // Scheme must be followed by '://'
+ if ( ( m_aUri[ PACKAGE_URL_SCHEME_LENGTH ] != ':' )
+ ||
+ ( m_aUri[ PACKAGE_URL_SCHEME_LENGTH + 1 ] != '/' )
+ ||
+ ( m_aUri[ PACKAGE_URL_SCHEME_LENGTH + 2 ] != '/' ) )
+ {
+ // error, but remember that we did a init().
+ m_aPath = "/";
+ return;
+ }
+
+ OUString aPureUri;
+ sal_Int32 nParam = m_aUri.indexOf( '?' );
+ if( nParam >= 0 )
+ {
+ m_aParam = m_aUri.copy( nParam );
+ aPureUri = m_aUri.copy( 0, nParam );
+ }
+ else
+ aPureUri = m_aUri;
+
+ // Scheme is case insensitive.
+ m_aScheme = aPureUri.copy(
+ 0, PACKAGE_URL_SCHEME_LENGTH ).toAsciiLowerCase();
+
+ if ( m_aScheme == PACKAGE_URL_SCHEME || m_aScheme == PACKAGE_ZIP_URL_SCHEME )
+ {
+ if ( m_aScheme == PACKAGE_ZIP_URL_SCHEME )
{
- // error, but remember that we did a init().
- m_aPath = "/";
- return;
+ m_aParam +=
+ ( !m_aParam.isEmpty()
+ ? OUString( "&purezip" )
+ : OUString( "?purezip" ) );
}
- // Scheme must be followed by '://'
- if ( ( m_aUri[ PACKAGE_URL_SCHEME_LENGTH ] != ':' )
- ||
- ( m_aUri[ PACKAGE_URL_SCHEME_LENGTH + 1 ] != '/' )
- ||
- ( m_aUri[ PACKAGE_URL_SCHEME_LENGTH + 2 ] != '/' ) )
+ aPureUri = aPureUri.replaceAt( 0,
+ m_aScheme.getLength(),
+ m_aScheme );
+
+ sal_Int32 nStart = PACKAGE_URL_SCHEME_LENGTH + 3;
+ sal_Int32 nEnd = aPureUri.lastIndexOf( '/' );
+ if ( nEnd == PACKAGE_URL_SCHEME_LENGTH + 3 )
{
+ // Only <scheme>:/// - Empty authority
+
// error, but remember that we did a init().
m_aPath = "/";
return;
}
-
- OUString aPureUri;
- sal_Int32 nParam = m_aUri.indexOf( '?' );
- if( nParam >= 0 )
+ else if ( nEnd == ( aPureUri.getLength() - 1 ) )
{
- m_aParam = m_aUri.copy( nParam );
- aPureUri = m_aUri.copy( 0, nParam );
- }
- else
- aPureUri = m_aUri;
-
- // Scheme is case insensitive.
- m_aScheme = aPureUri.copy(
- 0, PACKAGE_URL_SCHEME_LENGTH ).toAsciiLowerCase();
-
- if ( m_aScheme == PACKAGE_URL_SCHEME || m_aScheme == PACKAGE_ZIP_URL_SCHEME )
- {
- if ( m_aScheme == PACKAGE_ZIP_URL_SCHEME )
- {
- m_aParam +=
- ( !m_aParam.isEmpty()
- ? OUString( "&purezip" )
- : OUString( "?purezip" ) );
- }
-
- aPureUri = aPureUri.replaceAt( 0,
- m_aScheme.getLength(),
- m_aScheme );
-
- sal_Int32 nStart = PACKAGE_URL_SCHEME_LENGTH + 3;
- sal_Int32 nEnd = aPureUri.lastIndexOf( '/' );
- if ( nEnd == PACKAGE_URL_SCHEME_LENGTH + 3 )
+ if ( aPureUri[ aPureUri.getLength() - 2 ] == '/' )
{
- // Only <scheme>:/// - Empty authority
+ // Only <scheme>://// or <scheme>://<something>
// error, but remember that we did a init().
m_aPath = "/";
return;
}
- else if ( nEnd == ( aPureUri.getLength() - 1 ) )
- {
- if ( aPureUri[ aPureUri.getLength() - 2 ] == '/' )
- {
- // Only <scheme>://// or <scheme>://<something>
- // error, but remember that we did a init().
- m_aPath = "/";
- return;
- }
-
- // Remove trailing slash.
- aPureUri = aPureUri.copy( 0, nEnd );
- }
+ // Remove trailing slash.
+ aPureUri = aPureUri.copy( 0, nEnd );
+ }
- nEnd = aPureUri.indexOf( '/', nStart );
- if ( nEnd == -1 )
- {
- // root folder.
+ nEnd = aPureUri.indexOf( '/', nStart );
+ if ( nEnd == -1 )
+ {
+ // root folder.
- OUString aNormPackage = aPureUri.copy( nStart );
- normalize( aNormPackage );
+ OUString aNormPackage = aPureUri.copy( nStart );
+ normalize( aNormPackage );
- aPureUri = aPureUri.replaceAt(
- nStart, aPureUri.getLength() - nStart, aNormPackage );
- m_aPackage
- = ::ucb_impl::urihelper::decodeSegment( aNormPackage );
- m_aPath = "/";
- m_aUri = m_aUri.replaceAt( 0,
- ( nParam >= 0 )
- ? nParam
- : m_aUri.getLength(), aPureUri );
-
- sal_Int32 nLastSlash = m_aPackage.lastIndexOf( '/' );
- if ( nLastSlash != -1 )
- m_aName = ::ucb_impl::urihelper::decodeSegment(
- m_aPackage.copy( nLastSlash + 1 ) );
- else
- m_aName
- = ::ucb_impl::urihelper::decodeSegment( m_aPackage );
- }
+ aPureUri = aPureUri.replaceAt(
+ nStart, aPureUri.getLength() - nStart, aNormPackage );
+ m_aPackage
+ = ::ucb_impl::urihelper::decodeSegment( aNormPackage );
+ m_aPath = "/";
+ m_aUri = m_aUri.replaceAt( 0,
+ ( nParam >= 0 )
+ ? nParam
+ : m_aUri.getLength(), aPureUri );
+
+ sal_Int32 nLastSlash = m_aPackage.lastIndexOf( '/' );
+ if ( nLastSlash != -1 )
+ m_aName = ::ucb_impl::urihelper::decodeSegment(
+ m_aPackage.copy( nLastSlash + 1 ) );
else
- {
- m_aPath = aPureUri.copy( nEnd + 1 );
-
- // Unexpected sequences of characters:
- // - empty path segments
- // - encoded slashes
- // - parent folder segments ".."
- // - current folder segments "."
- if ( m_aPath.indexOf( "//" ) != -1
- || m_aPath.indexOf( "%2F" ) != -1
- || m_aPath.indexOf( "%2f" ) != -1
- || ::comphelper::OStorageHelper::PathHasSegment( m_aPath, ".." )
- || ::comphelper::OStorageHelper::PathHasSegment( m_aPath, "." ) )
- {
- // error, but remember that we did a init().
- m_aPath = "/";
- return;
- }
-
- OUString aNormPackage = aPureUri.copy( nStart, nEnd - nStart );
- normalize( aNormPackage );
-
- aPureUri = aPureUri.replaceAt(
- nStart, nEnd - nStart, aNormPackage );
- aPureUri = aPureUri.replaceAt(
- nEnd + 1,
- aPureUri.getLength() - nEnd - 1,
- ::ucb_impl::urihelper::encodeURI( m_aPath ) );
-
- m_aPackage
- = ::ucb_impl::urihelper::decodeSegment( aNormPackage );
- m_aPath = ::ucb_impl::urihelper::decodeSegment( m_aPath );
- m_aUri = m_aUri.replaceAt( 0,
- ( nParam >= 0 )
- ? nParam
- : m_aUri.getLength(), aPureUri );
-
- sal_Int32 nLastSlash = aPureUri.lastIndexOf( '/' );
- if ( nLastSlash != -1 )
- {
- m_aParentUri = aPureUri.copy( 0, nLastSlash );
- m_aName = ::ucb_impl::urihelper::decodeSegment(
- aPureUri.copy( nLastSlash + 1 ) );
- }
- }
-
- // success
- m_bValid = true;
+ m_aName
+ = ::ucb_impl::urihelper::decodeSegment( m_aPackage );
}
else
{
- // error, but remember that we did a init().
- m_aPath = "/";
+ m_aPath = aPureUri.copy( nEnd + 1 );
+
+ // Unexpected sequences of characters:
+ // - empty path segments
+ // - encoded slashes
+ // - parent folder segments ".."
+ // - current folder segments "."
+ if ( m_aPath.indexOf( "//" ) != -1
+ || m_aPath.indexOf( "%2F" ) != -1
+ || m_aPath.indexOf( "%2f" ) != -1
+ || ::comphelper::OStorageHelper::PathHasSegment( m_aPath, ".." )
+ || ::comphelper::OStorageHelper::PathHasSegment( m_aPath, "." ) )
+ {
+ // error, but remember that we did a init().
+ m_aPath = "/";
+ return;
+ }
+
+ OUString aNormPackage = aPureUri.copy( nStart, nEnd - nStart );
+ normalize( aNormPackage );
+
+ aPureUri = aPureUri.replaceAt(
+ nStart, nEnd - nStart, aNormPackage );
+ aPureUri = aPureUri.replaceAt(
+ nEnd + 1,
+ aPureUri.getLength() - nEnd - 1,
+ ::ucb_impl::urihelper::encodeURI( m_aPath ) );
+
+ m_aPackage
+ = ::ucb_impl::urihelper::decodeSegment( aNormPackage );
+ m_aPath = ::ucb_impl::urihelper::decodeSegment( m_aPath );
+ m_aUri = m_aUri.replaceAt( 0,
+ ( nParam >= 0 )
+ ? nParam
+ : m_aUri.getLength(), aPureUri );
+
+ sal_Int32 nLastSlash = aPureUri.lastIndexOf( '/' );
+ if ( nLastSlash != -1 )
+ {
+ m_aParentUri = aPureUri.copy( 0, nLastSlash );
+ m_aName = ::ucb_impl::urihelper::decodeSegment(
+ aPureUri.copy( nLastSlash + 1 ) );
+ }
}
+
+ // success
+ m_bValid = true;
}
+ else
+ {
+ // error, but remember that we did a init().
+ m_aPath = "/";
+ }
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */