diff options
author | Tino Rachui <tra@openoffice.org> | 2001-08-10 11:27:57 +0000 |
---|---|---|
committer | Tino Rachui <tra@openoffice.org> | 2001-08-10 11:27:57 +0000 |
commit | a6f6021fc64e409c2998b6dc8892dcd0c3d3fc7e (patch) | |
tree | 02680472057db91bfb603ab97925580a12567e9d /fpicker/source/win32/misc/WinImplHelper.cxx | |
parent | de856df34d2b60de8d17c436a17924164cf49a1a (diff) |
#89230#added methods to changed soffice labels with special chars to windows labels with special chars and vice versa
Diffstat (limited to 'fpicker/source/win32/misc/WinImplHelper.cxx')
-rw-r--r-- | fpicker/source/win32/misc/WinImplHelper.cxx | 139 |
1 files changed, 137 insertions, 2 deletions
diff --git a/fpicker/source/win32/misc/WinImplHelper.cxx b/fpicker/source/win32/misc/WinImplHelper.cxx index e8e6ecfed91f..e0037fb4c1e6 100644 --- a/fpicker/source/win32/misc/WinImplHelper.cxx +++ b/fpicker/source/win32/misc/WinImplHelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: WinImplHelper.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: tra $ $Date: 2001-06-28 11:11:06 $ + * last change: $Author: tra $ $Date: 2001-08-10 12:27:57 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,6 +67,10 @@ #include <osl/diagnose.h> #endif +#ifndef _RTL_USTRBUF_HXX_ +#include <rtl/ustrbuf.hxx> +#endif + #ifndef _AUTO_BUFFER_HXX_ #include "AutoBuffer.hxx" #endif @@ -86,6 +90,7 @@ //------------------------------------------------------------ using rtl::OUString; +using rtl::OUStringBuffer; using ::com::sun::star::lang::IllegalArgumentException; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::XInterface; @@ -93,6 +98,15 @@ using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Sequence; //------------------------------------------------------------ +// +//------------------------------------------------------------ + +const rtl::OUString TILDE = OUString::createFromAscii( "~" ); +const sal_Unicode TILDE_SIGN = L'~'; +const rtl::OUString AMPERSAND = OUString::createFromAscii( "&" ); +const sal_Unicode AMPERSAND_SIGN = L'&'; + +//------------------------------------------------------------ // determine if we are running under Win2000 //------------------------------------------------------------ @@ -401,3 +415,124 @@ sal_uInt32 SAL_CALL _wcslenex( const sal_Unicode* pStr ) return strLen; } + +//------------------------------------------------------------ +// +//------------------------------------------------------------ + +void Replace( const OUString& aLabel, sal_Unicode OldChar, sal_Unicode NewChar, OUStringBuffer& aBuffer ) +{ + OSL_ASSERT( aLabel.getLength( ) ); + OSL_ASSERT( aBuffer.getCapacity( ) >= (aLabel.getLength( )) ); + + sal_Int32 i = 0; + const sal_Unicode* pCurrent = aLabel.getStr( ); + const sal_Unicode* pNext = aLabel.getStr( ) + 1; + const sal_Unicode* pEnd = aLabel.getStr( ) + aLabel.getLength( ); + + while( pCurrent < pEnd ) + { + OSL_ASSERT( pNext <= pEnd ); + OSL_ASSERT( (i >= 0) && (i < aBuffer.getCapacity( )) ); + + if ( OldChar == *pCurrent ) + { + if ( OldChar == *pNext ) + { + // two OldChars in line will + // be replaced by one + // e.g. ~~ -> ~ + aBuffer.insert( i, *pCurrent ); + + // skip the next one + pCurrent++; + pNext++; + } + else + { + // one OldChar will be replace + // by NexChar + aBuffer.insert( i, NewChar ); + } + } + else if ( *pCurrent == NewChar ) + { + // a NewChar will be replaced by + // two NewChars + // e.g. & -> && + aBuffer.insert( i++, *pCurrent ); + aBuffer.insert( i, *pCurrent ); + } + else + { + aBuffer.insert( i, *pCurrent ); + } + + pCurrent++; + pNext++; + i++; + } +} + +//------------------------------------------------------------ +// converts a soffice label to a windows label +// the following rules for character replacements +// will be done: +// '~' -> '&' +// '~~' -> '~' +// '&' -> '&&' +//------------------------------------------------------------ + +OUString SOfficeToWindowsLabel( const rtl::OUString& aSOLabel ) +{ + OUString aWinLabel = aSOLabel; + + if ( (aWinLabel.indexOf( TILDE ) > -1) || (aWinLabel.indexOf( AMPERSAND ) > -1) ) + { + sal_Int32 nStrLen = aWinLabel.getLength( ); + + // in the worst case the new string is + // doubled in length, maybe some waste + // of memory but how long is a label + // normaly(?) + rtl::OUStringBuffer aBuffer( nStrLen * 2 ); + + Replace( aWinLabel, TILDE_SIGN, AMPERSAND_SIGN, aBuffer ); + + aWinLabel = aBuffer.makeStringAndClear( ); + } + + return aWinLabel; +} + +//------------------------------------------------------------ +// converts a windows label to a soffice label +// the following rules for character replacements +// will be done: +// '&' -> '~' +// '&&' -> '&' +// '~' -> '~~' +//------------------------------------------------------------ + +OUString WindowsToSOfficeLabel( const rtl::OUString& aWinLabel ) +{ + OUString aSOLabel = aWinLabel; + + if ( (aSOLabel.indexOf( TILDE ) > -1) || (aSOLabel.indexOf( AMPERSAND ) > -1) ) + { + sal_Int32 nStrLen = aSOLabel.getLength( ); + + // in the worst case the new string is + // doubled in length, maybe some waste + // of memory but how long is a label + // normaly(?) + rtl::OUStringBuffer aBuffer( nStrLen * 2 ); + + Replace( aSOLabel, AMPERSAND_SIGN, TILDE_SIGN, aBuffer ); + + aSOLabel = aBuffer.makeStringAndClear( ); + } + + return aSOLabel; +} + |