Geometry/Feature parsers -truncate 'where' message in on_error handler (currently 16 chars max)

This commit is contained in:
artemp 2013-05-14 14:51:28 +01:00
parent 2ec04ab9e3
commit 8d5b983cb6
4 changed files with 29 additions and 4 deletions

View file

@ -133,6 +133,7 @@ struct feature_grammar :
phoenix::function<put_property> put_property_;
phoenix::function<extract_geometry> extract_geometry_;
boost::phoenix::function<where_message> where_message_;
geometry_grammar<Iterator> geometry_grammar_;
};

View file

@ -84,6 +84,21 @@ struct cleanup
}
};
struct where_message
{
typedef std::string result_type;
template <typename Iterator>
std::string operator() (Iterator first, Iterator last, std::size_t size) const
{
std::string str(first, last);
if (str.length() > size)
return str.substr(0, size) + "..." ;
return str;
}
};
template <typename Iterator>
struct geometry_grammar :
qi::grammar<Iterator,qi::locals<int>, void(boost::ptr_vector<mapnik::geometry_type>& )
@ -118,6 +133,7 @@ struct geometry_grammar :
boost::phoenix::function<push_vertex> push_vertex_;
boost::phoenix::function<close_path> close_path_;
boost::phoenix::function<cleanup> cleanup_;
boost::phoenix::function<where_message> where_message_;
};
}}

View file

@ -134,15 +134,18 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
attribute_value %= number | string_ ;
feature.name("Feature");
properties.name("Properties");
attributes.name("Attributes");
on_error<fail>
(
feature
, std::clog
<< phoenix::val("Error! Expecting ")
<< _4 // what failed?
<< _4 // what failed?
<< phoenix::val(" here: \"")
<< construct<std::string>(_3, _2) // iterators to error-pos, end
<< where_message_(_3, _2, 16) // where? 16 is max chars to output
<< phoenix::val("\"")
<< std::endl
);

View file

@ -144,15 +144,20 @@ geometry_grammar<Iterator>::geometry_grammar()
// points
points = lit('[')[_a = SEG_MOVETO] > -(point (_a,_r1) % lit(',')[_a = SEG_LINETO]) > lit(']');
// give some rules names
geometry.name("Geometry");
geometry_collection.name("GeometryCollection");
geometry_dispatch.name("Geometry dispatch");
coordinates.name("Coordinates");
// error handler
on_error<fail>
(
geometry
, std::clog
<< boost::phoenix::val("Error! Expecting ")
<< _4 // what failed?
<< _4 // what failed?
<< boost::phoenix::val(" here: \"")
<< construct<std::string>(_3, _2) // iterators to error-pos, end
<< where_message_(_3, _2, 16) // max 16 chars
<< boost::phoenix::val("\"")
<< std::endl
);