less lexical cast - refs #1055

This commit is contained in:
Dane Springmeyer 2012-04-06 13:39:13 -07:00
parent e57eb47ba0
commit 98e470903c
4 changed files with 24 additions and 24 deletions

View file

@ -21,6 +21,7 @@
*****************************************************************************/ *****************************************************************************/
//$Id: envelope.cpp 17 2005-03-08 23:58:43Z pavlenko $ //$Id: envelope.cpp 17 2005-03-08 23:58:43Z pavlenko $
// mapnik
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
// stl // stl
@ -28,8 +29,8 @@
// boost // boost
#include <boost/tokenizer.hpp> #include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/spirit/include/qi.hpp>
namespace mapnik namespace mapnik
{ {
@ -332,31 +333,31 @@ inline
#endif #endif
bool box2d<T>::from_string(const std::string& s) bool box2d<T>::from_string(const std::string& s)
{ {
bool success = false;
boost::char_separator<char> sep(", ");
boost::tokenizer<boost::char_separator<char> > tok(s, sep);
unsigned i = 0; unsigned i = 0;
double d[4]; double d[4];
bool success = false;
boost::char_separator<char> sep(", ");
boost::tokenizer<boost::char_separator<char> > tok(s, sep);
for (boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin(); for (boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin();
beg != tok.end(); ++beg) beg != tok.end(); ++beg)
{ {
try std::string item(*beg);
{ boost::trim(item);
d[i] = boost::lexical_cast<double>(boost::trim_copy(*beg)); // note: we intentionally do not use mapnik::util::conversions::string2double
} // here to ensure that shapeindex can statically compile mapnik::box2d without
catch (boost::bad_lexical_cast & ex) // needing to link to libmapnik
std::string::const_iterator str_beg = item.begin();
std::string::const_iterator str_end = item.end();
bool r = boost::spirit::qi::phrase_parse(str_beg,str_end,boost::spirit::qi::double_,boost::spirit::ascii::space,d[i]);
if (!(r && (str_beg == str_end)))
{ {
break; break;
} }
if (i == 3) if (i == 3)
{ {
success = true; success = true;
break; break;
} }
++i; ++i;
} }

View file

@ -50,12 +50,12 @@
#include <mapnik/rule.hpp> #include <mapnik/rule.hpp>
#include <mapnik/config_error.hpp> #include <mapnik/config_error.hpp>
#include <mapnik/util/dasharray_parser.hpp> #include <mapnik/util/dasharray_parser.hpp>
#include <mapnik/util/conversions.hpp>
// boost // boost
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/tokenizer.hpp> #include <boost/tokenizer.hpp>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/xml_parser.hpp>
@ -69,8 +69,6 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
using boost::lexical_cast;
using boost::bad_lexical_cast;
using boost::tokenizer; using boost::tokenizer;
using std::endl; using std::endl;
@ -260,13 +258,12 @@ void map_parser::parse_map(Map & map, xml_node const& pt, std::string const& bas
for (boost::tokenizer<boost::char_separator<char> >::iterator beg = tokens.begin(); for (boost::tokenizer<boost::char_separator<char> >::iterator beg = tokens.begin();
beg != tokens.end(); ++beg) beg != tokens.end(); ++beg)
{ {
try std::string item(*beg);
boost::trim(item);
if (!mapnik::util::string2int(item,n[i]))
{ {
n[i] = boost::lexical_cast<int>(boost::trim_copy(*beg)); throw config_error(std::string("Invalid version string encountered: '")
} + *beg + "' in '" + *min_version_string + "'");
catch (boost::bad_lexical_cast & ex)
{
std::clog << *beg << " : " << ex.what() << "\n";
break; break;
} }
if (i==2) if (i==2)

View file

@ -149,7 +149,8 @@ std::string projection::expanded() const
if (proj_) { if (proj_) {
std::string def(pj_get_def( proj_, 0 )); std::string def(pj_get_def( proj_, 0 ));
//boost::algorithm::ireplace_first(def,params_,""); //boost::algorithm::ireplace_first(def,params_,"");
return boost::trim_copy(def); boost::trim(def);
return def;
} }
return std::string(""); return std::string("");
} }

View file

@ -144,7 +144,8 @@ private:
case rapidxml::node_data: case rapidxml::node_data:
case rapidxml::node_cdata: case rapidxml::node_cdata:
{ {
std::string trimmed = boost::algorithm::trim_copy(std::string(cur_node->value())); std::string trimmed(cur_node->value());
boost::trim(trimmed);
if (trimmed.empty()) break; //Don't add empty text nodes if (trimmed.empty()) break; //Don't add empty text nodes
node.add_child(trimmed, 0, true); node.add_child(trimmed, 0, true);
} }