summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/inc/comphelper/storagehelper.hxx2
-rw-r--r--comphelper/source/misc/storagehelper.cxx31
2 files changed, 33 insertions, 0 deletions
diff --git a/comphelper/inc/comphelper/storagehelper.hxx b/comphelper/inc/comphelper/storagehelper.hxx
index b613ddd2c5f1..b7e5704c4d68 100644
--- a/comphelper/inc/comphelper/storagehelper.hxx
+++ b/comphelper/inc/comphelper/storagehelper.hxx
@@ -161,6 +161,8 @@ public:
static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed );
static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed );
+
+ static sal_Bool PathHasSegment( const ::rtl::OUString& aPath, const ::rtl::OUString& aSegment );
};
}
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx
index e2557523f674..db5ba71cd876 100644
--- a/comphelper/source/misc/storagehelper.cxx
+++ b/comphelper/source/misc/storagehelper.cxx
@@ -452,5 +452,36 @@ sal_Bool OStorageHelper::IsValidZipEntryFileName(
return sal_True;
}
+// ----------------------------------------------------------------------
+sal_Bool OStorageHelper::PathHasSegment( const ::rtl::OUString& aPath, const ::rtl::OUString& aSegment )
+{
+ sal_Bool bResult = sal_False;
+ const sal_Int32 nPathLen = aPath.getLength();
+ const sal_Int32 nSegLen = aSegment.getLength();
+
+ if ( nSegLen && nPathLen >= nSegLen )
+ {
+ ::rtl::OUString aEndSegment( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
+ aEndSegment += aSegment;
+
+ ::rtl::OUString aInternalSegment( aEndSegment );
+ aInternalSegment += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
+
+ if ( aPath.indexOf( aInternalSegment ) >= 0 )
+ bResult = sal_True;
+
+ if ( !bResult && !aPath.compareTo( aSegment, nSegLen ) )
+ {
+ if ( nPathLen == nSegLen || aPath.getStr()[nSegLen] == (sal_Unicode)'/' )
+ bResult = sal_True;
+ }
+
+ if ( !bResult && nPathLen > nSegLen && aPath.copy( nPathLen - nSegLen - 1, nSegLen + 1 ).equals( aEndSegment ) )
+ bResult = sal_True;
+ }
+
+ return bResult;
+}
+
}