Skip to content

Commit

Permalink
use range based 'parse' method
Browse files Browse the repository at this point in the history
transcode strings in filter expressions (default to utf8 input)
  -- we can use map definition *.xml to define encoding
  -- and in case of Python from
    # -*- coding: utf-8 -*-
  
utf8 encoded filters are working now.
  • Loading branch information
artemp committed Feb 26, 2008
1 parent cb905b5 commit e1ea0a7
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 379 deletions.
11 changes: 8 additions & 3 deletions bindings/python/mapnik_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ using mapnik::filter_factory;
using mapnik::Feature;
using mapnik::create_filter;

filter_ptr create_filter_(std::string const& wkt)
{
return create_filter(wkt,"utf8");
}

void export_filter()
{
using namespace boost::python;
class_<filter<Feature>,boost::noncopyable>("Filter",
"An expression which allows "
"to select features.",no_init)
.def("__str__",&filter<Feature>::to_string);
;
.def("__str__",&filter<Feature>::to_string);
;

def("Filter",&create_filter);
def("Filter",&create_filter_);
}
58 changes: 30 additions & 28 deletions include/mapnik/filter_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <mapnik/config_error.hpp>
#include <mapnik/filter_parser.hpp>
#include <mapnik/unicode.hpp>

namespace mapnik
{
Expand All @@ -36,35 +37,36 @@ namespace mapnik
class MAPNIK_DECL filter_factory
{
public:
static filter_ptr compile(string const& str)
{
stack<shared_ptr<filter<FeatureT> > > filters;
stack<shared_ptr<expression<FeatureT> > > exps;
filter_grammar<FeatureT> grammar(filters,exps);
char const *text = str.c_str();
parse_info<> info = parse(text, grammar, space_p);
if ( ! info.full) {
std::ostringstream os;
os << "Failed to parse filter expression:" << std::endl
<< str << std::endl
<< "Parsing aborted at '" << info.stop << "'";

throw config_error( os.str() );
}

if ( ! filters.empty())
{
return filters.top();
}
else
{
// XXX: do we ever get here? [DS]
return filter_ptr(new none_filter<FeatureT>());
}
}
static filter_ptr compile(string const& str,transcoder const& tr)
{
stack<shared_ptr<filter<FeatureT> > > filters;
stack<shared_ptr<expression<FeatureT> > > exps;
filter_grammar<FeatureT> grammar(filters,exps,tr);
parse_info<std::string::const_iterator> info = parse(str.begin(), str.end(), grammar, space_p);
if ( !info.full)
{
std::ostringstream os;
os << "Failed to parse filter expression:\n"
<< str << "\nParsing aborted at '" << *info.stop << "'";

throw config_error( os.str() );
}

if ( ! filters.empty())
{
return filters.top();
}
else
{
// XXX: do we ever get here? [DS]
return filter_ptr(new none_filter<FeatureT>());
}
}
};

MAPNIK_DECL filter_ptr create_filter (std::string const& wkt);

MAPNIK_DECL filter_ptr create_filter (std::string const& wkt, std::string const& encoding);
MAPNIK_DECL filter_ptr create_filter (std::string const& wkt);

}

#endif //FILTER_FACTORY_HPP
Loading

0 comments on commit e1ea0a7

Please sign in to comment.