-
Notifications
You must be signed in to change notification settings - Fork 9
/
modAnalysisHeaders.bas
126 lines (101 loc) · 3.85 KB
/
modAnalysisHeaders.bas
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
Attribute VB_Name = "modAnalysisHeaders"
Option Explicit
Public Function GetHeaderValue(ByVal sInput As String, ByVal sHeader As String, Optional ByRef bFuzzySearch = True) As String
Dim sHeaderValue As String
Dim iHeaderTitle As Integer
Dim iHeaderStart As Integer
Dim iHeaderEnd As Integer
Dim iDelimiterPosition As Integer
iDelimiterPosition = InStr(1, sHeader, ":", vbBinaryCompare)
If (iDelimiterPosition = 0) Then
sHeader = sHeader & ":"
End If
If (bFuzzySearch = True) Then
iHeaderTitle = InStr(1, LCase$(sInput), LCase$(sHeader), vbBinaryCompare)
Else
iHeaderTitle = InStr(1, sInput, sHeader, vbBinaryCompare)
End If
If (iHeaderTitle <> 0) Then
iHeaderStart = iHeaderTitle + Len(sHeader)
iHeaderEnd = InStr(iHeaderStart, sInput, vbCrLf, vbBinaryCompare)
If (iHeaderEnd > 0) Then
iHeaderEnd = iHeaderEnd - iHeaderStart
End If
sHeaderValue = Mid$(sInput, iHeaderStart, iHeaderEnd)
End If
GetHeaderValue = Trim(sHeaderValue)
End Function
Public Function GetHeaderSpace(ByRef sInput As String) As Integer
Dim iDelimiterPosition As Integer
iDelimiterPosition = InStr(1, sInput, ":", vbBinaryCompare)
If (Mid$(sInput, iDelimiterPosition + 1, 1) = " ") Then
GetHeaderSpace = 1
Else
GetHeaderSpace = 0
End If
End Function
Public Function GetHeaderOrder(ByRef sInput As String, ByRef sIgnore As String) As String
Dim sIgnoreArray() As String
Dim iIgnoreCount As Integer
Dim bFiltered As Boolean
Dim sHeaderLines() As String
Dim iHeaderCount As Integer
Dim i As Integer
Dim j As Integer
Dim sHeaderName As String
Dim iHeaderNameEnd As Integer
Dim cHeaderNames As Concat
Set cHeaderNames = New Concat
sIgnoreArray = Split(sIgnore, "|", , vbBinaryCompare)
iIgnoreCount = UBound(sIgnoreArray)
sHeaderLines = Split(sInput, vbCrLf, , vbBinaryCompare)
iHeaderCount = UBound(sHeaderLines)
For i = 0 To iHeaderCount
iHeaderNameEnd = InStr(1, sHeaderLines(i), ":", vbBinaryCompare)
If (iHeaderNameEnd <> 0) Then
sHeaderName = Mid(sHeaderLines(i), 1, iHeaderNameEnd - 1)
bFiltered = False
For j = 0 To iIgnoreCount
If (InStrB(1, LCase$(sHeaderName), LCase$(sIgnoreArray(j)), vbBinaryCompare)) Then
bFiltered = True
Exit For
End If
Next j
If (bFiltered = False) Then
cHeaderNames.Concat sHeaderName
If (LenB(sHeaderLines(i + 1))) Then
cHeaderNames.Concat ","
End If
End If
End If
Next i
GetHeaderOrder = cHeaderNames.Value
End Function
Public Function GetHeaderCapitalAfterDash(ByRef sInput As String) As Integer
Dim sHeaders() As String
Dim iHeaderCount As Integer
Dim i As Integer
Dim j As Integer
Dim iDashPosition As Integer
Dim iCounterDashes As Integer
Dim iCounterCapital As Integer
sHeaders = Split(GetHeaderOrder(sInput, vbNullString), ",", , vbBinaryCompare)
iHeaderCount = UBound(sHeaders)
For i = 0 To iHeaderCount
iDashPosition = InStr(1, sHeaders(i), "-", vbBinaryCompare)
If (iDashPosition <> 0) Then
iCounterDashes = iCounterDashes + 1
For j = 65 To 90
If (ChrW$(j) = Mid(sHeaders(i), iDashPosition + 1, 1)) Then
iCounterCapital = iCounterCapital + 1
Exit For
End If
Next j
End If
Next i
If ((iCounterDashes / 2) < iCounterCapital) Then
GetHeaderCapitalAfterDash = 1
Else
GetHeaderCapitalAfterDash = 0
End If
End Function