[Toponaming] create ElementMap class (#9175)

* Copypaste ElementMap
* Add MappedNameRef
* Fix missing include
* Copypaste `findTagInElementName`
* fix error introduced _somewhere_
* refactor toponaming constants
* Move `findTagInElementName` in `MappedName`
* reintroduce workaround to compile ElementMap
* Added missing functions copied from complexgeodata
* fix last compile errors, reorder and format files
* remove recursive refs to ComplexGeoData
* Add more comments
* fixed comments and added tests
* added FIXME, make functions private, misc fixes
* Move static functions from complexGeoData to PostfixStringReferences. Rename to ElementNamingUtils
* Fix broken includes due to previous change
* Revert constants from string to const char*
* added childmap tests and made hasher public
* Make functions private
* Added remaining tests
* removed bool return from `erase` functions
* fix missing appexport

Co-authored-by: John Dupuy <jdupuy98@gmail.com>
This commit is contained in:
Pesc0
2023-06-15 16:05:24 +02:00
committed by GitHub
parent 32d8029780
commit 4a8d3853ba
26 changed files with 2450 additions and 218 deletions

View File

@@ -0,0 +1,88 @@
#include "ElementNamingUtils.h"
#include <boost/algorithm/string/predicate.hpp>
const char *Data::isMappedElement(const char *name) {
if(name && boost::starts_with(name, ELEMENT_MAP_PREFIX))
return name + ELEMENT_MAP_PREFIX_SIZE;
return nullptr;
}
std::string Data::newElementName(const char *name) {
if(!name)
return std::string();
const char *dot = strrchr(name,'.');
if(!dot || dot==name)
return name;
const char *c = dot-1;
for(;c!=name;--c) {
if(*c == '.') {
++c;
break;
}
}
if(isMappedElement(c))
return std::string(name,dot-name);
return name;
}
std::string Data::oldElementName(const char *name) {
if(!name)
return std::string();
const char *dot = strrchr(name,'.');
if(!dot || dot==name)
return name;
const char *c = dot-1;
for(;c!=name;--c) {
if(*c == '.') {
++c;
break;
}
}
if(isMappedElement(c))
return std::string(name,c-name)+(dot+1);
return name;
}
std::string Data::noElementName(const char *name) {
if(!name)
return std::string();
auto element = findElementName(name);
if(element)
return std::string(name,element-name);
return name;
}
const char *Data::findElementName(const char *subname) {
if(!subname || !subname[0] || isMappedElement(subname))
return subname;
const char *dot = strrchr(subname,'.');
if(!dot)
return subname;
const char *element = dot+1;
if(dot==subname || isMappedElement(element))
return element;
for(--dot;dot!=subname;--dot) {
if(*dot == '.') {
++dot;
break;
}
}
if(isMappedElement(dot))
return dot;
return element;
}
bool Data::hasMissingElement(const char *subname) {
if(!subname)
return false;
auto dot = strrchr(subname,'.');
if(dot)
subname = dot+1;
return boost::starts_with(subname, MISSING_PREFIX);
}
const char *Data::hasMappedElementName(const char *subname) {
return isMappedElement(findElementName(subname));
}