From 6ac4f3bcc0bd1306bf1a8dd1bebae1a00081c6b7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 8 Jan 2019 15:30:40 +0300 Subject: Add support for filtering during manifest parsing and serialization --- libbutl/manifest-parser.mxx | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'libbutl/manifest-parser.mxx') diff --git a/libbutl/manifest-parser.mxx b/libbutl/manifest-parser.mxx index 7fc4ee3..0289d6f 100644 --- a/libbutl/manifest-parser.mxx +++ b/libbutl/manifest-parser.mxx @@ -11,9 +11,10 @@ #ifndef __cpp_lib_modules #include #include -#include // uint64_t -#include // pair -#include // runtime_error +#include // uint64_t +#include // pair, move() +#include // runtime_error +#include #endif // Other includes. @@ -52,8 +53,19 @@ LIBBUTL_MODEXPORT namespace butl class LIBBUTL_SYMEXPORT manifest_parser: protected butl::char_scanner { public: - manifest_parser (std::istream& is, const std::string& name) - : char_scanner (is), name_ (name) {} + // The filter, if specified, is called by next() prior to returning the + // pair to the caller. If the filter returns false, then the pair is + // discarded. + // + // Note that the filter should handle the end-of-manifest pairs (see + // below) carefully, so next() doesn't end up with an infinite cycle. + // + using filter_function = bool (manifest_name_value&); + + manifest_parser (std::istream& is, + const std::string& name, + std::function filter = {}) + : char_scanner (is), name_ (name), filter_ (std::move (filter)) {} const std::string& name () const {return name_;} @@ -83,6 +95,9 @@ LIBBUTL_MODEXPORT namespace butl private: void + parse_next (manifest_name_value&); + + void parse_name (manifest_name_value&); void @@ -98,8 +113,11 @@ LIBBUTL_MODEXPORT namespace butl private: const std::string name_; + const std::function filter_; enum {start, body, end} s_ = start; std::string version_; // Current format version. }; } + +#include -- cgit v1.1