MCPcopy Create free account
hub / github.com/Barracuda09/SATPI / parseXML

Method parseXML

src/base/XMLSupport.cpp:44–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44bool XMLSupport::parseXML(const std::string &xml, const std::string &elementToFind, bool &found, std::string &element,
45 std::string::const_iterator &it, std::string &tagEnd, std::string::const_iterator &itEndElement) {
46 enum class StateXML {
47 SEARCH_START_TAG,
48 COMMENT,
49 XML_DECL,
50 TAG_START,
51 TAG_END,
52 ELEMENT,
53 ESCAPE
54 };
55 StateXML state = StateXML::SEARCH_START_TAG;
56 std::string::const_iterator itBegin;
57 std::string tag;
58 for (; it != xml.end(); ++it) {
59 switch (state) {
60 case StateXML::SEARCH_START_TAG:
61 // Check begin of 'tag'?
62 if (*it == '<') {
63 ++it;
64 if (it != xml.end()) {
65 itBegin = it;
66 switch (*it) {
67 case '!':
68 state = StateXML::COMMENT;
69 break;
70 case '?':
71 state = StateXML::XML_DECL;
72 break;
73 case '/':
74 itEndElement = it - 1;
75 state = StateXML::TAG_END;
76 break;
77 case '&':
78 state = StateXML::ESCAPE;
79 break;
80 default:
81 state = StateXML::TAG_START;
82 break;
83 }
84 } else {
85 return false;
86 }
87 } else {
88 itBegin = it;
89 state = StateXML::ELEMENT;
90 }
91 break;
92 case StateXML::XML_DECL:
93 if (*it == '?') {
94 ++it;
95 if (it != xml.end() && *it == '>') {
96 state = StateXML::SEARCH_START_TAG;
97 } else {
98 return false;
99 }
100 }
101 break;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected