-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAspTool.cs
128 lines (113 loc) · 4.14 KB
/
AspTool.cs
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
using System.Collections.Generic;
namespace AspCodeAnalyzer {
public class AspTool {
public static bool AppendVariables( List<Variable> pVariables, BlockReader pReader) {
var found = false;
string searchText;
var line = pReader.GetCurLine();
searchText = "dim";
var dimIndex = IdentifierPos( line, searchText);
if (dimIndex == -1) {
searchText = "const";
dimIndex = IdentifierPos( line, searchText);
}
if (dimIndex == -1 ) {
return false;
}
var objDefPos = line.IndexOf( ":");
if (objDefPos != -1 )
{
pReader.SetCurLine( line.Substring( objDefPos));
}
else
{
pReader.SetCurLine( "");
}
var vars = line.Substring( dimIndex + searchText.Length).Trim().Split( new char[] {','});
foreach (string t in vars)
{
var curVar = t.Trim();
if (curVar.Length != 0) {
int j = 0;
while ( j < curVar.Length && IsVariableCharacter( curVar[ j]) ) {
j++;
}
if (j > 0)
{
curVar = curVar.Substring(0, j);
var var = new Variable(curVar, pReader.GetLineNumber());
pVariables.Add(var);
found = true;
}
}
}
return found;
}
public static int IdentifierPos( string pText, string pIdentifier) {
int pos = pText.IndexOf( pIdentifier);
while (pos >= 0) {
if (pos == 0 || !IsVariableCharacter( pText[ pos - 1 ])) {
if (pos + pIdentifier.Length >= pText.Length || !IsVariableCharacter( pText[ pos + pIdentifier.Length])) {
return pos;
}
}
pos = pText.IndexOf( pIdentifier, pos + 1);
}
return -1;
}
public static bool ContainsIdentifier( string pText, string pIdentifier) {
int pos = pText.IndexOf( pIdentifier);
while (pos >= 0) {
if (pos == 0 || ((pText[pos-1] != '.') && !IsVariableCharacter( pText[ pos - 1 ]))) {
if (pos + pIdentifier.Length >= pText.Length || !IsVariableCharacter( pText[ pos + pIdentifier.Length])) {
return true;
}
}
pos = pText.IndexOf( pIdentifier, pos + 1);
}
return false;
}
private static bool CheckSingleSubContext(string searchType, ref string pFunctionName, ref string pFunctionType, BlockReader pReader)
{
int pos = pReader.GetCurLine().IndexOf(searchType + " ");
if (pos >= 0 ) {
if (pos == 0 || !IsVariableCharacter( pReader.GetCurLine()[ pos - 1 ])) {
pFunctionType = searchType;
int pos1 = pReader.GetCurLine().IndexOf( "(", pos);
if (pos1 == -1 ) {
pFunctionName = pReader.GetCurLine().Substring( pos + searchType.Length + 1).Trim();
pReader.ReadLine();
return true;
}
else {
pFunctionName = pReader.GetCurLine().Substring( pos + searchType.Length + 1, pos1 - pos - searchType.Length - 1).Trim();
pReader.ReadLine();
return true;
}
}
}
return false;
}
public static void CheckSubContext( ref string pFunctionName, ref string pFunctionType, BlockReader pReader)
{
pFunctionName = null;
pFunctionType = null;
if (CheckSingleSubContext("sub", ref pFunctionName, ref pFunctionType, pReader))
{
return;
}
if (CheckSingleSubContext("function", ref pFunctionName, ref pFunctionType, pReader))
{
return;
}
if (CheckSingleSubContext("class", ref pFunctionName, ref pFunctionType, pReader))
{
return;
}
}
public static bool IsVariableCharacter (char pChar)
{
return (char.IsLetterOrDigit(pChar) || pChar == '_');
}
}
}