From 7b4680482ea5be4f20aafe17af39922708c80471 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Sun, 18 Dec 2016 23:58:45 +0100
Subject: [PATCH] ENH: use string endsWith in a few places

    fieldName.endsWith("_0")
vs
    fieldName.size() > 2 && fieldName(fieldName.size()-2, 2) == "_0"
---
 .../dataConversion/foamToEnsight/checkData.H              | 5 ++---
 .../dataConversion/foamToEnsightParts/findFields.H        | 8 ++------
 .../GeometricFields/GeometricField/GeometricField.C       | 5 +----
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H
index 73a0e174171..f33a8f727f2 100644
--- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H
+++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/checkData.H
@@ -11,9 +11,8 @@ if (!fieldsToUse.found(fieldName))
     {
         variableGood =
         (
-            fieldName.size() > 2 && fieldName(fieldName.size()-2, 2) == "_0"
-          ? false
-          : IOobject
+            !fieldName.endsWith("_0")
+         && IOobject
             (
                 fieldName,
                 timeDirs[n1].name(),
diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H
index 721ba05101a..0c841369cf8 100644
--- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H
+++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/findFields.H
@@ -19,13 +19,9 @@ if (timeDirs.size())
         const word& fieldName = obj.name();
         const word& fieldType = obj.headerClassName();
 
-        if (fieldName.size() > 2 && fieldName(fieldName.size()-2, 2) == "_0")
+        if (volFieldTypes.found(fieldType) && !fieldName.endsWith("_0"))
         {
-            // ignore _0 fields
-        }
-        else if (volFieldTypes.found(fieldType))
-        {
-            // simply ignore types that we don't handle
+            // ignore types that we don't handle, and ignore _0 fields
             volumeFields.insert(fieldName, fieldType);
         }
     }
diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C
index 8f84b90986e..e7d6ea91402 100644
--- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C
+++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C
@@ -766,10 +766,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::storeOldTimes() const
     (
         field0Ptr_
      && timeIndex_ != this->time().timeIndex()
-     && !(
-            this->name().size() > 2
-         && this->name()(this->name().size()-2, 2) == "_0"
-         )
+     && !this->name().endsWith("_0")
     )
     {
         storeOldTime();
-- 
GitLab