From 3893754537114f8084c8fe9a92354c223ec51296 Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 21 Jul 2020 11:52:32 +0100 Subject: [PATCH] Refactor dynamics lat/lon parsing Using C++11 idioms, and avoid conversion to C strings for atof --- src/Airports/dynamicloader.cxx | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Airports/dynamicloader.cxx b/src/Airports/dynamicloader.cxx index d12e5addb..98651fceb 100644 --- a/src/Airports/dynamicloader.cxx +++ b/src/Airports/dynamicloader.cxx @@ -38,22 +38,17 @@ using std::string; ****************************************************************************/ static double processPosition(const string &pos) { - string prefix; - string subs; - string degree; - string decimal; - int sign = 1; - double value; - subs = pos; - prefix= subs.substr(0,1); - if (prefix == string("S") || (prefix == string("W"))) - sign = -1; - subs = subs.substr(1, subs.length()); - degree = subs.substr(0, subs.find(" ",0)); - decimal = subs.substr(subs.find(" ",0), subs.length()); + string subs{pos}; + int sign = 1; + const auto prefix = subs.substr(0, 1); + if (prefix == "S" || (prefix == "W")) + sign = -1; + subs = subs.substr(1, subs.length()); // drop first character + const auto spacePos = subs.find(" ", 0); + const auto degree = subs.substr(0, spacePos); + const auto decimal = subs.substr(spacePos, subs.length()); - value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0); - return value; + return sign * stoi(degree) + (stof(decimal) / 60.0); } FGGroundNetXMLLoader::FGGroundNetXMLLoader(FGGroundNetwork* net):