feature_generator_grammar - fix escaping
This commit is contained in:
parent
4ebd824368
commit
e8b7d50ebb
2 changed files with 30 additions and 16 deletions
|
@ -126,13 +126,12 @@ struct utf8
|
|||
}
|
||||
};
|
||||
|
||||
struct extract_string
|
||||
struct value_base
|
||||
{
|
||||
template <typename T>
|
||||
struct result { using type = std::string; };
|
||||
std::string operator() (mapnik::value const& val) const
|
||||
using result_type = mapnik::value_base const&;
|
||||
mapnik::value_base const& operator() (mapnik::value const& val) const
|
||||
{
|
||||
return val.to_expression_string();
|
||||
return val.base();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -145,6 +144,17 @@ struct escaped_string
|
|||
karma::symbols<char, char const*> esc_char;
|
||||
};
|
||||
|
||||
struct extract_string
|
||||
{
|
||||
using result_type = std::tuple<std::string,bool>;
|
||||
|
||||
result_type operator() (mapnik::value const& val) const
|
||||
{
|
||||
bool need_quotes = val.base().is<value_unicode_string>();
|
||||
return std::make_tuple(val.to_string(), need_quotes);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename OutputIterator>
|
||||
struct feature_generator_grammar:
|
||||
karma::grammar<OutputIterator, mapnik::feature_impl const&()>
|
||||
|
@ -158,11 +168,12 @@ struct feature_generator_grammar:
|
|||
escaped_string<OutputIterator> escaped_string_;
|
||||
karma::rule<OutputIterator, mapnik::feature_impl const&()> properties;
|
||||
karma::rule<OutputIterator, pair_type()> pair;
|
||||
karma::rule<OutputIterator, mapnik::value_base const&(mapnik::value const&)> value;
|
||||
karma::rule<OutputIterator, std::tuple<std::string,bool>()> value;
|
||||
karma::rule<OutputIterator, mapnik::value_null()> value_null_;
|
||||
karma::rule<OutputIterator, mapnik::value_unicode_string()> ustring;
|
||||
typename karma::int_generator<mapnik::value_integer,10, false> int__;
|
||||
boost::phoenix::function<get_id> id_;
|
||||
boost::phoenix::function<value_base> value_base_;
|
||||
boost::phoenix::function<extract_string> extract_string_;
|
||||
boost::phoenix::function<utf8> utf8_;
|
||||
std::string quote_;
|
||||
|
|
|
@ -40,7 +40,6 @@ escaped_string<OutputIterator>::escaped_string()
|
|||
karma::hex_type hex;
|
||||
karma::right_align_type right_align;
|
||||
karma::print_type kprint;
|
||||
|
||||
esc_char.add
|
||||
('"', "\\\"")
|
||||
('\\', "\\\\")
|
||||
|
@ -70,10 +69,11 @@ feature_generator_grammar<OutputIterator>::feature_generator_grammar()
|
|||
boost::spirit::karma::double_type double_;
|
||||
boost::spirit::karma::_val_type _val;
|
||||
boost::spirit::karma::_1_type _1;
|
||||
boost::spirit::karma::_r1_type _r1;
|
||||
boost::spirit::karma::string_type kstring;
|
||||
boost::spirit::karma::eps_type eps;
|
||||
|
||||
using boost::phoenix::at_c;
|
||||
|
||||
feature = lit("{\"type\":\"Feature\",\"id\":")
|
||||
<< uint_[_1 = id_(_val)]
|
||||
<< lit(",\"geometry\":") << geometry
|
||||
|
@ -89,18 +89,21 @@ feature_generator_grammar<OutputIterator>::feature_generator_grammar()
|
|||
pair = lit('"')
|
||||
<< kstring[_1 = boost::phoenix::at_c<0>(_val)] << lit('"')
|
||||
<< lit(':')
|
||||
<< value(boost::phoenix::at_c<1>(_val))
|
||||
<< value[_1 = extract_string_(value_base_(at_c<1>(_val)))]
|
||||
;
|
||||
|
||||
value = kstring[_1 = extract_string_(_r1)]
|
||||
;
|
||||
value_null_ = kstring[_1 = "null"]
|
||||
value = eps(at_c<1>(_val)) << escaped_string_(quote_.c_str())[_1 = at_c<0>(_val)]
|
||||
|
|
||||
kstring[_1 = at_c<0>(_val)]
|
||||
;
|
||||
|
||||
ustring = escaped_string_(quote_.c_str())[_1 = utf8_(_val)]
|
||||
;
|
||||
// FIXME http://boost-spirit.com/home/articles/karma-examples/creating-your-own-generator-component-for-spirit-karma/
|
||||
|
||||
// FIXME http://boost-spirit.com/home/articles/karma-examples/creating-your-own-generator-component-for-spirit-karma/
|
||||
//value = (value_null_| bool_ | int__ | double_ | ustring)//[_1 = value_base_(_r1)]
|
||||
// ;
|
||||
//value_null_ = kstring[_1 = "null"]
|
||||
// ;
|
||||
//ustring = escaped_string_(quote_.c_str())[_1 = utf8_(_val)]
|
||||
// ;
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
Loading…
Reference in a new issue