summaryrefslogtreecommitdiff
path: root/wizards/source
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2021-03-23 16:20:13 +0100
committerJean-Pierre Ledure <jp@ledure.be>2021-03-24 18:38:42 +0100
commit137b08799808d93614045aba7f7c2e77b7eaf9d3 (patch)
tree67f355a0c8b7606688614072fd6f28434c08d673 /wizards/source
parent8dded9c4c901118cb73bf59398f6fe08a73fa04a (diff)
ScriptForge - (scriptforge.py) String class
Only a subset of the available methods is implemented: HashStr, IsADate, IsEmail, IsFileName, IsIBAN, IsIPv4, IsLike, IsSheetName, IsUrl, SplitNotQuoted, Wrap The other methods are better replaced by Python builtin functions. The flgDateArg flag has been introduced to distinguish a date argument passed as a string that does not require conversion from a date passed in iso-format that requires a conversion to a Basic variable of type Date Change-Id: I80f7e816dfeaee793862f3c3d35488da7c573c8f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113002 Tested-by: Jean-Pierre Ledure <jp@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards/source')
-rw-r--r--wizards/source/scriptforge/SF_PythonHelper.xba5
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py64
2 files changed, 66 insertions, 3 deletions
diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba b/wizards/source/scriptforge/SF_PythonHelper.xba
index 7368390c97bf..5acd2dfc9228 100644
--- a/wizards/source/scriptforge/SF_PythonHelper.xba
+++ b/wizards/source/scriptforge/SF_PythonHelper.xba
@@ -558,6 +558,7 @@ Const cstNoArgs = &quot;+++NOARGS+++&quot;, cstSymEmpty = &quot;+++EMPTY+++&quot
&apos; Determines the CallType
Const vbGet = 2, vbLet = 4, vbMethod = 1, vbSet = 8
&apos; Protocol flags
+Const cstDateArg = 64 &apos; May contain a date argument
Const cstDateRet = 128 &apos; Return value can be a date
Const cstArgArray = 512 &apos; 1st argument can be a 2D array
Const cstRetArray = 1024 &apos; Return value can be an array
@@ -589,9 +590,9 @@ Check:
vArg = Null
ElseIf vArg = cstSymMissing Then
Exit For &apos; Next arguments must be missing also
- Else
+ ElseIf ( CallType And cstDateArg ) = cstDateArg Then &apos; Arguments might be dates
vArg = SF_Utils._CStrToDate(vArg)
- If vArg &lt; 0 Then vArg = Args(i) &apos;Conversion of iso format failed =&gt; forget
+ If vArg &lt; 0 Then vArg = Args(i) &apos; Conversion of iso format failed =&gt; reset
End If
End If
iNbArgs = iNbArgs + 1
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 14ba1e48c8db..92f214c34e52 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -360,6 +360,7 @@ class SFServices(object):
"""
# Python-Basic protocol constants and flags
vbGet, vbLet, vbMethod, vbSet = 2, 4, 1, 8 # CallByName constants
+ flgDateArg = 64 # Invoked service method may contain a date argument
flgDateRet = 128 # Invoked service method can return a date
flgArrayArg = 512 # 1st argument can be a 2D array
flgArrayRet = 1024 # Invoked service method can return a 2D array
@@ -764,7 +765,7 @@ class SFScriptForge:
result = []
for pv in iter(propertyvalues):
key = pv.Name
- if key not in self:
+ if overwrite is True or key not in self:
item = pv.Value
if 'com.sun.star.util.DateTime' in repr(type(item)):
item = datetime.datetime(item.Year, item.Month, item.Day,
@@ -1057,6 +1058,67 @@ class SFScriptForge:
processor = Processor
# #########################################################################
+ # SF_String CLASS
+ # #########################################################################
+ class SF_String(SFServices, metaclass = _Singleton):
+ """
+ Focus on string manipulation, regular expressions, encodings and hashing algorithms.
+ The methods implemented in Basic that are redundant with Python builtin functions
+ are not duplicated
+ """
+ # Mandatory class properties for service registration
+ serviceimplementation = 'basic'
+ servicename = 'ScriptForge.String'
+ servicesynonyms = ('string', 'scriptforge.string')
+ serviceproperties = dict()
+ propertysynonyms = SFServices._getAttributeSynonyms(serviceproperties)
+
+ def HashStr(self, inputstr, algorithm):
+ py = ScriptForge.pythonhelpermodule + '$' + '_SF_String__HashStr'
+ return self.SIMPLEEXEC(py, inputstr, algorithm.lower())
+ hashStr, hashstr = HashStr, HashStr
+
+ def IsADate(self, inputstr, dateformat = 'YYYY-MM-DD'):
+ return self.Execute(self.vbMethod, 'IsADate', inputstr, dateformat)
+ isADate, isadate = IsADate, IsADate
+
+ def IsEmail(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsEmail', inputstr)
+ isEmail, isemail = IsEmail, IsEmail
+
+ def IsFileName(self, inputstr, osname = ScriptForge.cstSymEmpty):
+ return self.Execute(self.vbMethod, 'IsFileName', inputstr, osname)
+ isFileName, isfilename = IsFileName, IsFileName
+
+ def IsIBAN(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsIBAN', inputstr)
+ isIBAN, isiban = IsIBAN, IsIBAN
+
+ def IsIPv4(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsIPv4', inputstr)
+ isIPv4, isipv4 = IsIPv4, IsIPv4
+
+ def IsLike(self, inputstr, pattern, casesensitive = False):
+ return self.Execute(self.vbMethod, 'IsLike', inputstr, pattern, casesensitive)
+ isLike, islike = IsLike, IsLike
+
+ def IsSheetName(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsSheetName', inputstr)
+ isSheetName, issheetname = IsSheetName, IsSheetName
+
+ def IsUrl(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsUrl', inputstr)
+ isUrl, isurl = IsUrl, IsUrl
+
+ def SplitNotQuoted(self, inputstr, delimiter = ' ', occurrences = 0, quotechar = '"'):
+ return self.Execute(self.vbMethod, 'SplitNotQuoted', inputstr, delimiter, occurrences, quotechar)
+ splitNotQuoted, splitnotquoted = SplitNotQuoted, SplitNotQuoted
+
+ def Wrap(self, inputstr, width = 70, tabsize = 8):
+ return self.Execute(self.vbMethod, 'Wrap', inputstr, width, tabsize)
+ wrap = Wrap
+
+ # #########################################################################
# SF_TextStream CLASS
# #########################################################################
class SF_TextStream(SFServices):