MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ParseNext

Method ParseNext

Source/Engine/Utilities/HtmlParser.cs:111–170  ·  view source on GitHub ↗

Parses the next tag that matches the specified tag name. Returns information on the next occurrence of the specified tag or null if none found. Name of the tags to parse (null to parse all tags). True if a tag was parsed or false if the end of the document was reached.

(out HtmlTag tag, string name = null)

Source from the content-addressed store, hash-verified

109 /// <param name="name">Name of the tags to parse (null to parse all tags).</param>
110 /// <returns>True if a tag was parsed or false if the end of the document was reached.</returns>
111 public bool ParseNext(out HtmlTag tag, string name = null)
112 {
113 tag = new HtmlTag();
114
115 // Loop until match is found or there are no more tags
116 while (MoveToNextTag())
117 {
118 // Skip opening '<'
119 Move();
120
121 char c = Peek();
122 if (c == '!' && Peek(1) == '-' && Peek(2) == '-')
123 {
124 // Skip over comments
125 const string endComment = "-->";
126 _pos = _html.IndexOf(endComment, _pos, StringComparison.Ordinal);
127 NormalizePosition();
128 Move(endComment.Length);
129 }
130 else
131 {
132 // Skip leading slash
133 bool isLeadingSlash = c == '/';
134 if (isLeadingSlash)
135 Move();
136
137 // Dont process if wrong slash is used.
138 if (c =='\\')
139 return false;
140
141 // Parse tag
142 bool result = ParseTag(ref tag, name);
143
144 // Because scripts may contain tag characters, we need special handling to skip over script contents
145 if (_scriptBegin)
146 {
147 const string endScript = "</script";
148 _pos = _html.IndexOf(endScript, _pos, StringComparison.OrdinalIgnoreCase);
149 NormalizePosition();
150 Move(endScript.Length);
151 SkipWhitespace();
152 if (Peek() == '>')
153 Move();
154 }
155
156 if (result)
157 {
158 if (isLeadingSlash)
159 {
160 // Tag starts with '/'
161 tag.StartPosition--;
162 tag.IsLeadingSlash = true;
163 }
164 return true;
165 }
166 }
167 }
168

Callers 7

TestValidMethod · 0.80
TestTagsMethod · 0.80
TestAttributesMethod · 0.80
TestEndingMethod · 0.80
TestStartPositionMethod · 0.80
TestEndPositionMethod · 0.80
OnParseTextBlocksMethod · 0.80

Calls 4

SkipWhitespaceFunction · 0.85
MoveFunction · 0.50
PeekFunction · 0.50
IndexOfMethod · 0.45

Tested by 6

TestValidMethod · 0.64
TestTagsMethod · 0.64
TestAttributesMethod · 0.64
TestEndingMethod · 0.64
TestStartPositionMethod · 0.64
TestEndPositionMethod · 0.64