-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathGAUG_RegExp_Win.cls
122 lines (98 loc) · 4.92 KB
/
GAUG_RegExp_Win.cls
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "GAUG_RegExp"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'***********************************************************************************************************************************************
'***********************************************************************************************************************************************
'** Author: José Luis González García **
'** Last modified: 2024-10-23 **
'** **
'** Class GAUG_RegExp **
'** **
'** This class is a very simplified wrapper for the original class RegExp provided by Microsoft VBScript Regular Expressions 5.5. **
'** It is used to remove the dependency on Microsoft VBScript Regular Expressions 5.5 on Windows **
'** and to be able to port Mendeley Macros to macOS. **
'***********************************************************************************************************************************************
'***********************************************************************************************************************************************
'private properties (standard from "VBScript.RegExp" for compatibility)
Private strPattern As String
Private blnIgnoreCase As Boolean
Private blnGlobalSearch As Boolean
'private object for regular expressions
Private objRegularExpression As Object
Private Sub Class_Initialize()
'creates the object for the regular expressions
Set objRegularExpression = CreateObject("VBScript.RegExp")
'initializes the properties
strPattern = ""
blnIgnoreCase = False
blnGlobalSearch = True
'initializes the object for regular expressions with new properties
objRegularExpression.pattern = strPattern
objRegularExpression.ignoreCase = blnIgnoreCase
objRegularExpression.Global = blnGlobalSearch
End Sub
Private Sub Class_Terminate()
'frees memory
Set objRegularExpression = Nothing
End Sub
'for Pattern
Public Property Get pattern() As String
pattern = strPattern
End Property
Public Property Let pattern(strNewPattern As String)
'sets the pattern
strPattern = strNewPattern
objRegularExpression.pattern = strPattern
End Property
'for IgnoreCase
Public Property Get ignoreCase() As Boolean
ignoreCase = blnIgnoreCase
End Property
Public Property Let ignoreCase(blnNewIgnoreCase As Boolean)
'sets case insensitivity
blnIgnoreCase = blnNewIgnoreCase
objRegularExpression.ignoreCase = blnIgnoreCase
End Property
'for GlobalSearch
Public Property Get GlobalSearch() As Boolean
GlobalSearch = blnGlobalSearch
End Property
Public Property Let GlobalSearch(blnNewGlobalSearch As Boolean)
'sets global applicability
blnGlobalSearch = blnNewGlobalSearch
objRegularExpression.Global = blnGlobalSearch
End Property
Public Function Test(strString As String) As Boolean
'tests and returns the result
Test = objRegularExpression.Test(strString)
End Function
Public Function Execute(strString As String) As Collection
'used to store the original collection of matches
Dim allMatches As Object
Dim currentMatch As Object
'used to store the new collection of matches
Dim colAllCustomMatches As New Collection
Dim customMatch As GAUG_Match
'executes the RegExp pattern against the input string
Set allMatches = objRegularExpression.Execute(strString)
'if matches exist
If allMatches.Count > 0 Then
For Each currentMatch In allMatches
'creates new custom match object and populates new custom match object
Set customMatch = New GAUG_Match
customMatch.Initialize lngNewFirstIndex:=currentMatch.FirstIndex, lngNewLength:=currentMatch.Length, strNewValue:=currentMatch.value
'adds the new custom match to the collection
colAllCustomMatches.Add customMatch
Next currentMatch
End If
'clears the original collection of matches
Set allMatches = Nothing
'returns the collection of matches
Set Execute = colAllCustomMatches
End Function