Parses the contents of an HTML tag. The current position should be at the first character following the tag's opening less-than character. We parse to the end of the tag even if this tag was not requested by the caller. This ensures subsequent parsing takes place after this tag. Returns information on this tag if it's one the caller is requ
(ref HtmlTag tag, string name = null)
| 177 | /// <param name="name">Name of the tags to parse (null to parse all tags).</param> |
| 178 | /// <returns>True if data is being returned for a tag requested by the caller or false otherwise.</returns> |
| 179 | private bool ParseTag(ref HtmlTag tag, string name = null) |
| 180 | { |
| 181 | // Get name of this tag |
| 182 | int start = _pos; |
| 183 | string s = ParseTagName(); |
| 184 | if (s == string.Empty) |
| 185 | return false; |
| 186 | |
| 187 | // Special handling |
| 188 | bool doctype = _scriptBegin = false; |
| 189 | if (string.Compare(s, "!DOCTYPE", StringComparison.OrdinalIgnoreCase) == 0) |
| 190 | doctype = true; |
| 191 | else if (string.Compare(s, "script", StringComparison.OrdinalIgnoreCase) == 0) |
| 192 | _scriptBegin = true; |
| 193 | |
| 194 | // Is this a tag requested by caller? |
| 195 | bool requested = false; |
| 196 | if (name == null || string.Compare(s, name, StringComparison.OrdinalIgnoreCase) == 0) |
| 197 | { |
| 198 | // Setup new tag |
| 199 | _attributes.Clear(); |
| 200 | tag = new HtmlTag |
| 201 | { |
| 202 | Name = s, |
| 203 | StartPosition = start - 1, |
| 204 | Attributes = _attributes, |
| 205 | }; |
| 206 | requested = true; |
| 207 | } |
| 208 | |
| 209 | // Parse attributes |
| 210 | SkipWhitespace(); |
| 211 | while (Peek() != '>') |
| 212 | { |
| 213 | // Return false if start of new html tag is detected. |
| 214 | if (Peek() == '<') |
| 215 | return false; |
| 216 | |
| 217 | if (Peek() == '/') |
| 218 | { |
| 219 | // Handle trailing forward slash |
| 220 | if (requested) |
| 221 | tag.IsEndingSlash = true; |
| 222 | Move(); |
| 223 | SkipWhitespace(); |
| 224 | |
| 225 | // If this is a script tag, it was closed |
| 226 | _scriptBegin = false; |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | // Parse attribute name |
| 231 | s = !doctype ? ParseAttributeName() : ParseAttributeValue(); |
| 232 | SkipWhitespace(); |
| 233 | |
| 234 | // Parse attribute value |
| 235 | var value = string.Empty; |
| 236 | if (Peek() == '=') |
nothing calls this directly
no test coverage detected