From 8f3f1d1e4cf7e232c73a47d72427a71f4db50faa Mon Sep 17 00:00:00 2001 From: marioalexis Date: Mon, 11 Apr 2022 11:23:32 -0300 Subject: [PATCH] App: Use regex to match names in ComplexGeoData::getSubElementByName --- src/App/ComplexGeoData.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/App/ComplexGeoData.cpp b/src/App/ComplexGeoData.cpp index c3a88688cd..115458272b 100644 --- a/src/App/ComplexGeoData.cpp +++ b/src/App/ComplexGeoData.cpp @@ -28,6 +28,7 @@ #endif #include +#include #include "ComplexGeoData.h" #include @@ -54,14 +55,16 @@ ComplexGeoData::~ComplexGeoData() Data::Segment* ComplexGeoData::getSubElementByName(const char* name) const { - int index = 0; - std::string element(name); - std::string::size_type pos = element.find_first_of("0123456789"); - if (pos != std::string::npos) { - index = std::atoi(element.substr(pos).c_str()); - element = element.substr(0, pos); - } - + int index = 0; + std::string element; + boost::regex ex("^([^0-9]*)([0-9]*)$"); + boost::cmatch what; + + if (boost::regex_match(name, what, ex)) { + element = what[1].str(); + index = std::atoi(what[2].str().c_str()); + } + return getSubElement(element.c_str(), static_cast(index)); }