From da61043dd9ce17bb5105d54be5f29d79a0006a87 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 9 Mar 2016 12:24:12 +0100 Subject: [PATCH] split csv_line_grammar into *.hpp *_impl.hpp ref #3343 --- include/mapnik/csv/csv_grammar.hpp | 31 +------------ include/mapnik/csv/csv_grammar_impl.hpp | 61 +++++++++++++++++++++++++ plugins/input/csv/csv_utils.cpp | 4 +- 3 files changed, 65 insertions(+), 31 deletions(-) create mode 100644 include/mapnik/csv/csv_grammar_impl.hpp diff --git a/include/mapnik/csv/csv_grammar.hpp b/include/mapnik/csv/csv_grammar.hpp index 723b0405b..240f11ce1 100644 --- a/include/mapnik/csv/csv_grammar.hpp +++ b/include/mapnik/csv/csv_grammar.hpp @@ -65,36 +65,7 @@ struct csv_white_space_skipper : qi::primitive_parser template struct csv_line_grammar : qi::grammar { - csv_line_grammar() - : csv_line_grammar::base_type(line) - { - qi::_r1_type _r1; - qi::_r2_type _r2; - qi::lit_type lit; - qi::char_type char_; - unesc_char.add - ("\\a", '\a') - ("\\b", '\b') - ("\\f", '\f') - ("\\n", '\n') - ("\\r", '\r') - ("\\t", '\t') - ("\\v", '\v') - ("\\\\",'\\') - ("\\\'", '\'') - ("\\\"", '\"') - ("\"\"", '\"') // double quote - ; - line = -lit("\r") > -lit("\n") > column(_r1, _r2) % lit(_r1) - ; - column = quoted(_r2) | *(char_ - lit(_r1)) - ; - quoted = lit(_r1) > text(_r1) > lit(_r1) // support unmatched quotes or not (??) - ; - text = *(unesc_char | (char_ - lit(_r1))) - ; - BOOST_SPIRIT_DEBUG_NODES((line)(column)(quoted)); - } + csv_line_grammar(); private: qi::rule line; qi::rule column; // no-skip diff --git a/include/mapnik/csv/csv_grammar_impl.hpp b/include/mapnik/csv/csv_grammar_impl.hpp new file mode 100644 index 000000000..560835443 --- /dev/null +++ b/include/mapnik/csv/csv_grammar_impl.hpp @@ -0,0 +1,61 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2016 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include + +namespace mapnik { + +namespace qi = boost::spirit::qi; + +template +csv_line_grammar::csv_line_grammar() + : csv_line_grammar::base_type(line) +{ + qi::_r1_type _r1; + qi::_r2_type _r2; + qi::lit_type lit; + qi::char_type char_; + unesc_char.add + ("\\a", '\a') + ("\\b", '\b') + ("\\f", '\f') + ("\\n", '\n') + ("\\r", '\r') + ("\\t", '\t') + ("\\v", '\v') + ("\\\\",'\\') + ("\\\'", '\'') + ("\\\"", '\"') + ("\"\"", '\"') // double quote + ; + line = -lit("\r") > -lit("\n") > column(_r1, _r2) % lit(_r1) + ; + column = quoted(_r2) | *(char_ - lit(_r1)) + ; + quoted = lit(_r1) > text(_r1) > lit(_r1) // support unmatched quotes or not (??) + ; + text = *(unesc_char | (char_ - lit(_r1))) + ; + BOOST_SPIRIT_DEBUG_NODES((line)(column)(quoted)); +} + +} // namespace mapnik diff --git a/plugins/input/csv/csv_utils.cpp b/plugins/input/csv/csv_utils.cpp index 69a3bb836..2f8a84a7b 100644 --- a/plugins/input/csv/csv_utils.cpp +++ b/plugins/input/csv/csv_utils.cpp @@ -27,9 +27,11 @@ #include #include #include -#include #include #include +// csv grammar +#include +// #include "csv_getline.hpp" #include "csv_utils.hpp"