add backwards compatibility support to the expressions parser so that the TextSymbolizer and ShieldSymbolizer 'name' parameter (and others in the future) syntax is understood as pre-0.8.0 syntax, while printing a deprecation warning - should allow older stylesheets to be used with Mapnik 0.8.0 - addresses #501

This commit is contained in:
Dane Springmeyer 2010-01-26 23:03:42 +00:00
parent ba187a4949
commit 9b69f65ea9

View File

@ -25,6 +25,8 @@
#include <mapnik/config_error.hpp>
#include <mapnik/unicode.hpp>
// boost
#include <boost/algorithm/string.hpp>
namespace mapnik
{
@ -47,7 +49,35 @@ public:
}
else
{
throw config_error( "Failed to parse filter expression:\""+str+"\"" );
// Backward compatiblity for version pre 0.8.0
// To be removed in 0.9.0...
if (!boost::algorithm::icontains(str,"'")
&& !boost::algorithm::icontains(str,"[")
&& !boost::algorithm::icontains(str,"]")
&& !boost::algorithm::icontains(str," ")
&& !boost::algorithm::icontains(str,"\""))
{
expression_ptr expr1(new expr_node(true));
mapnik::expression_grammar<std::string::const_iterator> g1(tr);
std::string str1("[" + str + "]");
std::string::const_iterator itr1 = str1.begin();
std::string::const_iterator end1 = str1.end();
bool r1 = boost::spirit::qi::phrase_parse(itr1,end1,g1, boost::spirit::standard_wide::space,*expr1);
if (r1 && itr1==end1)
{
std::clog << "Deprecation Warning: symbolizer value now an expression, please wrap properly in brackets like \"" + str1 + "\"\n";
return expr1;
}
else
{
throw config_error( "Failed to parse expression: \"" + str + "\"" );
}
}
else
{
throw config_error( "Failed to parse expression: \"" + str + "\"" );
}
}
}
};