From f646aa22289930450af2615dd4ffe7bea7239d81 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Fri, 27 Jan 2012 12:43:43 +0000 Subject: [PATCH] add support for escaped characters/hex notataion i.e \x20 allow both single and double quoted strings --- include/mapnik/expression_grammar.hpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/mapnik/expression_grammar.hpp b/include/mapnik/expression_grammar.hpp index 469a24a09..b562447ef 100644 --- a/include/mapnik/expression_grammar.hpp +++ b/include/mapnik/expression_grammar.hpp @@ -148,6 +148,8 @@ struct expression_grammar : qi::grammar using qi::lit; using qi::int_; using qi::double_; + using qi::hex; + using qi::omit; using standard_wide::char_; expr = logical_expr.alias(); @@ -223,14 +225,23 @@ struct expression_grammar : qi::grammar | '(' >> expr [_val = _1 ] >> ')' ; - + unesc_char.add("\\a", '\a')("\\b", '\b')("\\f", '\f')("\\n", '\n') + ("\\r", '\r')("\\t", '\t')("\\v", '\v')("\\\\", '\\') + ("\\\'", '\'')("\\\"", '\"') + ; + + ustring %= omit[quote_char[_a = _1]] + >> *(unesc_char | "\\x" >> hex | (char_ - lit(_a))) + >> lit(_a); + + quote_char %= char_('\'') | char_('"'); + #if BOOST_VERSION > 104200 - ustring %= '\'' >> no_skip[*~char_('\'')] >> '\''; attr %= '[' >> no_skip[+~char_(']')] >> ']'; #else - ustring %= '\'' >> lexeme[*(char_-'\'')] >> '\''; attr %= '[' >> lexeme[+(char_ - ']')] >> ']'; #endif + } qi::real_parser > strict_double; @@ -250,7 +261,9 @@ struct expression_grammar : qi::grammar qi::rule regex_match_expr; qi::rule, space_type> regex_replace_expr; qi::rule attr; - qi::rule ustring; + qi::rule > ustring; + qi::symbols unesc_char; + qi::rule quote_char; }; } // namespace