diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 470868c46a..53043ae3a1 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -53,6 +53,14 @@ bool to_uint64(char const * s, uint64_t & i) return !ss.fail(); } +bool to_int64(char const * s, int64_t & i) +{ + istringstream ss; + ss.str(s); + ss >> i; + return !ss.fail(); +} + bool to_double(char const * s, double & d) { char * stop; diff --git a/base/string_utils.hpp b/base/string_utils.hpp index ed8841f405..3d21062c5b 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -55,12 +55,14 @@ namespace utils bool to_int(char const * s, int & i); bool to_uint64(char const * s, uint64_t & i); + bool to_int64(char const * s, int64_t & i); bool to_double(char const * s, double & d); string to_string(size_t i); inline bool to_int(string const & s, int & i) { return to_int(s.c_str(), i); } inline bool to_uint64(string const & s, uint64_t & i) { return to_uint64(s.c_str(), i); } + inline bool to_int64(string const & s, int64_t & i) { return to_int64(s.c_str(), i); } inline bool to_double(string const & s, double & d) { return to_double(s.c_str(), d); } void make_lower_case(string & s); diff --git a/generator/osm_xml_parser.cpp b/generator/osm_xml_parser.cpp index 72da2821fc..f0f0b1da2f 100644 --- a/generator/osm_xml_parser.cpp +++ b/generator/osm_xml_parser.cpp @@ -202,9 +202,8 @@ namespace osm string const & elem = m_xmlTags.back(); if (attr == "id" && (elem == "node" || elem == "way" || elem == "relation")) { - uint64_t numVal; - CHECK(utils::to_uint64(value, numVal), ()); - m_id = static_cast(numVal); + CHECK(utils::to_int64(value, m_id), ()); + CHECK_NOT_EQUAL(m_id, 0, ("id == 0 is invalid")); } else if (attr == "lat" && elem == "node") { @@ -216,10 +215,10 @@ namespace osm } else if (attr == "ref") { - uint64_t numVal; - CHECK(utils::to_uint64(value, numVal), ()); + int64_t numVal; + CHECK(utils::to_int64(value, numVal), ()); if (elem == "nd") - m_ref = static_cast(numVal); + m_ref = numVal; else if (elem == "member") m_member.m_ref = numVal; }