From 5661b404b0104c3065a40ad622bdd3c11d748a99 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 20 Apr 2017 17:31:26 +0300 Subject: Implement string_parser --- butl/string-parser | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'butl/string-parser') diff --git a/butl/string-parser b/butl/string-parser index e3fa507..74391cd 100644 --- a/butl/string-parser +++ b/butl/string-parser @@ -8,6 +8,7 @@ #include #include #include // size_t +#include // pair #include // invalid_argument #include @@ -18,9 +19,9 @@ namespace butl { public: invalid_string (std::size_t p, const std::string& d) - : invalid_argument (d), pos (p) {} + : invalid_argument (d), position (p) {} - std::size_t pos; // Zero-based. + std::size_t position; // Zero-based. }; class LIBBUTL_EXPORT string_parser @@ -31,14 +32,24 @@ namespace butl // return one-level unquoted values. Throw invalid_string in case of // invalid quoting. // - std::vector - parse_quoted (const string&, bool unquote); + static std::vector + 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. + // + static std::vector> + 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. // - std::string - unquote (const string&); + static std::string + unquote (const std::string&); + + static std::vector + unquote (const std::vector&); }; } -- cgit v1.1