specialize string2int conversion to avoid std::string ctor
This commit is contained in:
parent
84daf7a2ad
commit
871650a3c2
1 changed files with 27 additions and 0 deletions
|
@ -35,6 +35,20 @@ namespace mapnik { namespace conversions {
|
|||
|
||||
using namespace boost::spirit;
|
||||
|
||||
// TODO - convert to templates
|
||||
|
||||
static bool string2int(const char * value, int * result)
|
||||
{
|
||||
size_t length = strlen(value);
|
||||
if (length < 1 || value == NULL)
|
||||
return false;
|
||||
const char *begin = value;
|
||||
const char *iter = begin;
|
||||
const char *end = value + length;
|
||||
bool r = qi::phrase_parse(iter,end,qi::int_,ascii::space,*result);
|
||||
return r && (iter == end);
|
||||
}
|
||||
|
||||
static bool string2int(std::string const& value, int * result)
|
||||
{
|
||||
if (value.empty())
|
||||
|
@ -55,6 +69,19 @@ static bool string2double(std::string const& value, double * result)
|
|||
return r && (str_beg == str_end);
|
||||
}
|
||||
|
||||
static bool string2int(const char * value, double * result)
|
||||
{
|
||||
size_t length = strlen(value);
|
||||
if (length < 1 || value == NULL)
|
||||
return false;
|
||||
const char *begin = value;
|
||||
const char *iter = begin;
|
||||
const char *end = value + length;
|
||||
bool r = qi::phrase_parse(iter,end,qi::double_,ascii::space,*result);
|
||||
return r && (iter == end);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue