[PD] Use compare to compare strings instead of substr

Used when finding subelements of a feature. Many of the comparisons used to also
check for string lengths, but as far as I can tell they are not strictly
necessary (see https://www.cplusplus.com/reference/string/string/substr/) and
just `substr` can be used without them. However, `compare` explicitly is for
comparing, and does not make a new object that `substr` does.
This commit is contained in:
Ajinkya Dahale
2021-11-28 15:30:41 -05:00
committed by Uwe
parent 2fcee8ea82
commit 5e3ad45ef4
11 changed files with 25 additions and 25 deletions

View File

@@ -148,7 +148,7 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
if (pObj && pObj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
std::string subName(sSubName);
if (edge && subName.size() > 4 && subName.substr(0,4) == "Edge") {
if (edge && subName.compare(0, 4, "Edge") == 0) {
const Part::TopoShape &shape = static_cast<const Part::Feature*>(pObj)->Shape.getValue();
TopoDS_Shape sh = shape.getSubShape(subName.c_str());
const TopoDS_Edge& edgeShape = TopoDS::Edge(sh);
@@ -162,7 +162,7 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
}
}
}
if (plane && subName.size() > 4 && subName.substr(0,4) == "Face") {
if (plane && subName.compare(0, 4, "Face") == 0) {
const Part::TopoShape &shape = static_cast<const Part::Feature*>(pObj)->Shape.getValue();
TopoDS_Shape sh = shape.getSubShape(subName.c_str());
const TopoDS_Face& face = TopoDS::Face(sh);
@@ -176,10 +176,10 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
}
}
}
if (point && subName.size() > 6 && subName.substr(0,6) == "Vertex") {
if (point && subName.compare(0, 6, "Vertex") == 0) {
return true;
}
if (circle && subName.size() > 4 && subName.substr(0,4) == "Edge") {
if (circle && subName.compare(0, 4, "Edge") == 0) {
const Part::TopoShape &shape = static_cast<const Part::Feature*>(pObj)->Shape.getValue();
TopoDS_Shape sh = shape.getSubShape(subName.c_str());
const TopoDS_Edge& edgeShape = TopoDS::Edge(sh);