-
Notifications
You must be signed in to change notification settings - Fork 79
/
Parse.cs
144 lines (129 loc) · 3.12 KB
/
Parse.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
namespace SensePost.Wikto
{
/// Base class for parseing tag based files, such as HTML, HTTP headers
/// or XML.
///
///
/// This spider is copyright 2003 by Jeff Heaton. However, it is
/// released under a Limited GNU Public License (LGPL). You may
/// use it freely in your own programs. For the latest version visit
/// http://www.jeffheaton.com.
/// ****************************************************************
/// Changes by SensePost (Pty) Ltd. - Ian de Villiers
/// http://www.sensepost.com
///
/// Fixed the somewhat broken monitor methods causing thread issues
/// on VS2005 .Net where threads would not terminate.
///
/// Removed the Done (Monitor) Class. Not entirely neccessary and
/// actually causes more problems than it assists with in VS 2005.
public class Parse:AttributeList
{
private string m_source;
private int m_idx;
private char m_parseDelim;
private string m_parseName;
private string m_parseValue;
public string m_tag;
public static bool IsWhiteSpace(char ch)
{
return( "\t\n\r ".IndexOf(ch) != -1 );
}
public void EatWhiteSpace()
{
while ( !Eof() )
{
if ( !IsWhiteSpace(GetCurrentChar()) ) return;
m_idx++;
}
}
public bool Eof()
{
return(m_idx>=m_source.Length );
}
public void ParseAttributeName()
{
EatWhiteSpace();
while ( !Eof() )
{
if ( IsWhiteSpace(GetCurrentChar()) || (GetCurrentChar()=='=') || (GetCurrentChar()=='>') )
break;
m_parseName+=GetCurrentChar();
m_idx++;
}
EatWhiteSpace();
}
public void ParseAttributeValue()
{
if ( m_parseDelim!=0 ) return;
if ( GetCurrentChar()=='=' )
{
m_idx++;
EatWhiteSpace();
if ( (GetCurrentChar()=='\'') || (GetCurrentChar()=='\"') )
{
m_parseDelim = GetCurrentChar();
m_idx++;
while ( GetCurrentChar()!=m_parseDelim )
{
m_parseValue+=GetCurrentChar();
m_idx++;
}
m_idx++;
}
else
{
while ( !Eof() && !IsWhiteSpace(GetCurrentChar()) && (GetCurrentChar()!='>') )
{
m_parseValue+=GetCurrentChar();
m_idx++;
}
}
EatWhiteSpace();
}
}
public void AddAttribute()
{
Attribute a = new Attribute(m_parseName, m_parseValue,m_parseDelim);
Add(a);
}
public char GetCurrentChar()
{
return GetCurrentChar(0);
}
public char GetCurrentChar(int peek)
{
if( (m_idx+peek)<m_source.Length ) return m_source[m_idx+peek];
else return (char)0;
}
public char AdvanceCurrentChar()
{
return m_source[m_idx++];
}
public void Advance()
{
m_idx++;
}
public string ParseName
{
get { return m_parseName; }
set { m_parseName = value; }
}
public string ParseValue
{
get { return m_parseValue; }
set { m_parseValue = value; }
}
public char ParseDelim
{
get { return m_parseDelim; }
set { m_parseDelim = value; }
}
public string Source
{
get { return m_source; }
set { m_source = value; }
}
}
}