Part: TopoShape make getElementTypeAndIndex more robust (#25913)
* Part: TopoShape make getElementTypeAndIndex more robust * Part: Add unit tests for new regex --------- Co-authored-by: Chris Hennes <chennes@gmail.com>
This commit is contained in:
@@ -299,7 +299,9 @@ std::pair<std::string, unsigned long> TopoShape::getElementTypeAndIndex(const ch
|
||||
{
|
||||
int index = 0;
|
||||
std::string element;
|
||||
boost::regex ex("^(Face|Edge|Vertex)([1-9][0-9]*)$");
|
||||
// Regex modified to allow a prefix ending in a separator (e.g. TNP hash or Dot notation)
|
||||
// Matches "Face3", "Part.Face3", or ";#7:1;:G0...F.Face3"
|
||||
boost::regex ex("^(?:.*[.;:,])?(Face|Edge|Vertex)([1-9][0-9]*)$");
|
||||
boost::cmatch what;
|
||||
|
||||
if (Name && boost::regex_match(Name, what, ex)) {
|
||||
|
||||
@@ -78,6 +78,27 @@ TEST_F(TopoShapeTest, TestElementTypeNull)
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeWithHash)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(";#7:1;:G0;XTR;:H11a6:8,F.Face3"),
|
||||
std::make_pair(std::string("Face"), 3UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeWithSubelements)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex("Part.Body.Pad.Face3"),
|
||||
std::make_pair(std::string("Face"), 3UL));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestElementTypeNonMatching)
|
||||
{
|
||||
for (std::array elements = {"Face0", "Face01", "XFace3", "Face3extra"};
|
||||
const auto& element : elements) {
|
||||
EXPECT_EQ(Part::TopoShape::getElementTypeAndIndex(element),
|
||||
std::make_pair(std::string(), 0UL));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeTest, TestTypeFace1)
|
||||
{
|
||||
EXPECT_EQ(Part::TopoShape::getTypeAndIndex("Face1"),
|
||||
|
||||
Reference in New Issue
Block a user