From aec70566de291d5a431546dd22cc2344783a3ea0 Mon Sep 17 00:00:00 2001
From: Martin Zak <zakmart1@fit.cvut.cz>
Date: Wed, 1 Jan 2014 17:00:20 +0100
Subject: [PATCH] RegExpFactory

---
 alib/src/RegExpFactory.cpp | 28 ++++++++++++++++++++++++++++
 alib/src/RegExpFactory.h   | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
 create mode 100644 alib/src/RegExpFactory.cpp
 create mode 100644 alib/src/RegExpFactory.h

diff --git a/alib/src/RegExpFactory.cpp b/alib/src/RegExpFactory.cpp
new file mode 100644
index 0000000000..0d5d9c514f
--- /dev/null
+++ b/alib/src/RegExpFactory.cpp
@@ -0,0 +1,28 @@
+/*
+ * RegExpFactory.cpp
+ *
+ *  Created on: Jan 1, 2014
+ *      Author: martin
+ */
+
+#include "sax/SaxInterface.h"
+#include "RegExpFactory.h"
+#include "regexp/RegExpParser.h"
+
+namespace regexp {
+
+RegExp RegExpFactory::fromFile(const string& filename) {
+	std::list<Token> tokens;
+	SaxInterface::parseFile(filename, tokens);
+	RegExpParser parser;
+	return parser.parse(tokens);
+}
+
+RegExp RegExpFactory::fromString(const string& str) {
+	list<Token> tokens;
+	SaxInterface::parseMemory(str, tokens);
+	RegExpParser parser;
+	return parser.parse(tokens);
+}
+
+} /* namespace regexp */
diff --git a/alib/src/RegExpFactory.h b/alib/src/RegExpFactory.h
new file mode 100644
index 0000000000..e81874405c
--- /dev/null
+++ b/alib/src/RegExpFactory.h
@@ -0,0 +1,38 @@
+/*
+ * RegExpFactory.h
+ *
+ *  Created on: Jan 1, 2014
+ *      Author: martin
+ */
+
+#ifndef REGEXPFACTORY_H_
+#define REGEXPFACTORY_H_
+
+#include "regexp/RegExp.h"
+
+namespace regexp {
+
+using namespace std;
+
+/**
+ * RegExp builder.
+ */
+class RegExpFactory {
+public:
+	/**
+	 * Parses the XML in file and returns the RegExp.
+	 * @param filename path to the file
+	 * @return RegExp
+	 */
+	static RegExp fromFile(const string& filename);
+
+	/**
+	 * Parses the XML and returns the RegExp.
+	 * @param str string containing the XML
+	 * @return RegExp
+	 */
+	static RegExp fromString(const string& str);
+};
+
+} /* namespace regexp */
+#endif /* REGEXPFACTORY_H_ */
-- 
GitLab