35 #include <unordered_map> 60 enum State { HEADER=1, HEADER_END=2, FOOTER=4, ATOM_END=8, NAME_VALUE=16,
61 ELEMENT=32, NEW=64, ILLEGAL=128, FINISH=256 };
95 void next(
State new_state,
const std::string& tag = std::string());
133 { ATOM_END|FOOTER, FOOTER|HEADER },
134 { HEADER, NAME_VALUE|HEADER_END|ATOM_END },
135 { NAME_VALUE, HEADER_END|ATOM_END|NAME_VALUE },
136 { HEADER_END, ELEMENT|HEADER },
176 Stream(std::ostream& os,
const std::string& root,
int step = 2, std::string sep =
"\n");
190 void out(
State state);
197 void out(
const std::string& tag);
206 enum Pending { NONE, HEADER_TAG, NAME, VALUE, ELEMENT_TAG };
245 Parser(std::istream& in,
const std::string& root);
262 bool check(
State state,
const std::string& tag = std::string());
285 const std::string&
getTag()
const {
return m_tag; }
295 bool getAttribute(
const std::string& name, std::string& value);
324 void syntaxError(
const std::string& msg);
345 bool EOL()
const {
return m_pos == m_tokens.size(); }
362 void tokenize(std::istream& in);
370 void tokenize(std::string xml);
378 void parse_attributes(
const std::string& nv);
394 void escape_tag(std::string& tag);
400 void unescape_tag(std::string& tag);
FSM fsm
current FSM state.
Definition: xml.h:214
std::string m_tag
last heder name tag processed
Definition: xml.h:338
bool finished()
Definition: xml.h:101
bool hasElement()
Definition: xml.h:309
std::vector< std::string > m_tokens
Storage for XML tokens to be processed.
Definition: xml.h:327
unsigned int m_pos
Index of current token being processed.
Definition: xml.h:328
std::unordered_map< std::string, std::string > m_attributes
Definition: xml.h:335
static void parse(const string &eqn_str)
EqnPanel class object.
Definition: milo_test.cpp:271
State getState()
Definition: xml.h:81
const int m_indent_step
Number of spaces in indention before HEADER and standalone FOOTER.
Definition: xml.h:210
State
Definition: xml.h:60
virtual ~Parser()
Definition: xml.h:253
std::string m_sep
Character to output before indention.
Definition: xml.h:208
FSM()
Definition: xml.h:75
std::string m_element
last tag element processed
Definition: xml.h:339
std::stack< std::string > m_tags
Stack of header name tags.
Definition: xml.h:110
const std::vector< std::array< int, 2 > > transitions
Definition: xml.h:131
FSM fsm
XML finite state machine.
Definition: xml.h:337
void next(State new_state, const std::string &tag=std::string())
Definition: xml.cpp:56
bool EOL() const
Definition: xml.h:345
void advance(State new_state)
Definition: xml.cpp:39
const std::string & getTag()
Definition: xml.h:87
Pending
Definition: xml.h:206
bool hasAttributes()
Definition: xml.h:302
State m_state
Current state. Initialized to NEW.
Definition: xml.h:109
const std::string & getTag() const
Definition: xml.h:285
Stream & operator<<(Stream &xml, State state)
Definition: xml.cpp:188
std::ostream & m_os
Ouput character stream to write XML.
Definition: xml.h:209
const std::string & getElement()
Definition: xml.h:316
std::string m_nv
temp space for name tag value.
Definition: xml.h:212