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 const sal_Unicode TILDE_SIGN
= L
'~';
28 const sal_Unicode AMPERSAND_SIGN
= L
'&';
30 // OS NAME Platform Major Minor
32 // Windows NT 3.51 VER_PLATFORM_WIN32_NT 3 51
33 // Windows NT 4.0 VER_PLATFORM_WIN32_NT 4 0
34 // Windows 2000 VER_PLATFORM_WIN32_NT 5 0
35 // Windows XP VER_PLATFORM_WIN32_NT 5 1
36 // Windows Vista VER_PLATFORM_WIN32_NT 6 0
37 // Windows 7 VER_PLATFORM_WIN32_NT 6 1
38 // Windows 95 VER_PLATFORM_WIN32_WINDOWS 4 0
39 // Windows 98 VER_PLATFORM_WIN32_WINDOWS 4 10
40 // Windows ME VER_PLATFORM_WIN32_WINDOWS 4 90
43 static void Replace( const OUString
& aLabel
, sal_Unicode OldChar
, sal_Unicode NewChar
, OUStringBuffer
& aBuffer
)
45 OSL_ASSERT( aLabel
.getLength( ) );
46 OSL_ASSERT( aBuffer
.getCapacity( ) >= (aLabel
.getLength( )) );
49 const sal_Unicode
* pCurrent
= aLabel
.getStr( );
50 const sal_Unicode
* pNext
= aLabel
.getStr( ) + 1;
51 const sal_Unicode
* pEnd
= aLabel
.getStr( ) + aLabel
.getLength( );
53 while( pCurrent
< pEnd
)
55 OSL_ASSERT( pNext
<= pEnd
);
56 OSL_ASSERT( (i
>= 0) && (i
< aBuffer
.getCapacity( )) );
58 if ( OldChar
== *pCurrent
)
60 if ( OldChar
== *pNext
)
62 // two OldChars in line will
65 aBuffer
.insert( i
, *pCurrent
);
73 // one OldChar will be replace
75 aBuffer
.insert( i
, NewChar
);
78 else if ( *pCurrent
== NewChar
)
80 // a NewChar will be replaced by
83 aBuffer
.insert( i
++, *pCurrent
);
84 aBuffer
.insert( i
, *pCurrent
);
88 aBuffer
.insert( i
, *pCurrent
);
97 // converts a soffice label to a windows label
98 // the following rules for character replacements
104 OUString
SOfficeToWindowsLabel( const OUString
& aSOLabel
)
106 OUString aWinLabel
= aSOLabel
;
108 if ( (aWinLabel
.indexOf( TILDE_SIGN
) > -1) || (aWinLabel
.indexOf( AMPERSAND_SIGN
) > -1) )
110 sal_Int32 nStrLen
= aWinLabel
.getLength( );
112 // in the worst case the new string is
113 // doubled in length, maybe some waste
114 // of memory but how long is a label
116 OUStringBuffer
aBuffer( nStrLen
* 2 );
118 Replace( aWinLabel
, TILDE_SIGN
, AMPERSAND_SIGN
, aBuffer
);
120 aWinLabel
= aBuffer
.makeStringAndClear( );
126 // converts a windows label to a soffice label
127 // the following rules for character replacements
133 OUString
WindowsToSOfficeLabel( const OUString
& aWinLabel
)
135 OUString aSOLabel
= aWinLabel
;
137 if ( (aSOLabel
.indexOf( TILDE_SIGN
) > -1) || (aSOLabel
.indexOf( AMPERSAND_SIGN
) > -1) )
139 sal_Int32 nStrLen
= aSOLabel
.getLength( );
141 // in the worst case the new string is
142 // doubled in length, maybe some waste
143 // of memory but how long is a label
145 OUStringBuffer
aBuffer( nStrLen
* 2 );
147 Replace( aSOLabel
, AMPERSAND_SIGN
, TILDE_SIGN
, aBuffer
);
149 aSOLabel
= aBuffer
.makeStringAndClear( );
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */