From 8df433860f15b42d514dd75e70a3f60c32938527 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 21 Jul 2017 12:30:42 +0200
Subject: [PATCH] STYLE: use string substr instead of string::operator()

- makes the purpose clearer.
  In some places, string::resize() is even simpler.

- use C++11 string::back() in preference to str[str.size()-1]
---
 .../fluent3DMeshToFoam/fluent3DMeshToFoam.L   |  3 +-
 .../mesh/manipulation/setSet/setSet.C         |  4 +-
 .../changeDictionary/changeDictionary.C       |  4 +-
 src/OSspecific/POSIX/POSIX.C                  |  2 +-
 src/OSspecific/POSIX/printStack.C             | 15 ++--
 src/OpenFOAM/db/dictionary/dictionaryIO.C     |  2 +-
 .../functionObjectList/functionObjectList.C   | 15 ++--
 src/OpenFOAM/dimensionSet/dimensionSetIO.C    | 16 ++---
 src/OpenFOAM/matrices/solution/solution.C     |  9 +--
 .../reactionRateFlameAreaNew.C                | 13 ++--
 .../psiCombustionModelNew.C                   | 12 ++--
 .../rhoCombustionModelNew.C                   | 14 ++--
 .../edgeMeshFormats/nas/NASedgeFormat.C       |  4 +-
 .../edgeMeshFormats/obj/OBJedgeFormat.C       |  4 +-
 .../thermalBaffleFvPatchScalarField.C         |  5 +-
 .../readers/ensight/ensightSurfaceReader.C    |  2 +-
 .../surfaceFormats/nas/NASsurfaceFormat.C     | 29 +++-----
 .../surfaceFormats/obj/OBJsurfaceFormat.C     |  4 +-
 .../surfaceFormats/tri/TRIsurfaceFormatCore.C | 16 ++---
 .../triSurface/interfaces/NAS/readNAS.C       | 40 ++++-------
 .../triSurface/interfaces/OBJ/readOBJ.C       |  6 +-
 .../triSurface/interfaces/TRI/readTRI.C       | 13 ++--
 .../radiationModels/fvDOM/fvDOM/fvDOM.C       |  6 +-
 .../sootModel/sootModel/sootModelNew.C        |  4 +-
 .../chemkinReader/chemkinLexer.L              | 69 +++++++++----------
 .../reaction/Reactions/Reaction/Reaction.C    | 11 +--
 26 files changed, 148 insertions(+), 174 deletions(-)

