Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. int main(int argc, const char * argv[]) {
  2.  
  3. 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>";
  4. HtmlParser HP(htmlStr.begin(), htmlStr.end());
  5. HP.toNextBracket();
  6. node firstNode;
  7. try
  8. {
  9. HP.parseTag(firstNode);
  10. }
  11. catch (const std::string & tagParseError)
  12. {
  13. std::cout << "Error in parsing of the tag: " << tagParseError << std::endl;
  14. }
  15. std::cout << firstNode.element_type << std::endl;
  16.  
  17.  
  18. return 0;
  19. }
  20.  
  21. void HtmlParser::parseTag(node & N)
  22. {
  23. char thisChar = getCurChar();
  24. /* Expected that the function is called when the current character is
  25. an opening bracket. If it isn't, throw an error.
  26. */
  27. if (thisChar != '<')
  28. {
  29. throw "Current character must be '<' in order to run parseTag()'";
  30. return;
  31. }
  32.  
  33. ++_curIter;
  34. /* _curIter now points to the character after the opening of the tag. */
  35.  
  36. std::string elementType;
  37. /* While the current character is one that is valid for an element type,
  38. add it to the string elementType and advance to the next character.
  39. Throw an error if elementType ends up being empty.
  40. */
  41.  
  42. while (_elementTypeChars.find(*_curIter) != std::string::npos && _curIter != _offend) elementType.push_back(*_curIter++);
  43. if (elementType.empty()) throw "Didn't process any characters into the element type!";
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement