📄 parser.cs
字号:
node.IsTerminated = true;
num++;
node = null;
}
else if ((num < tokens.Count) && ">".Equals(tokens[num]))
{
num++;
}
}
else if (">".Equals(tokens[num]))
{
num++;
}
else
{
if ("</".Equals(tokens[num]))
{
num++;
if (num >= tokens.Count)
{
return nodes;
}
string text4 = tokens[num];
num++;
int num2 = this.FindTagOpenNodeIndex(nodes, text4);
if (num2 != -1)
{
this.MoveNodesDown(ref nodes, num2 + 1, (TagElement) nodes[num2]);
}
while ((num < tokens.Count) && !">".Equals(tokens[num]))
{
num++;
}
if ((num < tokens.Count) && ">".Equals(tokens[num]))
{
num++;
}
node = null;
continue;
}
string input = tokens[num];
if (this.mRemoveEmptyElementText)
{
input = this.RemoveWhitespace(input);
}
input = DecodeScript(input);
if (!this.mRemoveEmptyElementText || (input.Length != 0))
{
if ((node == null) || !node.NoEscaping)
{
input = TagEncoder.DecodeValue(input);
}
TextNode node = new TextNode(input);
nodes.Add(node);
}
num++;
}
}
return nodes;
}
private string PreprocessScript(string input, string tag_name)
{
StringBuilder builder = new StringBuilder();
int startIndex = 0;
int length = tag_name.Length;
while (startIndex < input.Length)
{
bool flag = false;
if ((((startIndex + length) + 1) >= input.Length) || !input.Substring(startIndex, length + 1).ToLower().Equals("<" + tag_name))
{
goto Label_025C;
}
Label_004A:
if (startIndex < input.Length)
{
if (input.Substring(startIndex, 1).Equals(">"))
{
builder.Append(">");
startIndex++;
}
else if (((startIndex + 1) < input.Length) && input.Substring(startIndex, 2).Equals("/>"))
{
builder.Append("/>");
startIndex += 2;
flag = true;
}
else
{
if (input.Substring(startIndex, 1).Equals("\""))
{
builder.Append("\"");
startIndex++;
while ((startIndex < input.Length) && !input.Substring(startIndex, 1).Equals("\""))
{
builder.Append(input.Substring(startIndex, 1));
startIndex++;
}
if (startIndex < input.Length)
{
startIndex++;
builder.Append("\"");
}
}
else if (input.Substring(startIndex, 1).Equals("'"))
{
builder.Append("'");
startIndex++;
while ((startIndex < input.Length) && !input.Substring(startIndex, 1).Equals("'"))
{
builder.Append(input.Substring(startIndex, 1));
startIndex++;
}
if (startIndex < input.Length)
{
startIndex++;
builder.Append("'");
}
}
else
{
builder.Append(input.Substring(startIndex, 1));
startIndex++;
}
goto Label_004A;
}
}
if (startIndex >= input.Length)
{
break;
}
if (!flag)
{
StringBuilder builder2 = new StringBuilder();
while ((((startIndex + length) + 3) < input.Length) && !input.Substring(startIndex, length + 3).ToLower().Equals("</" + tag_name + ">"))
{
builder2.Append(input.Substring(startIndex, 1));
startIndex++;
}
builder.Append(EncodeScript(builder2.ToString()));
builder.Append("</" + tag_name + ">");
if (((startIndex + length) + 3) < input.Length)
{
startIndex += length + 3;
}
}
continue;
Label_025C:
builder.Append(input.Substring(startIndex, 1));
startIndex++;
}
return builder.ToString();
}
private string RemoveComments(string input)
{
StringBuilder builder = new StringBuilder();
int startIndex = 0;
bool flag = false;
while (startIndex < input.Length)
{
if (((startIndex + 4) < input.Length) && input.Substring(startIndex, 4).Equals("<!--"))
{
startIndex += 4;
startIndex = input.IndexOf("-->", startIndex);
if (startIndex == -1)
{
break;
}
startIndex += 3;
}
else
{
if (input.Substring(startIndex, 1).Equals("<"))
{
flag = true;
builder.Append("<");
startIndex++;
continue;
}
if (input.Substring(startIndex, 1).Equals(">"))
{
flag = false;
builder.Append(">");
startIndex++;
continue;
}
if (input.Substring(startIndex, 1).Equals("\"") && flag)
{
int num2 = startIndex;
startIndex++;
startIndex = input.IndexOf("\"", startIndex);
if (startIndex == -1)
{
break;
}
startIndex++;
builder.Append(input.Substring(num2, startIndex - num2));
continue;
}
if (input.Substring(startIndex, 1).Equals("'") && flag)
{
int num3 = startIndex;
startIndex++;
startIndex = input.IndexOf("'", startIndex);
if (startIndex == -1)
{
break;
}
startIndex++;
builder.Append(input.Substring(num3, startIndex - num3));
continue;
}
builder.Append(input.Substring(startIndex, 1));
startIndex++;
}
}
return builder.ToString();
}
private string RemoveSGMLComments(string input)
{
StringBuilder builder = new StringBuilder();
int startIndex = 0;
bool flag = false;
while (startIndex < input.Length)
{
if (((startIndex + 2) < input.Length) && input.Substring(startIndex, 2).Equals("<!"))
{
startIndex += 2;
startIndex = input.IndexOf(">", startIndex);
if (startIndex == -1)
{
break;
}
startIndex += 3;
}
else
{
if (input.Substring(startIndex, 1).Equals("<"))
{
flag = true;
builder.Append("<");
startIndex++;
continue;
}
if (input.Substring(startIndex, 1).Equals(">"))
{
flag = false;
builder.Append(">");
startIndex++;
continue;
}
if (input.Substring(startIndex, 1).Equals("\"") && flag)
{
int num2 = startIndex;
startIndex++;
startIndex = input.IndexOf("\"", startIndex);
if (startIndex == -1)
{
break;
}
startIndex++;
builder.Append(input.Substring(num2, startIndex - num2));
continue;
}
if (input.Substring(startIndex, 1).Equals("'") && flag)
{
int num3 = startIndex;
startIndex++;
startIndex = input.IndexOf("'", startIndex);
if (startIndex == -1)
{
break;
}
startIndex++;
builder.Append(input.Substring(num3, startIndex - num3));
continue;
}
builder.Append(input.Substring(startIndex, 1));
startIndex++;
}
}
return builder.ToString();
}
private string RemoveWhitespace(string input)
{
return input.Replace("\r", "").Replace("\n", "").Replace("\t", " ").Trim();
}
public bool RemoveEmptyElementText
{
get
{
return this.mRemoveEmptyElementText;
}
set
{
this.mRemoveEmptyElementText = value;
}
}
private enum ParseStatus
{
ReadText,
ReadEndTag,
ReadStartTag,
ReadAttributeName,
ReadAttributeValue
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -