From 62012fbf198ca5c481d65040b02b57a32ed4e4ac Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 14 Oct 2016 14:32:44 +0200 Subject: [PATCH] re-use literal parser implementation between `separator` and `quote` primitives --- include/mapnik/csv/csv_grammar_x3_def.hpp | 28 ++++++----------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/include/mapnik/csv/csv_grammar_x3_def.hpp b/include/mapnik/csv/csv_grammar_x3_def.hpp index 9b1d3ba6f..b40507030 100644 --- a/include/mapnik/csv/csv_grammar_x3_def.hpp +++ b/include/mapnik/csv/csv_grammar_x3_def.hpp @@ -53,9 +53,11 @@ struct unesc_char_ : x3::symbols } } unesc_char; -struct separator_ : x3::parser +template +struct literal : x3::parser> { using attribute_type = x3::unused_type; + using context_tag = T; static bool const has_attribute = false; template @@ -63,33 +65,17 @@ struct separator_ : x3::parser Context const& context, x3::unused_type, Attribute& ) const { x3::skip_over(first, last, context); - if (first != last && *first == x3::get(context)) + if (first != last && *first == x3::get(context)) { ++first; return true; } return false; } -} separator; +}; -struct quote_ : x3::parser -{ - using attribute_type = x3::unused_type; - static bool const has_attribute = false; - - template - bool parse(Iterator& first, Iterator const& last, - Context const& context, x3::unused_type, Attribute& ) const - { - x3::skip_over(first, last, context); - if (first != last && *first == x3::get(context)) - { - ++first; - return true; - } - return false; - } -} quote; +auto static const separator = literal{}; +auto static const quote = literal{}; // starting rule csv_line_grammar_type const line("csv-line");