App: Use regex to match names in ComplexGeoData::getSubElementByName
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#endif
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include "ComplexGeoData.h"
|
||||
#include <Base/BoundBox.h>
|
||||
@@ -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<unsigned long>(index));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user