[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:
@@ -116,7 +116,7 @@ void DressUp::getContinuousEdges(Part::TopoShape TopShape, std::vector< std::str
|
||||
{
|
||||
std::string aSubName = static_cast<std::string>(SubNames.at(i));
|
||||
|
||||
if (aSubName.size() > 4 && aSubName.substr(0,4) == "Edge") {
|
||||
if (aSubName.compare(0, 4, "Edge") == 0) {
|
||||
TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str()));
|
||||
const TopTools_ListOfShape& los = mapEdgeFace.FindFromKey(edge);
|
||||
|
||||
@@ -138,7 +138,7 @@ void DressUp::getContinuousEdges(Part::TopoShape TopShape, std::vector< std::str
|
||||
|
||||
i++;
|
||||
}
|
||||
else if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") {
|
||||
else if(aSubName.compare(0, 4, "Face") == 0) {
|
||||
TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str()));
|
||||
|
||||
TopTools_IndexedMapOfShape mapOfFaces;
|
||||
|
||||
@@ -98,12 +98,12 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
|
||||
axis = refSketch->getAxis(Part::Part2DObject::V_Axis);
|
||||
else if (subStrings[0] == "N_Axis")
|
||||
axis = refSketch->getAxis(Part::Part2DObject::N_Axis);
|
||||
else if (subStrings[0].size() > 4 && subStrings[0].substr(0,4) == "Axis") {
|
||||
else if (subStrings[0].compare(0, 4, "Axis") == 0) {
|
||||
int AxId = std::atoi(subStrings[0].substr(4,4000).c_str());
|
||||
if (AxId >= 0 && AxId < refSketch->getAxisCount())
|
||||
axis = refSketch->getAxis(AxId);
|
||||
}
|
||||
else if (subStrings[0].substr(0,4) == "Edge") {
|
||||
else if (subStrings[0].compare(0, 4, "Edge") == 0) {
|
||||
Part::TopoShape refShape = refSketch->Shape.getShape();
|
||||
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
|
||||
TopoDS_Edge refEdge = TopoDS::Edge(ref);
|
||||
|
||||
@@ -85,7 +85,7 @@ App::DocumentObjectExecReturn *Loft::execute(void)
|
||||
// only take the entire shape when we have a sketch selected, but
|
||||
// not a point of the sketch
|
||||
if (feature->isDerivedFrom(Part::Part2DObject::getClassTypeId()) &&
|
||||
!(subName.size() > 6 && subName.substr(0,6) == "Vertex"))
|
||||
subName.compare(0, 6, "Vertex") != 0)
|
||||
return static_cast<Part::Part2DObject*>(feature)->Shape.getValue();
|
||||
else {
|
||||
if(subName.empty())
|
||||
|
||||
@@ -77,7 +77,7 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
|
||||
axis = refSketch->getAxis(Part::Part2DObject::H_Axis);
|
||||
else if (subStrings[0] == "")
|
||||
axis = refSketch->getAxis(Part::Part2DObject::N_Axis);
|
||||
else if (subStrings[0].size() > 4 && subStrings[0].substr(0,4) == "Axis") {
|
||||
else if (subStrings[0].compare(0, 4, "Axis") == 0) {
|
||||
int AxId = std::atoi(subStrings[0].substr(4,4000).c_str());
|
||||
if (AxId >= 0 && AxId < refSketch->getAxisCount()) {
|
||||
axis = refSketch->getAxis(AxId);
|
||||
|
||||
@@ -123,7 +123,7 @@ App::DocumentObjectExecReturn *Pipe::execute(void)
|
||||
// only take the entire shape when we have a sketch selected, but
|
||||
// not a point of the sketch
|
||||
if (feature->isDerivedFrom(Part::Part2DObject::getClassTypeId()) &&
|
||||
!(subName.compare(0, 6, "Vertex") == 0))
|
||||
subName.compare(0, 6, "Vertex") != 0)
|
||||
return static_cast<Part::Part2DObject*>(feature)->Shape.getValue();
|
||||
else {
|
||||
if(subName.empty())
|
||||
@@ -490,7 +490,7 @@ void Pipe::getContinuousEdges(Part::TopoShape /*TopShape*/, std::vector< std::st
|
||||
{
|
||||
std::string aSubName = static_cast<std::string>(SubNames.at(i));
|
||||
|
||||
if (aSubName.size() > 4 && aSubName.substr(0, 4) == "Edge") {
|
||||
if (aSubName.compare(0, 4, "Edge") == 0) {
|
||||
TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str()));
|
||||
const TopTools_ListOfShape& los = mapEdgeEdge.FindFromKey(edge);
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
|
||||
axis = refSketch->getAxis(Part::Part2DObject::V_Axis);
|
||||
else if (subStrings[0] == "N_Axis")
|
||||
axis = refSketch->getAxis(Part::Part2DObject::N_Axis);
|
||||
else if (subStrings[0].size() > 4 && subStrings[0].substr(0,4) == "Axis") {
|
||||
else if (subStrings[0].compare(0, 4, "Axis") == 0) {
|
||||
int AxId = std::atoi(subStrings[0].substr(4,4000).c_str());
|
||||
if (AxId >= 0 && AxId < refSketch->getAxisCount())
|
||||
axis = refSketch->getAxis(AxId);
|
||||
|
||||
@@ -842,13 +842,13 @@ void ProfileBased::remapSupportShape(const TopoDS_Shape& newShape)
|
||||
|
||||
for (std::vector<std::string>::iterator it = subValues.begin(); it != subValues.end(); ++it) {
|
||||
std::string shapetype;
|
||||
if (it->size() > 4 && it->substr(0,4) == "Face") {
|
||||
if (it->compare(0, 4, "Face") == 0) {
|
||||
shapetype = "Face";
|
||||
}
|
||||
else if (it->size() > 4 && it->substr(0,4) == "Edge") {
|
||||
else if (it->compare(0, 4, "Edge") == 0) {
|
||||
shapetype = "Edge";
|
||||
}
|
||||
else if (it->size() > 6 && it->substr(0,6) == "Vertex") {
|
||||
else if (it->compare(0, 6, "Vertex") == 0) {
|
||||
shapetype = "Vertex";
|
||||
}
|
||||
else {
|
||||
@@ -1073,7 +1073,7 @@ void ProfileBased::getAxis(const App::DocumentObject *pcReferenceAxis, const std
|
||||
hasValidAxis = true;
|
||||
axis = sketch->getAxis(Part::Part2DObject::N_Axis);
|
||||
}
|
||||
else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0, 4) == "Axis") {
|
||||
else if (subReferenceAxis[0].compare(0, 4, "Axis") == 0) {
|
||||
int AxId = std::atoi(subReferenceAxis[0].substr(4, 4000).c_str());
|
||||
if (AxId >= 0 && AxId < sketch->getAxisCount()) {
|
||||
hasValidAxis = true;
|
||||
|
||||
Reference in New Issue
Block a user