Toposhape/Part: cleanup and test getElementName

This commit is contained in:
bgbsww
2024-02-27 10:11:35 -05:00
parent 59b563ca69
commit 7d0afaec54
8 changed files with 98 additions and 89 deletions

View File

@@ -4054,17 +4054,18 @@ Data::MappedName TopoShape::setElementComboName(const Data::IndexedName& element
return elementMap()->setElementName(element, newName, Tag, &sids);
}
std::vector<Data::MappedName>
TopoShape::decodeElementComboName(const Data::IndexedName &element,
const Data::MappedName &name,
const char *marker,
std::string *postfix) const
std::vector<Data::MappedName> TopoShape::decodeElementComboName(const Data::IndexedName& element,
const Data::MappedName& name,
const char* marker,
std::string* postfix) const
{
std::vector<Data::MappedName> names;
if (!element)
if (!element) {
return names;
if (!marker)
}
if (!marker) {
marker = "";
}
int plen = (int)elementMapPrefix().size();
int markerLen = strlen(marker);
int len;
@@ -4079,7 +4080,8 @@ TopoShape::decodeElementComboName(const Data::IndexedName &element,
if (len < 0) {
// No bracket is also possible, if there is only one name in the combo
pos = len = name.size();
} else {
}
else {
pos = name.find(")");
if (pos < 0) {
// non closing bracket?
@@ -4087,20 +4089,21 @@ TopoShape::decodeElementComboName(const Data::IndexedName &element,
}
++pos;
}
if (len <= (int)markerLen)
if (len <= (int)markerLen) {
return {};
len -= markerLen+plen;
}
len -= markerLen + plen;
}
if (name.find(elementMapPrefix(), len) != len
|| name.find(marker, len+plen) != len+plen)
if (name.find(elementMapPrefix(), len) != len || name.find(marker, len + plen) != len + plen) {
return {};
}
names.emplace_back(name, 0, len);
std::string text;
len += plen + markerLen;
name.toString(text, len, pos-len);
name.appendToBuffer(text, len, pos - len);
if (this->Hasher) {
if (auto id = App::StringID::fromString(names.back().toRawBytes())) {
@@ -4108,30 +4111,37 @@ TopoShape::decodeElementComboName(const Data::IndexedName &element,
names.pop_back();
names.emplace_back(sid);
}
else
else {
return names;
}
}
if (auto id = App::StringID::fromString(text.c_str())) {
if (App::StringIDRef sid = this->Hasher->getID(id))
if (App::StringIDRef sid = this->Hasher->getID(id)) {
text = sid.dataToText();
else
}
else {
return names;
}
}
}
if (text.empty() || text[0] != '(')
if (text.empty() || text[0] != '(') {
return names;
}
auto endPos = text.rfind(')');
if (endPos == std::string::npos)
if (endPos == std::string::npos) {
return names;
}
if (postfix)
*postfix = text.substr(endPos+1);
if (postfix) {
*postfix = text.substr(endPos + 1);
}
text.resize(endPos);
std::istringstream iss(text.c_str()+1);
std::istringstream iss(text.c_str() + 1);
std::string token;
while(std::getline(iss, token, '|'))
while (std::getline(iss, token, '|')) {
names.emplace_back(token);
}
return names;
}