aboutsummaryrefslogtreecommitdiff
path: root/libbutl/string-parser.mxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-09-22 23:32:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-09-22 23:32:28 +0200
commitc09cd7512491cee1e82c1ad8128ce9fd4bc3f79b (patch)
treea659ed768d849130ab5780a11b7f791a463a1a91 /libbutl/string-parser.mxx
parent2a00871f07067f8f9e2de08bb9c8f50e1bf6a650 (diff)
Initial modularization with both Clang and VC hacks
Note: gave up on VC about half way though.
Diffstat (limited to 'libbutl/string-parser.mxx')
-rw-r--r--libbutl/string-parser.mxx67
1 files changed, 67 insertions, 0 deletions
diff --git a/libbutl/string-parser.mxx b/libbutl/string-parser.mxx
new file mode 100644
index 0000000..559b938
--- /dev/null
+++ b/libbutl/string-parser.mxx
@@ -0,0 +1,67 @@
+// file : libbutl/string-parser.mxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef __cpp_modules
+#pragma once
+#endif
+
+// C includes.
+
+#ifndef __cpp_lib_modules
+#include <string>
+#include <vector>
+#include <cstddef> // size_t
+#include <utility> // pair
+#include <stdexcept> // invalid_argument
+#endif
+
+// Other includes.
+
+#ifdef __cpp_modules
+export module butl.string_parser;
+#ifdef __cpp_lib_modules
+import std.core;
+#endif
+#endif
+
+#include <libbutl/export.hxx>
+
+LIBBUTL_MODEXPORT namespace butl
+{
+ namespace string_parser
+ {
+ class LIBBUTL_SYMEXPORT invalid_string: public std::invalid_argument
+ {
+ public:
+ invalid_string (std::size_t p, const std::string& d)
+ : invalid_argument (d), position (p) {}
+
+ std::size_t position; // Zero-based.
+ };
+
+ // Parse a whitespace-separated list of strings. Can contain single or
+ // double quoted substrings. No escaping is supported. If unquote is true,
+ // return one-level unquoted values. Throw invalid_string in case of
+ // invalid quoting.
+ //
+ LIBBUTL_SYMEXPORT std::vector<std::string>
+ parse_quoted (const std::string&, bool unquote);
+
+ // As above but return a list of string and zero-based position pairs.
+ // Position is useful for issuing diagnostics about an invalid string
+ // during second-level parsing.
+ //
+ LIBBUTL_SYMEXPORT std::vector<std::pair<std::string, std::size_t>>
+ parse_quoted_position (const std::string&, bool unquote);
+
+ // Remove a single level of quotes. Note that the format or the
+ // correctness of the quotation is not validated.
+ //
+ LIBBUTL_SYMEXPORT std::string
+ unquote (const std::string&);
+
+ LIBBUTL_SYMEXPORT std::vector<std::string>
+ unquote (const std::vector<std::string>&);
+ }
+}