-
Notifications
You must be signed in to change notification settings - Fork 3
/
ZtRegMatch.cls
94 lines (68 loc) · 3.39 KB
/
ZtRegMatch.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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "ZtRegMatch"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Class ZtRegMatch.
' It capsules VBScript match and enables named groups in VBScript regexp.
'
' Zotero Tools.
' This software is under Revised ('New') BSD license.
' Copyright © 2019, Olaf Ahrens. All rights reserved.
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private variables.
Private pvtGroups As Collection
Private pvtMatch As VBScript_RegExp_55.Match
Private pvtInternalNrPattern As String
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Constructor.
Private Sub Class_Initialize()
pvtInternalNrPattern = "$#"
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Friend procedures and properties.
Friend Sub Initialize(ByVal valGroups As Collection, ByVal valMatch As VBScript_RegExp_55.Match)
Set pvtGroups = valGroups
Set pvtMatch = valMatch
End Sub
' @valGroupNameOrNr:
' - 0 = the whole match
' - 1, 2, ... = the first, second, ... named or unnamed group of the match
' - 'group name' = the specified group of the match
Friend Property Get Groups(ByVal valGroupNameOrNr As Variant) As String
Dim locRegGroup As ZtRegGroup
Dim locGroupNameOrNr As Variant
locGroupNameOrNr = valGroupNameOrNr
If locGroupNameOrNr Like pvtInternalNrPattern Then
locGroupNameOrNr = Right$(locGroupNameOrNr, 1)
End If
If IsNumeric(locGroupNameOrNr) Then
' VBA collections are 1-based.
locGroupNameOrNr = locGroupNameOrNr + 1
End If
Set locRegGroup = pvtGroups.Item(locGroupNameOrNr)
If locRegGroup.Nr = 0 Then
Groups = pvtMatch.Value
Else
Groups = pvtMatch.SubMatches(locRegGroup.Nr - 1)
End If
End Property
Friend Property Get FirstIndex() As Long
FirstIndex = pvtMatch.FirstIndex
End Property
Friend Property Get Length() As Long
Length = pvtMatch.Length
End Property
Friend Property Get Value() As String
Value = pvtMatch.Value
End Property
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *