1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "WinImplHelper.hxx"
23 #include <osl/diagnose.h>
24 #include <rtl/ustrbuf.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
27 using ::com::sun::star::lang::IllegalArgumentException
;
28 using ::com::sun::star::uno::Reference
;
29 using ::com::sun::star::uno::XInterface
;
30 using ::com::sun::star::uno::Any
;
31 using ::com::sun::star::uno::Sequence
;
33 const sal_Unicode TILDE_SIGN
= L
'~';
34 const sal_Unicode AMPERSAND_SIGN
= L
'&';
36 // OS NAME Platform Major Minor
38 // Windows NT 3.51 VER_PLATFORM_WIN32_NT 3 51
39 // Windows NT 4.0 VER_PLATFORM_WIN32_NT 4 0
40 // Windows 2000 VER_PLATFORM_WIN32_NT 5 0
41 // Windows XP VER_PLATFORM_WIN32_NT 5 1
42 // Windows Vista VER_PLATFORM_WIN32_NT 6 0
43 // Windows 7 VER_PLATFORM_WIN32_NT 6 1
44 // Windows 95 VER_PLATFORM_WIN32_WINDOWS 4 0
45 // Windows 98 VER_PLATFORM_WIN32_WINDOWS 4 10
46 // Windows ME VER_PLATFORM_WIN32_WINDOWS 4 90
49 static void Replace( const OUString
& aLabel
, sal_Unicode OldChar
, sal_Unicode NewChar
, OUStringBuffer
& aBuffer
)
51 OSL_ASSERT( aLabel
.getLength( ) );
52 OSL_ASSERT( aBuffer
.getCapacity( ) >= (aLabel
.getLength( )) );
55 const sal_Unicode
* pCurrent
= aLabel
.getStr( );
56 const sal_Unicode
* pNext
= aLabel
.getStr( ) + 1;
57 const sal_Unicode
* pEnd
= aLabel
.getStr( ) + aLabel
.getLength( );
59 while( pCurrent
< pEnd
)
61 OSL_ASSERT( pNext
<= pEnd
);
62 OSL_ASSERT( (i
>= 0) && (i
< aBuffer
.getCapacity( )) );
64 if ( OldChar
== *pCurrent
)
66 if ( OldChar
== *pNext
)
68 // two OldChars in line will
71 aBuffer
.insert( i
, *pCurrent
);
79 // one OldChar will be replace
81 aBuffer
.insert( i
, NewChar
);
84 else if ( *pCurrent
== NewChar
)
86 // a NewChar will be replaced by
89 aBuffer
.insert( i
++, *pCurrent
);
90 aBuffer
.insert( i
, *pCurrent
);
94 aBuffer
.insert( i
, *pCurrent
);
103 // converts a soffice label to a windows label
104 // the following rules for character replacements
110 OUString
SOfficeToWindowsLabel( const OUString
& aSOLabel
)
112 OUString aWinLabel
= aSOLabel
;
114 if ( (aWinLabel
.indexOf( TILDE_SIGN
) > -1) || (aWinLabel
.indexOf( AMPERSAND_SIGN
) > -1) )
116 sal_Int32 nStrLen
= aWinLabel
.getLength( );
118 // in the worst case the new string is
119 // doubled in length, maybe some waste
120 // of memory but how long is a label
122 OUStringBuffer
aBuffer( nStrLen
* 2 );
124 Replace( aWinLabel
, TILDE_SIGN
, AMPERSAND_SIGN
, aBuffer
);
126 aWinLabel
= aBuffer
.makeStringAndClear( );
132 // converts a windows label to a soffice label
133 // the following rules for character replacements
139 OUString
WindowsToSOfficeLabel( const OUString
& aWinLabel
)
141 OUString aSOLabel
= aWinLabel
;
143 if ( (aSOLabel
.indexOf( TILDE_SIGN
) > -1) || (aSOLabel
.indexOf( AMPERSAND_SIGN
) > -1) )
145 sal_Int32 nStrLen
= aSOLabel
.getLength( );
147 // in the worst case the new string is
148 // doubled in length, maybe some waste
149 // of memory but how long is a label
151 OUStringBuffer
aBuffer( nStrLen
* 2 );
153 Replace( aSOLabel
, AMPERSAND_SIGN
, TILDE_SIGN
, aBuffer
);
155 aSOLabel
= aBuffer
.makeStringAndClear( );
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */