Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, const char * argv[]) {
- const std::string htmlStr = "<div class='myClass1 myClass2' id='myId'><ul class='cool-list'><li><a href='www.google.com'>Google/a><li><a href='www.facebook.com'>Facebook</a></li></ul></div>";
- HtmlParser HP(htmlStr.begin(), htmlStr.end());
- HP.toNextBracket();
- node firstNode;
- try
- {
- HP.parseTag(firstNode);
- }
- catch (const std::string & tagParseError)
- {
- std::cout << "Error in parsing of the tag: " << tagParseError << std::endl;
- }
- std::cout << firstNode.element_type << std::endl;
- return 0;
- }
- void HtmlParser::parseTag(node & N)
- {
- char thisChar = getCurChar();
- /* Expected that the function is called when the current character is
- an opening bracket. If it isn't, throw an error.
- */
- if (thisChar != '<')
- {
- throw "Current character must be '<' in order to run parseTag()'";
- return;
- }
- ++_curIter;
- /* _curIter now points to the character after the opening of the tag. */
- std::string elementType;
- /* While the current character is one that is valid for an element type,
- add it to the string elementType and advance to the next character.
- Throw an error if elementType ends up being empty.
- */
- while (_elementTypeChars.find(*_curIter) != std::string::npos && _curIter != _offend) elementType.push_back(*_curIter++);
- if (elementType.empty()) throw "Didn't process any characters into the element type!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement