]> git.sesse.net Git - cubemap/blobdiff - parse.h
Support parsing streams from config file. Also support multiple streams (includes...
[cubemap] / parse.h
diff --git a/parse.h b/parse.h
new file mode 100644 (file)
index 0000000..83c5d2a
--- /dev/null
+++ b/parse.h
@@ -0,0 +1,28 @@
+#ifndef _PARSE_H
+#define _PARSE_H
+
+// Various routines that deal with parsing; both configuration files and HTTP requests.
+
+#include <map>
+#include <vector>
+#include <string>
+
+struct ConfigLine {
+       std::string keyword;
+       std::vector<std::string> arguments;
+       std::map<std::string, std::string> parameters;
+};
+
+// Split a line on whitespace, e.g. "foo  bar baz" -> {"foo", "bar", "baz"}.
+std::vector<std::string> split_tokens(const std::string &line);
+
+// Split a string on \n or \r\n, e.g. "foo\nbar\r\n\nbaz\r\n\r\n" -> {"foo", "bar", "baz"}.
+std::vector<std::string> split_lines(const std::string &str);
+
+// Parse the configuration file.
+std::vector<ConfigLine> parse_config(const std::string &filename);
+
+// Note: Limits are inclusive.
+int fetch_config_int(const std::vector<ConfigLine> &config, const std::string &keyword, int min_limit, int max_limit);
+
+#endif  // !defined(_PARSE_H)