/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
while( !aVbaTextStrm.isEof() )
{
OUString aCodeLine = aVbaTextStrm.readLine(); if( aCodeLine.match( "Attribute " ) )
{ // attribute int index = aCodeLine.indexOf( ".VB_ProcData.VB_Invoke_Func = " ); if ( index != -1 )
{ // format is // 'Attribute Procedure.VB_ProcData.VB_Invoke_Func = "*\n14"' // where 'Procedure' is the procedure name and '*' is the shortcut key // note: his is only relevant for Excel, seems that // word doesn't store the shortcut in the module // attributes int nSpaceIndex = aCodeLine.indexOf(' ');
OUString sProc = aCodeLine.copy( nSpaceIndex + 1, index - nSpaceIndex - 1); // for Excel short cut key seems limited to cntrl+'a-z, A-Z'
std::u16string_view sKey = aCodeLine.subView( aCodeLine.lastIndexOf("= ") + 3, 1 ); // only alpha key valid for key shortcut, however the api will accept other keys if ( rtl::isAsciiAlpha( sKey[ 0 ] ) )
{ // cntrl modifier is explicit ( but could be cntrl+shift ), parseKeyEvent // will handle and uppercase letter appropriately
OUString sApiKey = OUString::Concat("^") + sKey;
maKeyBindings.push_back({sApiKey, sProc});
}
}
} else
{ // Hack here to weed out any unmatched End Sub / Sub Foo statements. // The behaviour of the vba ide practically guarantees the case and // spacing of Sub statement(s). However, indentation can be arbitrary hence // the trim.
OUString trimLine( aCodeLine.trim() ); if ( mbExecutable && (
trimLine.match("Sub ") ||
trimLine.match("Public Sub ") ||
trimLine.match("Private Sub ") ||
trimLine.match("Static Sub ") ) )
{ // this should never happen, basic doesn't support nested procedures // first Sub Foo must be bogus if ( procInfo.bInProcedure )
{ // comment out the line
aSourceCode.insert( procInfo.nPos, sUnmatchedRemovedTag ); // mark location of this Sub
procInfo.nPos = aSourceCode.getLength();
} else
{
procInfo.bInProcedure = true;
procInfo.nPos = aSourceCode.getLength();
}
} elseif ( mbExecutable && o3tl::starts_with(o3tl::trim(aCodeLine), u"End Sub") )
{ // un-matched End Sub if ( !procInfo.bInProcedure )
{
aSourceCode.append( sUnmatchedRemovedTag );
} else
{
procInfo.bInProcedure = false;
procInfo.nPos = 0;
}
} // normal source code line if( !mbExecutable )
aSourceCode.append( "Rem " );
aSourceCode.append( aCodeLine + "\n" );
}
}
}
} return aSourceCode.makeStringAndClear();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.