summaryrefslogtreecommitdiff
path: root/algo1w4d1/ValidXML.h
diff options
context:
space:
mode:
Diffstat (limited to 'algo1w4d1/ValidXML.h')
-rw-r--r--algo1w4d1/ValidXML.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/algo1w4d1/ValidXML.h b/algo1w4d1/ValidXML.h
new file mode 100644
index 0000000..0810130
--- /dev/null
+++ b/algo1w4d1/ValidXML.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "Stack.h"
+
+class ValidXML {
+public:
+ /**
+ * @brief parse XML byte by byte (todo: utf-8 safe)
+ *
+ * XML is considered 'valid' when no hierarchy errors or invalid XML syntax
+ * is supplied (double tag opening/closing brackets). This means that partial
+ * or unfinished XML is considered valid. To check if XML is finished,
+ * uncomment the stack size check in the ValidXML::input_valid function.
+ *
+ * Each ValidXML instance parses one XML input, and cannot be reused.
+ */
+ virtual void parse(char);
+ virtual bool input_valid(); /** @brief return if input is valid (true when valid) */
+
+public:
+ ValidXML();
+ virtual ~ValidXML();
+
+private:
+ bool _valid = true; /** @brief if parsed XML is still valid */
+ Stack _tag_stack; /** @brief tag stack (used to validate tag hierarchy) */
+
+ std::string _tag_name; /** @brief tag name (without attributes) */
+ bool _tag_is_closing; /** @brief current tag is closing tag (starts with "</" instead of "<") */
+ bool _parsing_tag; /** @brief parsing text or tag */
+ unsigned _tag_counter; /** @brief characters since tag open character */
+
+private:
+ void tag_finished(); /** @brief handle finished tag */
+};
+