forked from svan-jansson/cRegex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcRegex.pkg
More file actions
329 lines (276 loc) · 10.4 KB
/
cRegex.pkg
File metadata and controls
329 lines (276 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// cRegex class v1.03:
// By Erik Svensson, posted on eriksven.com in March 2013
// License: MIT
Define cREGEX_INCLUDED for 1
// Visual DataFlex COM proxy classes generated from C:\Windows\system32\vbscript.dll\2
Use FlexCom20.pkg
// CLSID: {3F4DACA0-160D-11D2-A8E9-00104B365C9F}
Class cComIRegularExpressions is a Mixin
{ MethodType=Property DesignTime=False }
Function ComPattern Returns String
Handle hDispatchDriver
String retVal
Get phDispatchDriver to hDispatchDriver
Get InvokeComMethod of hDispatchDriver 10001 OLE_VT_BSTR to retVal
Function_Return retVal
End_Function
{ MethodType=Property DesignTime=False }
Procedure Set ComPattern String value
Handle hDispatchDriver
Get phDispatchDriver to hDispatchDriver
Send PrepareParams to hDispatchDriver 1
Set ComProperty of hDispatchDriver 10001 OLE_VT_BSTR to value
End_Procedure
{ MethodType=Property DesignTime=False }
Function ComIgnoreCase Returns Boolean
Handle hDispatchDriver
Boolean retVal
Get phDispatchDriver to hDispatchDriver
Get InvokeComMethod of hDispatchDriver 10002 OLE_VT_BOOL to retVal
Function_Return retVal
End_Function
{ MethodType=Property DesignTime=False }
Procedure Set ComIgnoreCase Boolean value
Handle hDispatchDriver
Get phDispatchDriver to hDispatchDriver
Send PrepareParams to hDispatchDriver 1
Set ComProperty of hDispatchDriver 10002 OLE_VT_BOOL to value
End_Procedure
{ MethodType=Property DesignTime=False }
Function ComGlobal Returns Boolean
Handle hDispatchDriver
Boolean retVal
Get phDispatchDriver to hDispatchDriver
Get InvokeComMethod of hDispatchDriver 10003 OLE_VT_BOOL to retVal
Function_Return retVal
End_Function
{ MethodType=Property DesignTime=False }
Procedure Set ComGlobal Boolean value
Handle hDispatchDriver
Get phDispatchDriver to hDispatchDriver
Send PrepareParams to hDispatchDriver 1
Set ComProperty of hDispatchDriver 10003 OLE_VT_BOOL to value
End_Procedure
Function ComExecute String llsourceString Returns Variant
Handle hDispatchDriver
Variant retVal
Get phDispatchDriver to hDispatchDriver
Send PrepareParams to hDispatchDriver 1
Send DefineParam to hDispatchDriver OLE_VT_BSTR llsourceString
Get InvokeComMethod of hDispatchDriver 10004 OLE_VT_DISPATCH to retVal
Function_Return retVal
End_Function
Function ComTest String llsourceString Returns Boolean
Handle hDispatchDriver
Boolean retVal
Get phDispatchDriver to hDispatchDriver
Send PrepareParams to hDispatchDriver 1
Send DefineParam to hDispatchDriver OLE_VT_BSTR llsourceString
Get InvokeComMethod of hDispatchDriver 10005 OLE_VT_BOOL to retVal
Function_Return retVal
End_Function
Function ComReplace String llsourceString String llreplaceString Returns String
Handle hDispatchDriver
String retVal
Get phDispatchDriver to hDispatchDriver
Send PrepareParams to hDispatchDriver 2
Send DefineParam to hDispatchDriver OLE_VT_BSTR llsourceString
Send DefineParam to hDispatchDriver OLE_VT_BSTR llreplaceString
Get InvokeComMethod of hDispatchDriver 10006 OLE_VT_BSTR to retVal
Function_Return retVal
End_Function
End_Class
// CoClass
// ProgID: VBScript.RegExp
// CLSID: {3F4DACA4-160D-11D2-A8E9-00104B365C9F}
Class cComRegularExpressions is a cComAutomationObject
Import_Class_Protocol cComIRegularExpressions
Procedure Construct_Object
Forward Send Construct_Object
Set psProgID to "{3F4DACA4-160D-11D2-A8E9-00104B365C9F}"
Set peAutoCreate to acNoAutoCreate
End_Procedure
End_Class
// CLSID: {3F4DACA1-160D-11D2-A8E9-00104B365C9F}
Class cComIRegExMatch is a Mixin
{ MethodType=Property DesignTime=False }
Function ComValue Returns String
Handle hDispatchDriver
String retVal
Get phDispatchDriver to hDispatchDriver
Get InvokeComMethod of hDispatchDriver 0 OLE_VT_BSTR to retVal
Function_Return retVal
End_Function
{ MethodType=Property DesignTime=False }
Function ComFirstIndex Returns Integer
Handle hDispatchDriver
Integer retVal
Get phDispatchDriver to hDispatchDriver
Get InvokeComMethod of hDispatchDriver 10001 OLE_VT_I4 to retVal
Function_Return retVal
End_Function
{ MethodType=Property DesignTime=False }
Function ComLength Returns Integer
Handle hDispatchDriver
Integer retVal
Get phDispatchDriver to hDispatchDriver
Get InvokeComMethod of hDispatchDriver 10002 OLE_VT_I4 to retVal
Function_Return retVal
End_Function
End_Class
// CoClass
// CLSID: {3F4DACA5-160D-11D2-A8E9-00104B365C9F}
Class cComRegExMatch is a cComAutomationObject
Import_Class_Protocol cComIRegExMatch
Procedure Construct_Object
Forward Send Construct_Object
Set peAutoCreate to acNoAutoCreate
End_Procedure
End_Class
// CLSID: {3F4DACA2-160D-11D2-A8E9-00104B365C9F}
Class cComIRegExMatchCollection is a Mixin
{ MethodType=Property DesignTime=False }
Function ComItem Integer llindex Returns Variant
Handle hDispatchDriver
Variant retVal
Get phDispatchDriver to hDispatchDriver
Send PrepareParams to hDispatchDriver 1
Send DefineParam to hDispatchDriver OLE_VT_I4 llindex
Get InvokeComMethod of hDispatchDriver 0 OLE_VT_DISPATCH to retVal
Function_Return retVal
End_Function
{ MethodType=Property DesignTime=False }
Function ComCount Returns Integer
Handle hDispatchDriver
Integer retVal
Get phDispatchDriver to hDispatchDriver
Get InvokeComMethod of hDispatchDriver 1 OLE_VT_I4 to retVal
Function_Return retVal
End_Function
{ MethodType=Property DesignTime=False }
Function Com_NewEnum Returns Variant
Handle hDispatchDriver
Variant retVal
Get phDispatchDriver to hDispatchDriver
Get InvokeComMethod of hDispatchDriver -4 OLE_VT_UNKNOWN to retVal
Function_Return retVal
End_Function
End_Class
// CoClass
// CLSID: {3F4DACA6-160D-11D2-A8E9-00104B365C9F}
Class cComRegExMatchCollection is a cComAutomationObject
Import_Class_Protocol cComIRegExMatchCollection
Procedure Construct_Object
Forward Send Construct_Object
Set peAutoCreate to acNoAutoCreate
End_Procedure
End_Class
//Wrapper
Class cRegularExpressions is a cObject
Procedure Construct_Object
Variant vMyVar
Handle hoRegExp
Forward Send Construct_Object
Property String psPattern ""
Property Boolean pbIgnoreCase False
Property Handle phRegex 0
Property Boolean pbGlobalFind False
Get Create U_cComRegularExpressions to hoRegExp
Send CreateComObject of hoRegExp
Set phRegex to hoRegExp
End_Procedure
Procedure Set Pattern String sPattern
Set psPattern to sPattern
Set ComPattern of (phRegex(Self)) to sPattern
End_Procedure
Procedure Set IgnoreCase Boolean bVal
Set ComIgnoreCase of (phRegex(Self)) to bVal
End_Procedure
Procedure Set GlobalFind Boolean bVal
Set ComGlobal of (phRegex(Self)) to bVal
End_Procedure
Function Test String sSource Returns Boolean
Function_Return (ComTest(phRegex(Self),sSource))
End_Procedure
Function StringReplace String sSource String sWith Returns String
Function_Return (ComReplace(phRegex(Self),sSource,sWith))
End_Function
End_Class
//Global functions
Function Regex_Replace Global String sSource String sReplaceWith String sPattern Boolean bIgnoreCase Returns String
Handle hRegEx
String sRetVal
Get Create U_cRegularExpressions to hRegEx
If (hRegEx > 0) Begin
If (num_arguments = 4) Begin
Set IgnoreCase of hRegEx to bIgnoreCase
End
Set Pattern of hRegEx to sPattern
Set GlobalFind of hRegEx to True
Get StringReplace of hRegEx sSource sReplaceWith to sRetVal
Send Destroy of hRegEx
End
Else Begin
Error 999 "Cound not instatiate cRegex class"
End
Function_Return sRetVal
End_Function
Function Regex_IsMatch Global String sInput String sPattern Boolean bIgnoreCase Returns Boolean
Handle hRegEx
Boolean bIsMatch
Get Create U_cRegularExpressions to hRegEx
If (hRegEx > 0) Begin
If (num_arguments = 3) Begin
Set IgnoreCase of hRegEx to bIgnoreCase
End
Set Pattern of hRegEx to sPattern
Set GlobalFind of hRegEx to True
Get Test of hRegEx (Trim(sInput)) to bIsMatch
Send Destroy of hRegEx
End
Else Begin
Error 999 "Cound not instatiate cRegex class"
End
Function_Return bIsMatch
End_Function
Struct tRegexMatch
String Val
Integer FirstIndex
Integer Length
End_Struct
Function Regex_Match Global String sInput String sPattern Boolean bIgnoreCase Returns tRegexMatch[]
String sValue
Variant vMatchCollection vMatch
Integer iItems iItem iFirstIndex iLength
Handle hMatchCollection hRegEx hMatch
tRegexMatch match null
tRegexMatch[] matchArr
Get Create U_cRegularExpressions to hRegEx
If (hRegEx > 0) Begin
If (num_arguments = 3) Begin
Set IgnoreCase of hRegEx to bIgnoreCase
End
Set Pattern of hRegEx to sPattern
Set GlobalFind of hRegEx to True
Get Create U_cComRegExMatchCollection to hMatchCollection
Get ComExecute of (phRegex(hRegEx)) sInput to vMatchCollection
Set pvComObject of hMatchCollection to vMatchCollection
Get ComCount of hMatchCollection to iItems
For iItem from 1 to iItems
Get Create U_cComRegExMatch to hMatch
Get ComItem of hMatchCollection (iItem-1) to vMatch
Set pvComObject of hMatch to vMatch
Get ComValue of hMatch to match.Val
Get ComFirstIndex of hMatch to match.FirstIndex
Get ComLength of hMatch to match.Length
Move match to matchArr[SizeOfArray(matchArr)]
Send Destroy of hMatch
Loop
Send Destroy of hMatchCollection
Send Destroy of hRegEx
End
Else Begin
Error 999 "Cound not instatiate cRegex class"
End
Function_Return matchArr
End_Function