allow "stringified" nested objects and arrays as feature property
This commit is contained in:
parent
6beee4ad68
commit
671c0046ee
3 changed files with 16 additions and 6 deletions
|
@ -104,7 +104,9 @@ struct feature_grammar :
|
|||
qi::rule<Iterator,void(FeatureType &),space_type> properties;
|
||||
qi::rule<Iterator,qi::locals<std::string>, void(FeatureType &),space_type> attributes;
|
||||
qi::rule<Iterator, json_value(), space_type> attribute_value;
|
||||
|
||||
qi::rule<Iterator, qi::locals<std::int32_t>, std::string(), space_type> stringify_object;
|
||||
qi::rule<Iterator, qi::locals<std::int32_t>, std::string(), space_type> stringify_array;
|
||||
// functions
|
||||
phoenix::function<put_property> put_property_;
|
||||
phoenix::function<extract_geometry> extract_geometry_;
|
||||
// error handler
|
||||
|
|
|
@ -43,15 +43,14 @@ feature_grammar<Iterator,FeatureType,ErrorHandler>::feature_grammar(mapnik::tran
|
|||
qi::_a_type _a;
|
||||
qi::_r1_type _r1;
|
||||
qi::eps_type eps;
|
||||
|
||||
qi::char_type char_;
|
||||
using qi::fail;
|
||||
using qi::on_error;
|
||||
using phoenix::new_;
|
||||
using phoenix::construct;
|
||||
|
||||
// generic json types
|
||||
json_.value = json_.object | json_.array | json_.string_
|
||||
| json_.number
|
||||
json_.value = json_.object | json_.array | json_.string_ | json_.number
|
||||
;
|
||||
|
||||
json_.pairs = json_.key_value % lit(',')
|
||||
|
@ -94,7 +93,14 @@ feature_grammar<Iterator,FeatureType,ErrorHandler>::feature_grammar(mapnik::tran
|
|||
attributes = (json_.string_ [_a = _1] > lit(':') > attribute_value [put_property_(_r1,_a,_1)]) % lit(',')
|
||||
;
|
||||
|
||||
attribute_value %= json_.number | json_.string_ ;
|
||||
attribute_value %= json_.number | json_.string_ | stringify_object | stringify_array
|
||||
;
|
||||
|
||||
stringify_object %= char_('{')[_a = 1 ] >> *(eps(_a > 0) >> (char_('{')[_a +=1] | char_('}')[_a -=1] | char_))
|
||||
;
|
||||
|
||||
stringify_array %= char_('[')[_a = 1 ] >> *(eps(_a > 0) >> (char_('[')[_a +=1] | char_(']')[_a -=1] | char_))
|
||||
;
|
||||
|
||||
feature.name("Feature");
|
||||
feature_type.name("type");
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
"spaces":"this has spaces",
|
||||
"double":1.1,
|
||||
"boolean":true,
|
||||
"NOM_FR":"Québec"
|
||||
"NOM_FR":"Québec",
|
||||
"object": {"value":{"type":"u'\u041c\u0430pni\u043a'","array": [3,0,"x"]}},
|
||||
"array" : [ [ [1], ["deux"]],[[3,"four","\u4e94"]]]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue