use boost::spirit to parse int and double from dbf
This commit is contained in:
parent
7776b8f4ae
commit
65eba5f894
1 changed files with 116 additions and 110 deletions
|
@ -26,7 +26,7 @@
|
||||||
#include "dbffile.hpp"
|
#include "dbffile.hpp"
|
||||||
// boost
|
// boost
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -117,11 +117,11 @@ const field_descriptor& dbf_file::descriptor(int col) const
|
||||||
|
|
||||||
void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature const& f) const throw()
|
void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature const& f) const throw()
|
||||||
{
|
{
|
||||||
|
using namespace boost::spirit;
|
||||||
|
|
||||||
if (col>=0 && col<num_fields_)
|
if (col>=0 && col<num_fields_)
|
||||||
{
|
{
|
||||||
std::string name=fields_[col].name_;
|
std::string name=fields_[col].name_;
|
||||||
std::string str(record_+fields_[col].offset_,fields_[col].length_);
|
|
||||||
boost::trim(str);
|
|
||||||
|
|
||||||
switch (fields_[col].type_)
|
switch (fields_[col].type_)
|
||||||
{
|
{
|
||||||
|
@ -130,28 +130,34 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature cons
|
||||||
case 'M':
|
case 'M':
|
||||||
case 'L':
|
case 'L':
|
||||||
{
|
{
|
||||||
|
// FIXME!!!
|
||||||
|
std::string str(record_+fields_[col].offset_,fields_[col].length_);
|
||||||
|
boost::trim(str);
|
||||||
f[name] = tr.transcode(str.c_str());
|
f[name] = tr.transcode(str.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'N':
|
case 'N':
|
||||||
case 'F':
|
case 'F':
|
||||||
{
|
{
|
||||||
if (str[0]=='*')
|
|
||||||
|
if (record_[fields_[col].offset_] == '*')
|
||||||
{
|
{
|
||||||
boost::put(f,name,0);
|
boost::put(f,name,0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( fields_[col].dec_>0 )
|
if ( fields_[col].dec_>0 )
|
||||||
{
|
{
|
||||||
double d = 0.0;
|
double val = 0.0;
|
||||||
std::istringstream(str) >> d;
|
qi::phrase_parse(record_+fields_[col].offset_,record_+fields_[col].offset_ + fields_[col].length_,
|
||||||
boost::put(f,name,d);
|
double_,ascii::space,val);
|
||||||
|
boost::put(f,name,val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i = 0;
|
int val = 0;
|
||||||
std::istringstream(str) >> i;
|
qi::phrase_parse(record_+fields_[col].offset_,record_+fields_[col].offset_ + fields_[col].length_,
|
||||||
boost::put(f,name,i);
|
int_,ascii::space,val);
|
||||||
|
boost::put(f,name,val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue