LibreOffice Module fpicker (master) 1
WinImplHelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "WinImplHelper.hxx"
21
22#include <vector>
23#include <osl/diagnose.h>
24#include <rtl/ustrbuf.hxx>
25#include <com/sun/star/uno/Sequence.hxx>
26
29
30// OS NAME Platform Major Minor
31
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
41
42
43static void Replace( const OUString& aLabel, sal_Unicode OldChar, sal_Unicode NewChar, OUStringBuffer& aBuffer )
44{
45 OSL_ASSERT( aLabel.getLength( ) );
46 OSL_ASSERT( aBuffer.getCapacity( ) >= (aLabel.getLength( )) );
47
48 sal_Int32 i = 0;
49 const sal_Unicode* pCurrent = aLabel.getStr( );
50 const sal_Unicode* pNext = aLabel.getStr( ) + 1;
51 const sal_Unicode* pEnd = aLabel.getStr( ) + aLabel.getLength( );
52
53 while( pCurrent < pEnd )
54 {
55 OSL_ASSERT( pNext <= pEnd );
56 OSL_ASSERT( (i >= 0) && (i < aBuffer.getCapacity( )) );
57
58 if ( OldChar == *pCurrent )
59 {
60 if ( OldChar == *pNext )
61 {
62 // two OldChars in line will
63 // be replaced by one
64 // e.g. ~~ -> ~
65 aBuffer.insert( i, *pCurrent );
66
67 // skip the next one
68 pCurrent++;
69 pNext++;
70 }
71 else
72 {
73 // one OldChar will be replace
74 // by NexChar
75 aBuffer.insert( i, NewChar );
76 }
77 }
78 else if ( *pCurrent == NewChar )
79 {
80 // a NewChar will be replaced by
81 // two NewChars
82 // e.g. & -> &&
83 aBuffer.insert( i++, *pCurrent );
84 aBuffer.insert( i, *pCurrent );
85 }
86 else
87 {
88 aBuffer.insert( i, *pCurrent );
89 }
90
91 pCurrent++;
92 pNext++;
93 i++;
94 }
95}
96
97// converts a soffice label to a windows label
98// the following rules for character replacements
99// will be done:
100// '~' -> '&'
101// '~~' -> '~'
102// '&' -> '&&'
103
104OUString SOfficeToWindowsLabel( const OUString& aSOLabel )
105{
106 OUString aWinLabel = aSOLabel;
107
108 if ( (aWinLabel.indexOf( TILDE_SIGN ) > -1) || (aWinLabel.indexOf( AMPERSAND_SIGN ) > -1) )
109 {
110 sal_Int32 nStrLen = aWinLabel.getLength( );
111
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
115 // normally(?)
116 OUStringBuffer aBuffer( nStrLen * 2 );
117
119
120 aWinLabel = aBuffer.makeStringAndClear( );
121 }
122
123 return aWinLabel;
124}
125
126// converts a windows label to a soffice label
127// the following rules for character replacements
128// will be done:
129// '&' -> '~'
130// '&&' -> '&'
131// '~' -> '~~'
132
133OUString WindowsToSOfficeLabel( const OUString& aWinLabel )
134{
135 OUString aSOLabel = aWinLabel;
136
137 if ( (aSOLabel.indexOf( TILDE_SIGN ) > -1) || (aSOLabel.indexOf( AMPERSAND_SIGN ) > -1) )
138 {
139 sal_Int32 nStrLen = aSOLabel.getLength( );
140
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
144 // normally(?)
145 OUStringBuffer aBuffer( nStrLen * 2 );
146
148
149 aSOLabel = aBuffer.makeStringAndClear( );
150 }
151
152 return aSOLabel;
153}
154
155/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Unicode AMPERSAND_SIGN
OUString WindowsToSOfficeLabel(const OUString &aWinLabel)
OUString SOfficeToWindowsLabel(const OUString &aSOLabel)
static void Replace(const OUString &aLabel, sal_Unicode OldChar, sal_Unicode NewChar, OUStringBuffer &aBuffer)
const sal_Unicode TILDE_SIGN
int i
sal_uInt16 sal_Unicode
OUString aLabel
std::unique_ptr< char[]> aBuffer