/// <summary> /// Skips the font awesome specification at the current specified pos. Pos is inside str at the '@'. font awesome /// directives are @fa-iconname. newPos is positioned to character after iconname if successful match. iconname scanned is specified in iconname. /// </summary> /// <param name="str">The string.</param> /// <param name="currentPos">The current position.</param> /// <param name="newPos">The new position.</param> /// <param name="iconName">Name of the icon.</param> /// <returns> /// bool if match was found and properly skipped, otherwise false. /// </returns> public static bool SkipFontAwesome(string str, int currentPos, out int newPos, out string iconName) { newPos = currentPos; iconName = string.Empty; if (str[currentPos] != '@') { return(false); } var scanner = new StringScanner(str, currentPos); // skip '@' scanner.SkipForward(1); if (!scanner.DoesMatch("fa-")) { // not a font awesome specification return(false); } scanner.SkipForward(3); iconName = string.Empty; if (!scanner.SkipIdentifier(ref iconName)) { // no icon name specified return(false); } if (string.IsNullOrWhiteSpace(iconName)) { return(false); } // matched a fontawesome specification newPos = scanner.Position; return(true); }
private static HtmlTag ParseHelper(StringScanner p) { // Does it look like a tag? if (p.Current != '<') return null; // Skip '<' p.SkipForward(1); // Is it a comment? if (p.SkipString("!--")) { p.Mark(); if (p.Find("-->")) { var t = new HtmlTag("!"); t.m_attributes.Add("content", p.Extract()); t.m_closed = true; p.SkipForward(3); return t; } } // Is it a closing tag eg: </div> bool bClosing = p.SkipChar('/'); // Get the tag name string tagName=null; if (!p.SkipIdentifier(ref tagName)) return null; // Probably a tag, create the HtmlTag object now HtmlTag tag = new HtmlTag(tagName); tag.m_closing = bClosing; // If it's a closing tag, no attributes if (bClosing) { if (p.Current != '>') return null; p.SkipForward(1); return tag; } while (!p.Eof) { // Skip whitespace p.SkipWhitespace(); // Check for closed tag eg: <hr /> if (p.SkipString("/>")) { tag.m_closed=true; return tag; } // End of tag? if (p.SkipChar('>')) { return tag; } // attribute name string attributeName = null; if (!p.SkipIdentifier(ref attributeName)) return null; // Skip whitespace p.SkipWhitespace(); // Skip equal sign if (p.SkipChar('=')) { // Skip whitespace p.SkipWhitespace(); // Optional quotes if (p.SkipChar('\"')) { // Scan the value p.Mark(); if (!p.Find('\"')) return null; // Store the value tag.m_attributes.Add(attributeName, p.Extract()); // Skip closing quote p.SkipForward(1); } else { // Scan the value p.Mark(); while (!p.Eof && !char.IsWhiteSpace(p.Current) && p.Current != '>' && p.Current != '/') p.SkipForward(1); if (!p.Eof) { // Store the value tag.m_attributes.Add(attributeName, p.Extract()); } } } else { tag.m_attributes.Add(attributeName, ""); } } return null; }
private static HtmlTag ParseHelper(StringScanner p) { // Does it look like a tag? if (p.current != '<') { return(null); } // Skip '<' p.SkipForward(1); // Is it a comment? if (p.SkipString("!--")) { p.Mark(); if (p.Find("-->")) { var t = new HtmlTag("!"); t.m_attributes.Add("content", p.Extract()); t.m_closed = true; p.SkipForward(3); return(t); } } // Is it a closing tag eg: </div> bool bClosing = p.SkipChar('/'); // Get the tag name string tagName = null; if (!p.SkipIdentifier(ref tagName)) { return(null); } // Probably a tag, create the HtmlTag object now HtmlTag tag = new HtmlTag(tagName); tag.m_closing = bClosing; // If it's a closing tag, no attributes if (bClosing) { if (p.current != '>') { return(null); } p.SkipForward(1); return(tag); } while (!p.eof) { // Skip whitespace p.SkipWhitespace(); // Check for closed tag eg: <hr /> if (p.SkipString("/>")) { tag.m_closed = true; return(tag); } // End of tag? if (p.SkipChar('>')) { return(tag); } // attribute name string attributeName = null; if (!p.SkipIdentifier(ref attributeName)) { return(null); } // Skip whitespace p.SkipWhitespace(); // Skip equal sign if (p.SkipChar('=')) { // Skip whitespace p.SkipWhitespace(); // Optional quotes if (p.SkipChar('\"')) { // Scan the value p.Mark(); if (!p.Find('\"')) { return(null); } // Store the value tag.m_attributes.Add(attributeName, p.Extract()); // Skip closing quote p.SkipForward(1); } else { // Scan the value p.Mark(); while (!p.eof && !char.IsWhiteSpace(p.current) && p.current != '>' && p.current != '/') { p.SkipForward(1); } if (!p.eof) { // Store the value tag.m_attributes.Add(attributeName, p.Extract()); } } } else { tag.m_attributes.Add(attributeName, ""); } } return(null); }