diff options
author | Matthias Huetsch <mhu@openoffice.org> | 2001-08-15 15:38:18 +0000 |
---|---|---|
committer | Matthias Huetsch <mhu@openoffice.org> | 2001-08-15 15:38:18 +0000 |
commit | 3a60b7fd9c48a27026af228c3b67bdcffd10a761 (patch) | |
tree | 1bd15bda7fe908a4c0d07975f744b6e00fa7b3c2 /ucb | |
parent | 34de7d8e6f2952842ae46c45e5166ffd6fb6c8dd (diff) |
#90503# Fixed 'makeAbsolutePath()' to use 'OUStringBuffer' for token reassembly.
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/ucp/file/filglob.cxx | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/ucb/source/ucp/file/filglob.cxx b/ucb/source/ucp/file/filglob.cxx index 7537007499db..fe56da3369ad 100644 --- a/ucb/source/ucp/file/filglob.cxx +++ b/ucb/source/ucp/file/filglob.cxx @@ -62,8 +62,8 @@ #ifndef _OSL_DIAGNOSE_H_ #include "osl/diagnose.h" #endif -#ifndef _RTL_USTRING_H_ -#include "rtl/ustring.h" +#ifndef _RTL_USTRBUF_HXX_ +#include "rtl/ustrbuf.hxx" #endif #ifndef _RTL_USTRING_HXX_ #include "rtl/ustring.hxx" @@ -262,23 +262,38 @@ namespace fileaccess { //---------------------------------------------------------------------------- - sal_Bool SAL_CALL makeAbsolutePath( const rtl::OUString& aRelPath, rtl::OUString& aAbsPath ) + sal_Bool SAL_CALL makeAbsolutePath( const rtl::OUString& aRelPath, + rtl::OUString& aAbsPath ) { - sal_Int32 nIndex = 6; - - std::vector< rtl::OUString > aTokenStack; - // should no longer happen - OSL_ASSERT( 0 != aRelPath.compareTo( rtl::OUString::createFromAscii( "//./" ), 4 ) ); + OSL_ASSERT( 0 != aRelPath.compareToAscii( "//./" , 4 ) ); - if ( 0 != aRelPath.compareTo( rtl::OUString::createFromAscii( "file://" ), 7 ) ) + if ( 0 != aRelPath.compareToAscii( "file://" , 7 ) ) return sal_False; - aRelPath.getToken( 0, '/', nIndex ); + // The 'upward' ('/../') pattern. + static const sal_Unicode pattern[5] = + { + '/', '.', '.', '/', 0 + }; + // Ensure 'relative path' contains 'pattern'. + if (rtl_ustr_indexOfStr_WithLength ( + aRelPath.getStr(), aRelPath.getLength(), pattern, 4) < 0) + { + // Path already absolute. + aAbsPath = aRelPath; + return sal_True; + } + + // Tokenize 'relative path'. + std::vector< rtl::OUString > aTokenStack; + sal_Int32 nIndex = 6; + + aRelPath.getToken( 0, '/', nIndex ); while ( nIndex >= 0 ) { - rtl::OUString aToken = aRelPath.getToken( 0, '/', nIndex ); + rtl::OUString aToken (aRelPath.getToken( 0, '/', nIndex )); if ( aToken.compareToAscii( ".." ) == 0 ) aTokenStack.pop_back(); @@ -286,16 +301,19 @@ namespace fileaccess { aTokenStack.push_back( aToken ); } + // Reassemble as 'absolute path'. + rtl::OUStringBuffer aBuffer (aRelPath.getLength()); + aBuffer.appendAscii ("file:/", 6); - std::vector< rtl::OUString >::iterator it; - aAbsPath = rtl::OUString::createFromAscii("file:/"); - - for ( it = aTokenStack.begin(); it != aTokenStack.end(); it++ ) + std::vector< rtl::OUString >::const_iterator it; + for (it = aTokenStack.begin(); it != aTokenStack.end(); ++it) { - aAbsPath += rtl::OUString::createFromAscii( "/" ); - aAbsPath += *it; + aBuffer.append (sal_Unicode('/')); + aBuffer.append (*it); } + aAbsPath = aBuffer.makeStringAndClear(); + return sal_True; } |