diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-01-08 15:30:40 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-01-08 15:31:29 +0300 |
commit | 6ac4f3bcc0bd1306bf1a8dd1bebae1a00081c6b7 (patch) | |
tree | 18557b6da8fafbdc511a0c0f505137ca9317d5ef /libbutl/manifest-parser.mxx | |
parent | 6876fd23ef84487c016e7be46d3deb7d1e695cef (diff) |
Add support for filtering during manifest parsing and serialization
Diffstat (limited to 'libbutl/manifest-parser.mxx')
-rw-r--r-- | libbutl/manifest-parser.mxx | 28 |
1 files changed, 23 insertions, 5 deletions
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 <string> #include <iosfwd> -#include <cstdint> // uint64_t -#include <utility> // pair -#include <stdexcept> // runtime_error +#include <cstdint> // uint64_t +#include <utility> // pair, move() +#include <stdexcept> // runtime_error +#include <functional> #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_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_function> filter_; enum {start, body, end} s_ = start; std::string version_; // Current format version. }; } + +#include <libbutl/manifest-parser.ixx> |