diff --git a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L
index ca276a03488..8898cded2c6 100644
--- a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L
+++ b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L
@@ -221,6 +221,7 @@ redundantBlock             {space}({comment}|{unknownPeriodicFace}|{periodicFace
 endOfSection               {space}")"{space}
 
 
+/* balance "-quoted for editor */
 
  /* ------------------------------------------------------------------------ *\
                       -----  Exclusive start states -----
@@ -693,7 +694,7 @@ endOfSection               {space}")"{space}
 {lbrac}{label} {
         Warning
             << "Found unknown block of type: "
-            << Foam::string(YYText())(1, YYLeng()-1) << nl
+            << std::string(YYText()).substr(1, YYLeng()-1) << nl
             << "    on line " << lineNo << endl;
 
         yy_push_state(ignoreBlock);
diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C
index 4a64e6f8011..2f5b6a5cca3 100644
--- a/applications/utilities/mesh/manipulation/setSet/setSet.C
+++ b/applications/utilities/mesh/manipulation/setSet/setSet.C
@@ -903,10 +903,10 @@ int main(int argc, char *argv[])
             }
 
             // Strip off anything after #
-            string::size_type i = rawLine.find_first_of("#");
+            string::size_type i = rawLine.find('#');
             if (i != string::npos)
             {
-                rawLine = rawLine(0, i);
+                rawLine.resize(i);
             }
 
             if (rawLine.empty())
diff --git a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C
index ea80da840ff..f9be71c75fa 100644
--- a/applications/utilities/preProcessing/changeDictionary/changeDictionary.C
+++ b/applications/utilities/preProcessing/changeDictionary/changeDictionary.C
@@ -254,7 +254,7 @@ bool merge
 
         if (key[0] == '~')
         {
-            word eraseKey = key(1, key.size()-1);
+            const word eraseKey = key.substr(1);
             if (thisDict.remove(eraseKey))
             {
                 // Mark thisDict entry as having been match for wildcard
@@ -325,7 +325,7 @@ bool merge
 
             if (key[0] == '~')
             {
-                word eraseKey = key(1, key.size()-1);
+                const word eraseKey = key.substr(1);
 
                 // List of indices into thisKeys
                 labelList matches
diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C
index d9b2e0b3a4d..3a922ed016c 100644
--- a/src/OSspecific/POSIX/POSIX.C
+++ b/src/OSspecific/POSIX/POSIX.C
@@ -88,7 +88,7 @@ static inline bool isBackupName(const Foam::fileName& name)
     {
         return false;
     }
-    else if (name[name.size()-1] == '~')
+    else if (name.back() == '~')
     {
         return true;
     }
diff --git a/src/OSspecific/POSIX/printStack.C b/src/OSspecific/POSIX/printStack.C
index bee02686b36..4031b91d77a 100644
--- a/src/OSspecific/POSIX/printStack.C
+++ b/src/OSspecific/POSIX/printStack.C
@@ -40,12 +40,11 @@ namespace Foam
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-string pOpen(const string &cmd, label line=0)
+string pOpen(const string& cmd, label line=0)
 {
-    string res = "\n";
+    string res;
 
     FILE *cmdPipe = popen(cmd.c_str(), "r");
-
     if (cmdPipe)
     {
         char *buf = nullptr;
@@ -54,8 +53,7 @@ string pOpen(const string &cmd, label line=0)
         for (label cnt = 0; cnt <= line; cnt++)
         {
             size_t linecap = 0;
-            ssize_t linelen;
-            linelen = ::getline(&buf, &linecap, cmdPipe);
+            ssize_t linelen = ::getline(&buf, &linecap, cmdPipe);
 
             if (linelen < 0)
             {
@@ -65,6 +63,11 @@ string pOpen(const string &cmd, label line=0)
             if (cnt == line)
             {
                 res = string(buf);
+                // Trim trailing newline
+                if (res.size())
+                {
+                    res.resize(res.size()-1);
+                }
                 break;
             }
         }
@@ -77,7 +80,7 @@ string pOpen(const string &cmd, label line=0)
         pclose(cmdPipe);
     }
 
-    return res.substr(0, res.size() - 1);
+    return res;
 }
 
 
diff --git a/src/OpenFOAM/db/dictionary/dictionaryIO.C b/src/OpenFOAM/db/dictionary/dictionaryIO.C
index 836add62f94..f1605e50fa7 100644
--- a/src/OpenFOAM/db/dictionary/dictionaryIO.C
+++ b/src/OpenFOAM/db/dictionary/dictionaryIO.C
@@ -130,7 +130,7 @@ bool Foam::dictionary::read(Istream& is)
 
 bool Foam::dictionary::substituteKeyword(const word& keyword, bool mergeEntry)
 {
-    const word varName = keyword(1, keyword.size()-1);
+    const word varName = keyword.substr(1);
 
     // Lookup the variable name in the given dictionary
     const entry* ePtr = lookupEntryPtr(varName, true, true);
diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
index 397262386b9..37db0a30671 100644
--- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
+++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C
@@ -210,7 +210,7 @@ bool Foam::functionObjectList::readFunctionObject
         {
             if (argLevel == 0)
             {
-                funcName = funcNameArgs(start, i - start);
+                funcName = funcNameArgs.substr(start, i - start);
                 start = i+1;
             }
             ++argLevel;
@@ -226,7 +226,7 @@ bool Foam::functionObjectList::readFunctionObject
                         Tuple2<word, string>
                         (
                             argName,
-                            funcNameArgs(start, i - start)
+                            funcNameArgs.substr(start, i - start)
                         )
                     );
                     namedArg = false;
@@ -235,7 +235,10 @@ bool Foam::functionObjectList::readFunctionObject
                 {
                     args.append
                     (
-                        string::validate<word>(funcNameArgs(start, i - start))
+                        string::validate<word>
+                        (
+                            funcNameArgs.substr(start, i - start)
+                        )
                     );
                 }
                 start = i+1;
@@ -252,7 +255,11 @@ bool Foam::functionObjectList::readFunctionObject
         }
         else if (c == '=')
         {
-            argName = string::validate<word>(funcNameArgs(start, i - start));
+            argName = string::validate<word>
+            (
+                funcNameArgs.substr(start, i - start)
+            );
+
             start = i+1;
             namedArg = true;
         }
diff --git a/src/OpenFOAM/dimensionSet/dimensionSetIO.C b/src/OpenFOAM/dimensionSet/dimensionSetIO.C
index 768acc8efc8..032555cd25b 100644
--- a/src/OpenFOAM/dimensionSet/dimensionSetIO.C
+++ b/src/OpenFOAM/dimensionSet/dimensionSetIO.C
@@ -140,7 +140,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
         {
             if (i > start)
             {
-                word subWord = w(start, i-start);
+                const word subWord = w.substr(start, i-start);
                 if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
                 {
                     push(token(readScalar(IStringStream(subWord)())));
@@ -166,7 +166,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
     }
     if (start < w.size())
     {
-        word subWord = w(start, w.size()-start);
+        const word subWord = w.substr(start);
         if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
         {
             push(token(readScalar(IStringStream(subWord)())));
@@ -524,9 +524,9 @@ Foam::Istream& Foam::dimensionSet::read
         do
         {
             word symbolPow = nextToken.wordToken();
-            if (symbolPow[symbolPow.size()-1] == token::END_SQR)
+            if (symbolPow.back() == token::END_SQR)
             {
-                symbolPow = symbolPow(0, symbolPow.size()-1);
+                symbolPow.resize(symbolPow.size()-1);
                 continueParsing = false;
             }
 
@@ -537,8 +537,8 @@ Foam::Istream& Foam::dimensionSet::read
             size_t index = symbolPow.find('^');
             if (index != string::npos)
             {
-                word symbol = symbolPow(0, index);
-                word exp = symbolPow(index+1, symbolPow.size()-index+1);
+                const word symbol = symbolPow.substr(0, index);
+                const word exp = symbolPow.substr(index+1);
                 scalar exponent = readScalar(IStringStream(exp)());
 
                 dimensionedScalar s;
@@ -580,9 +580,9 @@ Foam::Istream& Foam::dimensionSet::read
     {
         // Read first five dimensions
         exponents_[dimensionSet::MASS] = nextToken.number();
-        for (int Dimension=1; Dimension<dimensionSet::CURRENT; Dimension++)
+        for (int d=1; d < dimensionSet::CURRENT; ++d)
         {
-            is >> exponents_[Dimension];
+            is >> exponents_[d];
         }
 
         // Read next token
diff --git a/src/OpenFOAM/matrices/solution/solution.C b/src/OpenFOAM/matrices/solution/solution.C
index 5abac0fa3e2..982c3398b65 100644
--- a/src/OpenFOAM/matrices/solution/solution.C
+++ b/src/OpenFOAM/matrices/solution/solution.C
@@ -76,16 +76,13 @@ void Foam::solution::read(const dictionary& dict)
                 const word& e = entryNames[i];
                 scalar value = readScalar(relaxDict.lookup(e));
 
-                if (e(0, 1) == "p")
+                if (e.startsWith("p"))
                 {
                     fieldRelaxDict_.add(e, value);
                 }
-                else if (e.length() >= 3)
+                else if (e.startsWith("rho"))
                 {
-                    if (e(0, 3) == "rho")
-                    {
-                        fieldRelaxDict_.add(e, value);
-                    }
+                    fieldRelaxDict_.add(e, value);
                 }
 
             }
diff --git a/src/combustionModels/FSD/reactionRateFlameAreaModels/reactionRateFlameArea/reactionRateFlameAreaNew.C b/src/combustionModels/FSD/reactionRateFlameAreaModels/reactionRateFlameArea/reactionRateFlameAreaNew.C
index 2154d2cc948..83222a222bf 100644
--- a/src/combustionModels/FSD/reactionRateFlameAreaModels/reactionRateFlameArea/reactionRateFlameAreaNew.C
+++ b/src/combustionModels/FSD/reactionRateFlameAreaModels/reactionRateFlameArea/reactionRateFlameAreaNew.C
@@ -34,16 +34,15 @@ Foam::autoPtr<Foam::reactionRateFlameArea> Foam::reactionRateFlameArea::New
     const combustionModel& combModel
 )
 {
-    word reactionRateFlameAreaType
+    const word modelType
     (
         dict.lookup("reactionRateFlameArea")
     );
 
     Info<< "Selecting reaction rate flame area correlation "
-        << reactionRateFlameAreaType << endl;
+        << modelType << endl;
 
-    auto cstrIter =
-        dictionaryConstructorTablePtr_->cfind(reactionRateFlameAreaType);
+    auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
 
     if (!cstrIter.found())
     {
@@ -51,15 +50,13 @@ Foam::autoPtr<Foam::reactionRateFlameArea> Foam::reactionRateFlameArea::New
         (
             dict
         )   << "Unknown reactionRateFlameArea type "
-            << reactionRateFlameAreaType << nl << nl
+            << modelType << nl << nl
             << "Valid reaction rate flame area types :" << endl
             << dictionaryConstructorTablePtr_->sortedToc()
             << exit(FatalIOError);
     }
 
-    const label tempOpen = reactionRateFlameAreaType.find('<');
-
-    const word className = reactionRateFlameAreaType(0, tempOpen);
+    const word className = modelType.substr(0, modelType.find('<'));
 
     return autoPtr<reactionRateFlameArea>
         (cstrIter()(className, dict, mesh, combModel));
diff --git a/src/combustionModels/psiCombustionModel/psiCombustionModel/psiCombustionModelNew.C b/src/combustionModels/psiCombustionModel/psiCombustionModel/psiCombustionModelNew.C
index ca7d0616b8d..50e69d177db 100644
--- a/src/combustionModels/psiCombustionModel/psiCombustionModel/psiCombustionModelNew.C
+++ b/src/combustionModels/psiCombustionModel/psiCombustionModel/psiCombustionModelNew.C
@@ -35,7 +35,7 @@ Foam::combustionModels::psiCombustionModel::New
     const word& phaseName
 )
 {
-    const word combModelName
+    const word modelType
     (
         IOdictionary
         (
@@ -51,21 +51,21 @@ Foam::combustionModels::psiCombustionModel::New
         ).lookup("combustionModel")
     );
 
-    Info<< "Selecting combustion model " << combModelName << endl;
+    Info<< "Selecting combustion model " << modelType << endl;
 
-    auto cstrIter = dictionaryConstructorTablePtr_->cfind(combModelName);
+    auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
 
     if (!cstrIter.found())
     {
         FatalErrorInFunction
             << "Unknown psiCombustionModel type "
-            << combModelName << endl << endl
-            << "Valid combustionModel types :" << endl
+            << modelType << nl << nl
+            << "Valid combustionModel types :" << nl
             << dictionaryConstructorTablePtr_->sortedToc()
             << exit(FatalError);
     }
 
-    const word className = combModelName(0, combModelName.find('<'));
+    const word className = modelType.substr(0, modelType.find('<'));
 
     return autoPtr<psiCombustionModel>
     (
diff --git a/src/combustionModels/rhoCombustionModel/rhoCombustionModel/rhoCombustionModelNew.C b/src/combustionModels/rhoCombustionModel/rhoCombustionModel/rhoCombustionModelNew.C
index f6ffadc0b6a..fb03177606a 100644
--- a/src/combustionModels/rhoCombustionModel/rhoCombustionModel/rhoCombustionModelNew.C
+++ b/src/combustionModels/rhoCombustionModel/rhoCombustionModel/rhoCombustionModelNew.C
@@ -35,7 +35,7 @@ Foam::combustionModels::rhoCombustionModel::New
     const word& phaseName
 )
 {
-    const word combTypeName
+    const word modelType
     (
         IOdictionary
         (
@@ -51,23 +51,21 @@ Foam::combustionModels::rhoCombustionModel::New
         ).lookup("combustionModel")
     );
 
-    Info<< "Selecting combustion model " << combTypeName << endl;
+    Info<< "Selecting combustion model " << modelType << endl;
 
-    auto cstrIter = dictionaryConstructorTablePtr_->cfind(combTypeName);
+    auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
 
     if (!cstrIter.found())
     {
         FatalErrorInFunction
             << "Unknown rhoCombustionModel type "
-            << combTypeName << endl << endl
-            << "Valid combustionModel types :" << endl
+            << modelType << nl << nl
+            << "Valid combustionModel types :" << nl
             << dictionaryConstructorTablePtr_->sortedToc()
             << exit(FatalError);
     }
 
-    const label tempOpen = combTypeName.find('<');
-
-    const word className = combTypeName(0, tempOpen);
+    const word className = modelType.substr(0, modelType.find('<'));
 
     return autoPtr<rhoCombustionModel>
     (
diff --git a/src/meshTools/edgeMesh/edgeMeshFormats/nas/NASedgeFormat.C b/src/meshTools/edgeMesh/edgeMeshFormats/nas/NASedgeFormat.C
index 7bd0acab4fa..7bcc2d32439 100644
--- a/src/meshTools/edgeMesh/edgeMeshFormats/nas/NASedgeFormat.C
+++ b/src/meshTools/edgeMesh/edgeMeshFormats/nas/NASedgeFormat.C
@@ -74,7 +74,7 @@ bool Foam::fileFormats::NASedgeFormat::read
         // Check if character 72 is continuation
         if (line.size() > 72 && line[72] == '+')
         {
-            line = line.substr(0, 72);
+            line.resize(72);
 
             while (true)
             {
@@ -87,7 +87,7 @@ bool Foam::fileFormats::NASedgeFormat::read
                 }
                 else
                 {
-                    line += buf.substr(8, buf.size()-8);
+                    line += buf.substr(8);
                     break;
                 }
             }
diff --git a/src/meshTools/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C b/src/meshTools/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C
index 1261b971cf1..e0af5e0e764 100644
--- a/src/meshTools/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C
+++ b/src/meshTools/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C
@@ -117,9 +117,9 @@ bool Foam::fileFormats::OBJedgeFormat::read(const fileName& filename)
         string line = this->getLineNoComment(is);
 
         // handle continuations
-        if (line[line.size()-1] == '\\')
+        if (line.back() == '\\')
         {
-            line.substr(0, line.size()-1);
+            line.resize(line.size()-1);
             line += this->getLineNoComment(is);
         }
 
diff --git a/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C b/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C
index ca1f1511c06..58f78403985 100644
--- a/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C
+++ b/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C
@@ -191,9 +191,8 @@ void thermalBaffleFvPatchScalarField::createPatchMesh()
     dicts[bottomPatchID].add("inGroups", inGroups);
     dicts[bottomPatchID].add("sampleMode", mpp.sampleModeNames_[mpp.mode()]);
 
-    const label sepPos = coupleGroup.find('_');
-
-    const word coupleGroupSlave = coupleGroup(0, sepPos) + "_slave";
+    const word coupleGroupSlave =
+        coupleGroup.substr(0, coupleGroup.find('_')) + "_slave";
 
     inGroups[0] = coupleGroupSlave;
     dicts[topPatchID].add("coupleGroup", coupleGroupSlave);
diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C
index 2c21271939d..38a51d61411 100644
--- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C
+++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReader.C
@@ -186,7 +186,7 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
         //   surfaceName.****.fieldName
         // This is not parser friendly - simply take remainder of buffer
         label iPos = iss.stdStream().tellg();
-        fieldFileName = buffer(iPos, buffer.size() - iPos);
+        fieldFileName = buffer.substr(iPos);
         size_t p0  = fieldFileName.find_first_not_of(' ');
         if (p0 == string::npos)
         {
diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C
index 7f64549e9c2..3bcc0351883 100644
--- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C
@@ -89,12 +89,12 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
         string line;
         is.getLine(line);
 
-        // Ansa extension
-        if (line.substr(0, 10) == "$ANSA_NAME")
+        // ANSA extension
+        if (line.startsWith("$ANSA_NAME"))
         {
-            string::size_type sem0 = line.find (';', 0);
-            string::size_type sem1 = line.find (';', sem0+1);
-            string::size_type sem2 = line.find (';', sem1+1);
+            string::size_type sem0 = line.find(';', 0);
+            string::size_type sem1 = line.find(';', sem0+1);
+            string::size_type sem2 = line.find(';', sem1+1);
 
             if
             (
@@ -111,14 +111,11 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
 
                 string rawName;
                 is.getLine(rawName);
-                if (rawName[rawName.size()-1] == '\r')
+                if (rawName.back() == '\r')
                 {
-                    rawName = rawName.substr(1, rawName.size()-2);
-                }
-                else
-                {
-                    rawName = rawName.substr(1, rawName.size()-1);
+                    rawName.resize(rawName.size()-1);
                 }
+                rawName = rawName.substr(1);
 
                 string::stripInvalid<word>(rawName);
                 ansaName = rawName;
@@ -132,11 +129,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
 
         // Hypermesh extension
         // $HMNAME COMP                   1"partName"
-        if
-        (
-            line.substr(0, 12) == "$HMNAME COMP"
-         && line.find ('"') != string::npos
-        )
+        if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
         {
             label groupId = readLabel
             (
@@ -165,7 +158,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
         // Check if character 72 is continuation
         if (line.size() > 72 && line[72] == '+')
         {
-            line = line.substr(0, 72);
+            line.resize(72);
 
             while (true)
             {
@@ -178,7 +171,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
                 }
                 else
                 {
-                    line += buf.substr(8, buf.size()-8);
+                    line += buf.substr(8);
                     break;
                 }
             }
diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
index 708f7654e97..692f2ee3bc4 100644
--- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
+++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C
@@ -82,9 +82,9 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
         string line = this->getLineNoComment(is);
 
         // handle continuations
-        if (line[line.size()-1] == '\\')
+        if (line.back() == '\\')
         {
-            line.substr(0, line.size()-1);
+            line.resize(line.size()-1);
             line += this->getLineNoComment(is);
         }
 
diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C
index 97b4112f9b6..385ad872abf 100644
--- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C
+++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C
@@ -87,9 +87,9 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
         string line = this->getLineNoComment(is);
 
         // handle continuations ?
-        //          if (line[line.size()-1] == '\\')
+        //          if (line.back() == '\\')
         //          {
-        //              line.substr(0, line.size()-1);
+        //              line.resize(line.size()-1);
         //              line += this->getLineNoComment(is);
         //          }
 
@@ -128,14 +128,14 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
         // ie, instead of having 0xFF, skip 0 and leave xFF to
         // get read as a word and name it "zoneFF"
 
-        char zero;
-        lineStream >> zero;
+        char zeroChar;
+        lineStream >> zeroChar;
 
-        word rawName(lineStream);
-        word name("zone" + rawName(1, rawName.size()-1));
+        const word rawName(lineStream);
+        const word name("zone" + rawName.substr(1));
 
-        HashTable<label>::const_iterator fnd = lookup.find(name);
-        if (fnd != lookup.end())
+        HashTable<label>::const_iterator fnd = lookup.cfind(name);
+        if (fnd.found())
         {
             if (zoneI != fnd())
             {
diff --git a/src/surfMesh/triSurface/interfaces/NAS/readNAS.C b/src/surfMesh/triSurface/interfaces/NAS/readNAS.C
index 42196867735..0653ea8f013 100644
--- a/src/surfMesh/triSurface/interfaces/NAS/readNAS.C
+++ b/src/surfMesh/triSurface/interfaces/NAS/readNAS.C
@@ -32,7 +32,6 @@ Description
         GRID          28        10.20269-.030265-2.358-8
     \endverbatim
 
-
 \*---------------------------------------------------------------------------*/
 
 #include "triSurface.H"
@@ -78,11 +77,8 @@ static std::string readNASToken
     size_t& index
 )
 {
-    size_t indexStart, indexEnd;
-
-    indexStart = index;
-
-    indexEnd = line.find(',', indexStart);
+    size_t indexStart = index;
+    size_t indexEnd = line.find(',', indexStart);
     index = indexEnd + 1;
 
     if (indexEnd == std::string::npos)
@@ -134,12 +130,12 @@ bool triSurface::readNAS(const fileName& fName)
         string line;
         is.getLine(line);
 
-        // Ansa extension
-        if (line.substr(0, 10) == "$ANSA_NAME")
+        // ANSA extension
+        if (line.startsWith("$ANSA_NAME"))
         {
-            string::size_type sem0 = line.find (';', 0);
-            string::size_type sem1 = line.find (';', sem0+1);
-            string::size_type sem2 = line.find (';', sem1+1);
+            string::size_type sem0 = line.find(';', 0);
+            string::size_type sem1 = line.find(';', sem0+1);
+            string::size_type sem2 = line.find(';', sem1+1);
 
             if
             (
@@ -156,15 +152,11 @@ bool triSurface::readNAS(const fileName& fName)
 
                 string nameString;
                 is.getLine(ansaName);
-                if (ansaName[ansaName.size()-1] == '\r')
+                if (ansaName.back() == '\r')
                 {
-                    ansaName = ansaName.substr(1, ansaName.size()-2);
+                    ansaName.resize(ansaName.size()-1);
                 }
-                else
-                {
-                    ansaName = ansaName.substr(1, ansaName.size()-1);
-                }
-
+                ansaName = ansaName.substr(1);
                 // Info<< "ANSA tag for NastranID:" << ansaId
                 //     << " of type " << ansaType
                 //     << " name " << ansaName << endl;
@@ -174,11 +166,7 @@ bool triSurface::readNAS(const fileName& fName)
 
         // Hypermesh extension
         // $HMNAME COMP                   1"partName"
-        if
-        (
-            line.substr(0, 12) == "$HMNAME COMP"
-         && line.find ('"') != string::npos
-        )
+        if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
         {
             label groupId = readLabel
             (
@@ -204,20 +192,20 @@ bool triSurface::readNAS(const fileName& fName)
         // Check if character 72 is continuation
         if (line.size() > 72 && line[72] == '+')
         {
-            line = line.substr(0, 72);
+            line.resize(72);
 
             while (true)
             {
                 string buf;
                 is.getLine(buf);
 
-                if (buf.size() > 72 && buf[72]=='+')
+                if (buf.size() > 72 && buf[72] == '+')
                 {
                     line += buf.substr(8, 64);
                 }
                 else
                 {
-                    line += buf.substr(8, buf.size()-8);
+                    line += buf.substr(8);
                     break;
                 }
             }
diff --git a/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C b/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C
index 9a5f3fe4996..42393a1af01 100644
--- a/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C
+++ b/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C
@@ -51,13 +51,13 @@ bool Foam::triSurface::readOBJ(const fileName& OBJfileName)
     {
         string line = getLineNoComment(OBJfile);
 
-        label sz = line.size();
+        const label sz = line.size();
 
         if (sz)
         {
-            if (line[sz-1] == '\\')
+            if (line.back() == '\\')
             {
-                line.substr(0, sz-1);
+                line.resize(sz-1);
                 line += getLineNoComment(OBJfile);
             }
 
diff --git a/src/surfMesh/triSurface/interfaces/TRI/readTRI.C b/src/surfMesh/triSurface/interfaces/TRI/readTRI.C
index 841ab10692d..b8190d39d54 100644
--- a/src/surfMesh/triSurface/interfaces/TRI/readTRI.C
+++ b/src/surfMesh/triSurface/interfaces/TRI/readTRI.C
@@ -99,19 +99,18 @@ bool Foam::triSurface::readTRI(const fileName& TRIfileName)
 
         // Region/colour in .tri file starts with 0x. Skip.
 
-        char zero;
-        lineStream >> zero;
+        char zeroChar;
+        lineStream >> zeroChar;
 
-        word rawSolidName(lineStream);
+        const word rawSolidName(lineStream);
 
-        word solidName("patch" + rawSolidName(1, rawSolidName.size()-1));
+        const word solidName("patch" + rawSolidName.substr(1));
 
         label region  = -1;
 
-        HashTable<label, string>::const_iterator fnd =
-            STLsolidNames.find(solidName);
+        auto fnd = STLsolidNames.cfind(solidName);
 
-        if (fnd != STLsolidNames.end())
+        if (fnd.found())
         {
             region = fnd();
         }
diff --git a/src/thermophysicalModels/radiation/radiationModels/fvDOM/fvDOM/fvDOM.C b/src/thermophysicalModels/radiation/radiationModels/fvDOM/fvDOM/fvDOM.C
index 23fd128691b..3eace6af4cd 100644
--- a/src/thermophysicalModels/radiation/radiationModels/fvDOM/fvDOM/fvDOM.C
+++ b/src/thermophysicalModels/radiation/radiationModels/fvDOM/fvDOM/fvDOM.C
@@ -531,11 +531,11 @@ void Foam::radiation::fvDOM::setRayIdLambdaId
 ) const
 {
     // assuming name is in the form: CHARS_rayId_lambdaId
-    size_type i1 = name.find_first_of("_");
-    size_type i2 = name.find_last_of("_");
+    const size_type i1 = name.find('_');
+    const size_type i2 = name.rfind('_');
 
     rayId = readLabel(IStringStream(name.substr(i1+1, i2-1))());
-    lambdaId = readLabel(IStringStream(name.substr(i2+1, name.size()-1))());
+    lambdaId = readLabel(IStringStream(name.substr(i2+1))());
 }
 
 
diff --git a/src/thermophysicalModels/radiation/submodels/sootModel/sootModel/sootModelNew.C b/src/thermophysicalModels/radiation/submodels/sootModel/sootModel/sootModelNew.C
index 18fc90ada9f..a9af94a66f5 100644
--- a/src/thermophysicalModels/radiation/submodels/sootModel/sootModel/sootModelNew.C
+++ b/src/thermophysicalModels/radiation/submodels/sootModel/sootModel/sootModelNew.C
@@ -56,9 +56,7 @@ Foam::radiation::sootModel::New
             << exit(FatalError);
     }
 
-    const label tempOpen = modelType.find('<');
-
-    const word className = modelType(0, tempOpen);
+    const word className = modelType.substr(0, modelType.find('<'));
 
     return autoPtr<sootModel>(cstrIter()(dict, mesh, className));
 }
diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L
index 79eca025078..c016113a19c 100644
--- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L
+++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L
@@ -382,7 +382,7 @@ bool finishReaction = false;
     }
 
 <readSpecies>{specieName} {
-        word specieName(foamName(foamSpecieString(YYText())));
+        const word specieName(foamName(foamSpecieString(YYText())));
 
         if (specieName == "THERMO")
         {
@@ -429,10 +429,10 @@ bool finishReaction = false;
     }
 
 <readThermoAll>{thermoTemp}{thermoTemp}{thermoTemp} {
-        string temperaturesString(YYText());
-        //scalar lowestT(stringToScalar(temperaturesString(0, 10)));
-        allCommonT = stringToScalar(temperaturesString(10, 10));
-        //scalar highestT(stringToScalar(temperaturesString(20, 10)));
+        const string temperaturesString(YYText());
+        //scalar lowestT(stringToScalar(temperaturesString.substr(0, 10)));
+        allCommonT = stringToScalar(temperaturesString.substr(10, 10));
+        //scalar highestT(stringToScalar(temperaturesString.substr(20, 10)));
         BEGIN(readThermoSpecieName);
     }
 
@@ -449,7 +449,7 @@ bool finishReaction = false;
             size_t spacePos = specieString.find(' ');
             if (spacePos != string::npos)
             {
-                currentSpecieName = specieString(0, spacePos);
+                currentSpecieName = specieString.substr(0, spacePos);
             }
             else
             {
@@ -467,15 +467,15 @@ bool finishReaction = false;
     }
 
 <readThermoFormula>{thermoFormula} {
-        string thermoFormula(YYText());
+        const string thermoFormula(YYText());
 
         nSpecieElements = 0;
         currentSpecieComposition.setSize(5);
 
         for (int i=0; i<4; i++)
         {
-            word elementName(foamName(thermoFormula(5*i, 2)));
-            label nAtoms = atoi(thermoFormula(5*i + 2, 3).c_str());
+            word elementName(foamName(thermoFormula.substr(5*i, 2)));
+            label nAtoms = atoi(thermoFormula.substr(5*i + 2, 3).c_str());
 
             if (elementName.size() && nAtoms)
             {
@@ -490,7 +490,7 @@ bool finishReaction = false;
     }
 
 <readThermoPhase>{thermoPhase} {
-        char phaseChar = YYText()[0];
+        const char phaseChar = YYText()[0];
 
         switch (phaseChar)
         {
@@ -511,10 +511,10 @@ bool finishReaction = false;
     }
 
 <readThermoTemps>{thermoLowTemp}{thermoHighTemp}{thermoCommonTemp} {
-        string temperaturesString(YYText());
-        currentLowT = stringToScalar(temperaturesString(0, 10));
-        currentHighT = stringToScalar(temperaturesString(10, 10));
-        currentCommonT = stringToScalar(temperaturesString(20, 8));
+        const string temperaturesString(YYText());
+        currentLowT = stringToScalar(temperaturesString.substr(0, 10));
+        currentHighT = stringToScalar(temperaturesString.substr(10, 10));
+        currentCommonT = stringToScalar(temperaturesString.substr(20, 8));
 
         if (currentCommonT < SMALL)
         {
@@ -525,9 +525,9 @@ bool finishReaction = false;
     }
 
 <readThermoFormula2>{thermoFormula2} {
-        string thermoFormula(YYText());
-        word elementName(foamName(thermoFormula(0, 2)));
-        label nAtoms = atoi(thermoFormula(2, 3).c_str());
+        const string thermoFormula(YYText());
+        word elementName(foamName(thermoFormula.substr(0, 2)));
+        const label nAtoms = atoi(thermoFormula.substr(2, 3).c_str());
 
         if
         (
@@ -568,13 +568,13 @@ bool finishReaction = false;
     }
 
 <readThermoCoeff1>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
-        string thermoCoeffString(YYText());
+        const string thermoCoeffString(YYText());
 
-        highCpCoeffs[0] = stringToScalar(thermoCoeffString(0, 15));
-        highCpCoeffs[1] = stringToScalar(thermoCoeffString(15, 15));
-        highCpCoeffs[2] = stringToScalar(thermoCoeffString(30, 15));
-        highCpCoeffs[3] = stringToScalar(thermoCoeffString(45, 15));
-        highCpCoeffs[4] = stringToScalar(thermoCoeffString(60, 15));
+        highCpCoeffs[0] = stringToScalar(thermoCoeffString.substr(0, 15));
+        highCpCoeffs[1] = stringToScalar(thermoCoeffString.substr(15, 15));
+        highCpCoeffs[2] = stringToScalar(thermoCoeffString.substr(30, 15));
+        highCpCoeffs[3] = stringToScalar(thermoCoeffString.substr(45, 15));
+        highCpCoeffs[4] = stringToScalar(thermoCoeffString.substr(60, 15));
 
         BEGIN(readThermoLineLabel2);
     }
@@ -586,12 +586,12 @@ bool finishReaction = false;
 <readThermoCoeff2>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
         string thermoCoeffString(YYText());
 
-        highCpCoeffs[5] = stringToScalar(thermoCoeffString(0, 15));
-        highCpCoeffs[6] = stringToScalar(thermoCoeffString(15, 15));
+        highCpCoeffs[5] = stringToScalar(thermoCoeffString.substr(0, 15));
+        highCpCoeffs[6] = stringToScalar(thermoCoeffString.substr(15, 15));
 
-        lowCpCoeffs[0] = stringToScalar(thermoCoeffString(30, 15));
-        lowCpCoeffs[1] = stringToScalar(thermoCoeffString(45, 15));
-        lowCpCoeffs[2] = stringToScalar(thermoCoeffString(60, 15));
+        lowCpCoeffs[0] = stringToScalar(thermoCoeffString.substr(30, 15));
+        lowCpCoeffs[1] = stringToScalar(thermoCoeffString.substr(45, 15));
+        lowCpCoeffs[2] = stringToScalar(thermoCoeffString.substr(60, 15));
 
         BEGIN(readThermoLineLabel3);
     }
@@ -603,10 +603,10 @@ bool finishReaction = false;
 <readThermoCoeff3>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
         string thermoCoeffString(YYText());
 
-        lowCpCoeffs[3] = stringToScalar(thermoCoeffString(0, 15));
-        lowCpCoeffs[4] = stringToScalar(thermoCoeffString(15, 15));
-        lowCpCoeffs[5] = stringToScalar(thermoCoeffString(30, 15));
-        lowCpCoeffs[6] = stringToScalar(thermoCoeffString(45, 15));
+        lowCpCoeffs[3] = stringToScalar(thermoCoeffString.substr(0, 15));
+        lowCpCoeffs[4] = stringToScalar(thermoCoeffString.substr(15, 15));
+        lowCpCoeffs[5] = stringToScalar(thermoCoeffString.substr(30, 15));
+        lowCpCoeffs[6] = stringToScalar(thermoCoeffString.substr(45, 15));
 
         BEGIN(readThermoLineLabel4);
     }
@@ -1327,11 +1327,10 @@ bool finishReaction = false;
 
 <readPDependentSpecie>{pDependentSpecie} {
 
-        word rhsPDependentSpecieName = pDependentSpecieName;
+        const word rhsPDependentSpecieName = pDependentSpecieName;
         pDependentSpecieName =
             foamName(foamSpecieString(YYText()));
-        pDependentSpecieName =
-            pDependentSpecieName(0, pDependentSpecieName.size() - 1);
+        pDependentSpecieName.resize(pDependentSpecieName.size()-1);
 
         if (rrType == thirdBodyArrhenius)
         {
diff --git a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C
index 8f0330cea99..5da2f878c4b 100644
--- a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C
+++ b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C
@@ -211,17 +211,12 @@ Foam::Reaction<ReactionThermo>::specieCoeffs::specieCoeffs
     {
         word specieName = t.wordToken();
 
-        size_t i = specieName.find('^');
+        const size_t i = specieName.find('^');
 
         if (i != word::npos)
         {
-            string exponentStr = specieName
-            (
-                i + 1,
-                specieName.size() - i - 1
-            );
-            exponent = atof(exponentStr.c_str());
-            specieName = specieName(0, i);
+            exponent = atof(specieName.substr(i + 1).c_str());
+            specieName.resize(i);
         }
 
         if (species.contains(specieName))
-- 
GitLab