-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLine.cls
78 lines (69 loc) · 2.28 KB
/
Line.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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Line"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private mRawtext As String
Private mKeywords As cKeywords
'Private mKeyWordDict As Collection 'Obsolete -> Centralized in Highlighter
Private mParagraph As Paragraph
Private mHighlighter As Highlighter
Public Sub ParseParagraph(para As Paragraph)
Dim wd As Range
Dim tmpKeyWord As cKeyword
Dim actCategory As String
For Each wd In para.Range.Words
'The Range of a word includes spacecharacters.
On Error Resume Next
actCategory = mHighlighter.KeyWordDictionary.Item(Replace(wd.Text, " ", ""))
On Error GoTo 0
If Not actCategory = vbNullString Then
Set tmpKeyWord = New cKeyword
Set tmpKeyWord.Range = wd
tmpKeyWord.KeywordType = actCategory
mKeywords.Add tmpKeyWord
End If
actCategory = vbNullString
Next wd
End Sub
Public Sub ParseText(RawLine As String)
Dim myArr As Variant
Dim i As Long
Dim tmpLen As Long
Dim actWord As String
Dim tmpKeyWord As cKeyword
tmpLen = 1
mRawtext = vbNullString
mRawtext = RawLine
initKeyWordDict
myArr = Split(Replace(Replace(Replace(Replace(RawLine, "(", " "), ")", " "), vbCr, " "), vbLf, " "), Space(1))
For i = LBound(myArr) To UBound(myArr)
On Error Resume Next
actWord = mKeyWordDict.Item(myArr(i))
On Error GoTo 0
If Not actWord = vbNullString Then
Set tmpKeyWord = New cKeyword
tmpKeyWord.Start = tmpLen
tmpKeyWord.Tag = myArr(i)
tmpKeyWord.KeywordType = actWord
mKeywords.Add tmpKeyWord
End If
tmpLen = tmpLen + Len(myArr(i)) + 1 'To determine the start
actWord = vbNullString
Next i
End Sub
Public Property Get Keywords() As cKeywords
Set Keywords = mKeywords
End Property
Private Sub initKeyWordDict()
'Obsolete -> Centralized in Highlighter
End Sub
Private Sub Class_Initialize()
Set mKeywords = New cKeywords
Set mKeyWordDict = New Collection
End Sub