The purpose of the macro is to run a regular expression over the string passed in and return the resulting string to the Basic macro.
Here is my Basic code:
Code: Select all
Sub CallJavaScript
Dim oScriptProvider, oScript
Dim aParams(), aOutParamIndex(), aOutParam()
Dim MyArray(2)
Dim MyParam As String
MyArray(0)="John O'Brien"
MyArray(1)="'"
MyArray(2)="''"
oScriptProvider = ThisComponent.getScriptProvider()
oScript = oScriptProvider.getScript( "vnd.sun.star.script:abpaJavaScripts.jsRegExp.js?language=JavaScript&location=document" )
oScript.invoke( MyArray, aOutParamIndex, aOutParam)
subInspect(oScript)
End Sub
Code: Select all
/*
* 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 .
*/
/* Applies strReplace to all instances of strRegexp in strSearch and returns the result */
function jsRegExp(strSearch, strRegexp, strReplace) {
var strRetVal;
strRetVal = strSearch.replace(strRegexp, strReplace);
return strRetVal;
}
Cheers,
Doug