From 61377c582e0f2675baa5f5e6e30a35d1a4164b33 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 1 May 2017 16:08:43 +0300 Subject: Add hxx extension for headers and lib prefix for library dir --- libbutl/string-parser.hxx | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 libbutl/string-parser.hxx (limited to 'libbutl/string-parser.hxx') diff --git a/libbutl/string-parser.hxx b/libbutl/string-parser.hxx new file mode 100644 index 0000000..56ba348 --- /dev/null +++ b/libbutl/string-parser.hxx @@ -0,0 +1,56 @@ +// file : libbutl/string-parser.hxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef LIBBUTL_STRING_PARSER_HXX +#define LIBBUTL_STRING_PARSER_HXX + +#include +#include +#include // size_t +#include // pair +#include // invalid_argument + +#include + +namespace butl +{ + class LIBBUTL_EXPORT 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. + }; + + class LIBBUTL_EXPORT string_parser + { + public: + // 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. + // + 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. + // + static std::string + unquote (const std::string&); + + static std::vector + unquote (const std::vector&); + }; +} + +#endif // LIBBUTL_STRING_PARSER_HXX -- cgit v1.1