From e70fc6166021eda62ddaf9f68168bfc2a2303783 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 2 Aug 2017 12:33:35 +0200 Subject: [PATCH 1/2] ENH: consolidate, cleanup some string methods - consolidate word::validated() into word::validate() and also allow as short form for string::validate(). Also less confusing than having similarly named methods that essentially do the same thing. - more consistent const access when iterating over strings - add valid(char) for keyType and wordRe --- applications/test/io/Test-io.C | 3 +- applications/test/string/Test-string.C | 2 +- .../mesh/conversion/ccm/foamToCcm/foamToCcm.C | 2 +- .../conversion/gambitToFoam/gambitToFoam.L | 2 +- .../mesh/conversion/gmshToFoam/gmshToFoam.C | 10 +-- .../ideasUnvToFoam/ideasUnvToFoam.C | 2 +- .../reconstructPar/reconstructPar.C | 5 +- src/OpenFOAM/db/IOobject/IOobject.C | 6 +- .../db/IOstreams/Pstreams/UOPstream.C | 2 +- src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C | 13 +--- .../functionObjectList/functionObjectList.C | 6 +- .../db/objectRegistry/objectRegistry.C | 2 +- src/OpenFOAM/primitives/chars/wchar/wchar.H | 6 +- src/OpenFOAM/primitives/chars/wchar/wcharIO.C | 7 +- .../primitives/strings/fileName/fileName.C | 13 +--- .../primitives/strings/fileName/fileName.H | 2 +- .../primitives/strings/fileName/fileNameI.H | 5 +- .../primitives/strings/keyType/keyType.H | 5 ++ .../primitives/strings/keyType/keyTypeI.H | 15 ++++ .../primitives/strings/lists/CStringListI.H | 8 +- .../strings/lists/CStringListTemplates.C | 58 +++++++-------- .../primitives/strings/string/string.C | 73 +++++++++---------- .../primitives/strings/string/string.H | 23 +++--- .../primitives/strings/string/stringI.H | 56 +++++++------- .../primitives/strings/stringOps/stringOps.C | 23 +++--- src/OpenFOAM/primitives/strings/word/word.C | 48 +++--------- src/OpenFOAM/primitives/strings/word/word.H | 9 ++- src/OpenFOAM/primitives/strings/word/wordI.H | 3 +- .../primitives/strings/wordRe/wordRe.H | 5 ++ .../primitives/strings/wordRe/wordReI.H | 6 ++ src/conversion/ccm/reader/ccmReader.C | 8 +- src/conversion/fire/FIREMeshReader.C | 4 +- src/fileFormats/stl/STLReaderASCII.L | 2 +- .../edgeMeshFormats/obj/OBJedgeFormat.C | 5 +- .../surfaceFormats/ac3d/AC3DsurfaceFormat.C | 6 +- .../surfaceFormats/nas/NASsurfaceFormat.C | 14 +--- src/surfMesh/surfaceFormats/obj/OBJstream.C | 16 +--- .../surfaceFormats/obj/OBJsurfaceFormat.C | 5 +- .../starcd/STARCDsurfaceFormatCore.C | 2 +- .../surfaceFormats/tri/TRIsurfaceFormatCore.C | 11 ++- .../triSurface/interfaces/NAS/readNAS.C | 17 +++-- .../triSurface/interfaces/OBJ/readOBJ.C | 7 +- .../chemkinReader/chemkinLexer.L | 61 ++++------------ 43 files changed, 258 insertions(+), 320 deletions(-) diff --git a/applications/test/io/Test-io.C b/applications/test/io/Test-io.C index aeef9468ec..40f503a4ee 100644 --- a/applications/test/io/Test-io.C +++ b/applications/test/io/Test-io.C @@ -40,7 +40,8 @@ using namespace Foam; int main(void) { string st("sfdsf sdfs23df sdf32f . sdfsdff23/2sf32"); - Info<< word(string::validate(st)) << "END" << endl; + Info<<"string: " << st << nl; + Info<<"word: \"" << string::validate(st) << "\"" << endl; string st1("1234567"); diff --git a/applications/test/string/Test-string.C b/applications/test/string/Test-string.C index d660a36240..7975620442 100644 --- a/applications/test/string/Test-string.C +++ b/applications/test/string/Test-string.C @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) for (const auto& s : { " text with \"spaces'", "08/15 value" }) { Info<<"validated \"" << s << "\" => " - << word::validated(s, true) << nl; + << word::validate(s, true) << nl; } Info<< nl; diff --git a/applications/utilities/mesh/conversion/ccm/foamToCcm/foamToCcm.C b/applications/utilities/mesh/conversion/ccm/foamToCcm/foamToCcm.C index 8042faa876..31ef8b3a8d 100644 --- a/applications/utilities/mesh/conversion/ccm/foamToCcm/foamToCcm.C +++ b/applications/utilities/mesh/conversion/ccm/foamToCcm/foamToCcm.C @@ -207,7 +207,7 @@ int main(int argc, char *argv[]) // #include "checkHasMovingMesh.H" // #include "checkHasLagrangian.H" - IOobjectList objects(mesh, timeDirs[timeDirs.size()-1].name()); + IOobjectList objects(mesh, timeDirs.last().name()); forAll(timeDirs, timeI) { diff --git a/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L b/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L index 6db26071d5..23432898a6 100644 --- a/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L +++ b/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L @@ -488,7 +488,7 @@ mtype {space}"MTYPE:"{space} {spaceNl}{word}{spaceNl} { - word streamName(Foam::string::validate(YYText())); + const word streamName(word::validate(YYText())); BEGIN(cellStreamFlags); } diff --git a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C index ea0bd7f6dc..cf87849079 100644 --- a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C +++ b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C @@ -370,7 +370,7 @@ void readPhysNames(IFstream& inFile, Map& physicalNames) lineStr >> regionI >> regionName; Info<< " " << regionI << '\t' - << string::validate(regionName) << endl; + << word::validate(regionName) << endl; } else if (nSpaces == 2) { @@ -380,21 +380,21 @@ void readPhysNames(IFstream& inFile, Map& physicalNames) if (physType == 1) { Info<< " " << "Line " << regionI << '\t' - << string::validate(regionName) << endl; + << word::validate(regionName) << endl; } else if (physType == 2) { Info<< " " << "Surface " << regionI << '\t' - << string::validate(regionName) << endl; + << word::validate(regionName) << endl; } else if (physType == 3) { Info<< " " << "Volume " << regionI << '\t' - << string::validate(regionName) << endl; + << word::validate(regionName) << endl; } } - physicalNames.insert(regionI, string::validate(regionName)); + physicalNames.insert(regionI, word::validate(regionName)); } inFile.getLine(line); diff --git a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C index 8583c9fac5..6ad6dfcd43 100644 --- a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C +++ b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C @@ -512,7 +512,7 @@ void readSets >> dofSet >> tempSet >> contactSet >> nFaces; is.getLine(line); - word groupName = string::validate(line); + const word groupName = word::validate(line); Info<< "For group " << group << " named " << groupName diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C index 6789c6f9e9..4be4abb392 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructPar.C @@ -598,10 +598,7 @@ int main(int argc, char *argv[]) // Pass2: reconstruct the cloud forAllConstIter(HashTable, cloudObjects, iter) { - const word cloudName = string::validate - ( - iter.key() - ); + const word cloudName = word::validate(iter.key()); // Objects (on arbitrary processor) const IOobjectList& sprayObjs = iter(); diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 5ec0b29cf0..1dfeac4253 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -149,7 +149,7 @@ bool Foam::IOobject::fileNameComponents // No '/' found (or empty entirely) // => no instance or local - name = word::validated(path, false); + name = word::validate(path); } else if (first == 0) { @@ -160,7 +160,7 @@ bool Foam::IOobject::fileNameComponents const std::string ending = path.substr(last+1); nameLen = ending.size(); // The raw length of name - name = word::validated(ending, false); + name = word::validate(ending); } else { @@ -176,7 +176,7 @@ bool Foam::IOobject::fileNameComponents const std::string ending = path.substr(last+1); nameLen = ending.size(); // The raw length of name - name = word::validated(ending, false); + name = word::validate(ending); } // Check for valid (and stripped) name, regardless of the debug level diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C index 8e6a5eb17a..cf53be0f84 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C @@ -185,7 +185,7 @@ Foam::Ostream& Foam::UOPstream::write(const char c) Foam::Ostream& Foam::UOPstream::write(const char* str) { - word nonWhiteChars(string::validate(str)); + const word nonWhiteChars(string::validate(str)); if (nonWhiteChars.size() == 1) { diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C index 0feb835340..69897b999d 100644 --- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C +++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C @@ -81,9 +81,9 @@ Foam::Ostream& Foam::OSstream::write(const string& str) os_ << token::BEGIN_STRING; int backslash = 0; - for (string::const_iterator iter = str.begin(); iter != str.end(); ++iter) + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { - char c = *iter; + const char c = *iter; if (c == '\\') { @@ -132,14 +132,9 @@ Foam::Ostream& Foam::OSstream::writeQuoted os_ << token::BEGIN_STRING; int backslash = 0; - for - ( - string::const_iterator iter = str.begin(); - iter != str.end(); - ++iter - ) + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { - char c = *iter; + const char c = *iter; if (c == '\\') { diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 9f6070472a..fea664c741 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -235,7 +235,7 @@ bool Foam::functionObjectList::readFunctionObject { args.append ( - string::validate + word::validate ( funcNameArgs.substr(start, i - start) ) @@ -255,7 +255,7 @@ bool Foam::functionObjectList::readFunctionObject } else if (c == '=') { - argName = string::validate + argName = word::validate ( funcNameArgs.substr(start, i - start) ); @@ -330,7 +330,7 @@ bool Foam::functionObjectList::readFunctionObject // Merge this functionObject dictionary into functionsDict dictionary funcArgsDict; - funcArgsDict.add(string::validate(funcNameArgs), funcDict); + funcArgsDict.add(word::validate(funcNameArgs), funcDict); functionsDict.merge(funcArgsDict); return true; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.C b/src/OpenFOAM/db/objectRegistry/objectRegistry.C index 2f048ea71c..4a6c60c612 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.C @@ -55,7 +55,7 @@ Foam::objectRegistry::objectRegistry ( IOobject ( - string::validate(t.caseName()), + word::validate(t.caseName()), t.path(), t, IOobject::NO_READ, diff --git a/src/OpenFOAM/primitives/chars/wchar/wchar.H b/src/OpenFOAM/primitives/chars/wchar/wchar.H index e6cc3e182e..480a580119 100644 --- a/src/OpenFOAM/primitives/chars/wchar/wchar.H +++ b/src/OpenFOAM/primitives/chars/wchar/wchar.H @@ -53,13 +53,13 @@ class Ostream; // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // //- Output wide character (Unicode) as UTF-8 -Ostream& operator<<(Ostream&, const wchar_t); +Ostream& operator<<(Ostream& os, const wchar_t wc); //- Output wide character (Unicode) string as UTF-8 -Ostream& operator<<(Ostream&, const wchar_t*); +Ostream& operator<<(Ostream& os, const wchar_t* wstr); //- Output wide character (Unicode) string as UTF-8 -Ostream& operator<<(Ostream&, const std::wstring&); +Ostream& operator<<(Ostream& os, const std::wstring& wstr); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/chars/wchar/wcharIO.C b/src/OpenFOAM/primitives/chars/wchar/wcharIO.C index fc710a52dd..ed88e5703f 100644 --- a/src/OpenFOAM/primitives/chars/wchar/wcharIO.C +++ b/src/OpenFOAM/primitives/chars/wchar/wcharIO.C @@ -116,12 +116,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const wchar_t* wstr) Foam::Ostream& Foam::operator<<(Ostream& os, const std::wstring& wstr) { - for - ( - std::wstring::const_iterator iter = wstr.begin(); - iter != wstr.end(); - ++iter - ) + for (auto iter = wstr.cbegin(); iter != wstr.cend(); ++iter) { os << *iter; } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 87ddec68b7..fe1b70da74 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -120,14 +120,9 @@ bool Foam::fileName::clean() string::size_type nChar = top+1; string::size_type maxLen = this->size(); - for - ( - string::size_type src = nChar; - src < maxLen; - /*nil*/ - ) + for (string::size_type src = nChar; src < maxLen; /*nil*/) { - char c = operator[](src++); + const char c = operator[](src++); if (prev == '/') { @@ -148,12 +143,12 @@ bool Foam::fileName::clean() // Peek at the next character - char c1 = operator[](src); + const char c1 = operator[](src); // Found '/./' - skip it if (c1 == '/') { - src++; + ++src; continue; } diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 19cd295120..d134996178 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -108,7 +108,7 @@ public: inline fileName(const fileName& fn); //- Construct as copy of word - inline fileName(const word& s); + inline fileName(const word& w); //- Construct as copy of string inline fileName(const string& s, const bool doStripInvalid=true); diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H index b119926305..e65d599e09 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H @@ -23,12 +23,13 @@ License \*---------------------------------------------------------------------------*/ +#include // for std::cerr + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // inline void Foam::fileName::stripInvalid() { - // skip stripping unless debug is active to avoid - // costly operations + // Skip stripping unless debug is active (to avoid costly operations) if (debug && string::stripInvalid(*this)) { std::cerr diff --git a/src/OpenFOAM/primitives/strings/keyType/keyType.H b/src/OpenFOAM/primitives/strings/keyType/keyType.H index 82713fd9ff..0f9d613943 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyType.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyType.H @@ -111,6 +111,11 @@ public: // Member functions + //- Is this character valid for a keyType? + // This is largely identical with what word accepts, but also + // permit brace-brackets, which are valid for some regexs. + inline static bool valid(char c); + //- Treat as a pattern rather than a literal string? inline bool isPattern() const; diff --git a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H index 964f48cbb0..575bb834b1 100644 --- a/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H +++ b/src/OpenFOAM/primitives/strings/keyType/keyTypeI.H @@ -23,6 +23,21 @@ License \*---------------------------------------------------------------------------*/ +// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // + +inline bool Foam::keyType::valid(char c) +{ + return + ( + !isspace(c) + && c != '"' // string quote + && c != '\'' // string quote + && c != '/' // path separator + && c != ';' // end statement + ); +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::keyType::keyType() diff --git a/src/OpenFOAM/primitives/strings/lists/CStringListI.H b/src/OpenFOAM/primitives/strings/lists/CStringListI.H index d91a9de646..766ff2c28b 100644 --- a/src/OpenFOAM/primitives/strings/lists/CStringListI.H +++ b/src/OpenFOAM/primitives/strings/lists/CStringListI.H @@ -46,8 +46,8 @@ inline Foam::CStringList::CStringList() : argc_(0), len_(0), - argv_(0), - data_(0) + argv_(nullptr), + data_(nullptr) {} @@ -69,12 +69,12 @@ inline void Foam::CStringList::clear() if (data_) { delete[] data_; - data_ = 0; + data_ = nullptr; } if (argv_) { delete[] argv_; - argv_ = 0; + argv_ = nullptr; } } diff --git a/src/OpenFOAM/primitives/strings/lists/CStringListTemplates.C b/src/OpenFOAM/primitives/strings/lists/CStringListTemplates.C index 8a5d383dbf..9019855429 100644 --- a/src/OpenFOAM/primitives/strings/lists/CStringListTemplates.C +++ b/src/OpenFOAM/primitives/strings/lists/CStringListTemplates.C @@ -33,8 +33,8 @@ Foam::CStringList::CStringList : argc_(0), len_(0), - argv_(0), - data_(0) + argv_(nullptr), + data_(nullptr) { reset(input); } @@ -50,42 +50,40 @@ void Foam::CStringList::reset { clear(); - argc_ = input.size(); - forAll(input, argI) + if (input.empty()) { - len_ += input[argI].size(); - ++len_; // nul terminator for C-strings + // Special handling of an empty list + argv_ = new char*[1]; + argv_[0] = nullptr; // Final nullptr terminator + return; } - argv_ = new char*[argc_+1]; - argv_[argc_] = nullptr; // extra terminator - - if (argc_ > 0) + // Count overall required string length, including each trailing nul char + for (const auto& str : input) { - // allocation includes final nul terminator, - // but overall count does not - data_ = new char[len_--]; + len_ += str.size() + 1; + } - char* ptr = data_; - forAll(input, argI) + argv_ = new char*[input.size()+1]; + data_ = new char[len_]; + --len_; // Do not include final nul terminator in overall count + + argv_[argc_] = nullptr; // extra terminator + + // Copy contents + char* ptr = data_; + for (const auto& str : input) + { + argv_[argc_++] = ptr; // The start of this string + + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { - argv_[argI] = ptr; - - const std::string& str = - static_cast(input[argI]); - - for - ( - std::string::const_iterator iter = str.begin(); - iter != str.end(); - ++iter - ) - { - *(ptr++) = *iter; - } - *(ptr++) = '\0'; + *(ptr++) = *iter; } + *(ptr++) = '\0'; } + + argv_[argc_] = nullptr; // Final nullptr terminator } diff --git a/src/OpenFOAM/primitives/strings/string/string.C b/src/OpenFOAM/primitives/strings/string/string.C index dff5626411..b16b30f66d 100644 --- a/src/OpenFOAM/primitives/strings/string/string.C +++ b/src/OpenFOAM/primitives/strings/string/string.C @@ -101,17 +101,17 @@ bool Foam::string::hasExt(const wordRe& ending) const Foam::string::size_type Foam::string::count(const char c) const { - size_type cCount = 0; + size_type nChar = 0; - for (const_iterator iter = cbegin(); iter != cend(); ++iter) + for (auto iter = cbegin(); iter != cend(); ++iter) { if (*iter == c) { - ++cCount; + ++nChar; } } - return cCount; + return nChar; } @@ -119,14 +119,14 @@ Foam::string& Foam::string::replace ( const string& oldStr, const string& newStr, - size_type start + const size_type start ) { - size_type newStart = start; + size_type pos = start; - if ((newStart = find(oldStr, newStart)) != npos) + if ((pos = find(oldStr, pos)) != npos) { - std::string::replace(newStart, oldStr.size(), newStr); + std::string::replace(pos, oldStr.size(), newStr); } return *this; @@ -137,17 +137,22 @@ Foam::string& Foam::string::replaceAll ( const string& oldStr, const string& newStr, - size_type start + const size_type start ) { - if (oldStr.size()) - { - size_type newStart = start; + const size_type lenOld = oldStr.size(); + const size_type lenNew = newStr.size(); - while ((newStart = find(oldStr, newStart)) != npos) + if (lenOld) + { + for + ( + size_type pos = start; + (pos = find(oldStr, pos)) != npos; + pos += lenNew + ) { - std::string::replace(newStart, oldStr.size(), newStr); - newStart += newStr.size(); + std::string::replace(pos, lenOld, newStr); } } @@ -168,19 +173,14 @@ bool Foam::string::removeRepeated(const char character) if (character && find(character) != npos) { - string::size_type nChar=0; - iterator iter2 = begin(); + string::size_type nChar = 0; + iterator outIter = begin(); char prev = 0; - for - ( - string::const_iterator iter1 = iter2; - iter1 != end(); - iter1++ - ) + for (auto iter = cbegin(); iter != cend(); ++iter) { - char c = *iter1; + const char c = *iter; if (prev == c && c == character) { @@ -188,11 +188,12 @@ bool Foam::string::removeRepeated(const char character) } else { - *iter2 = prev = c; - ++iter2; + *outIter = prev = c; + ++outIter; ++nChar; } } + resize(nChar); } @@ -210,16 +211,14 @@ Foam::string Foam::string::removeRepeated(const char character) const bool Foam::string::removeTrailing(const char character) { - bool changed = false; - - string::size_type nChar = size(); + const string::size_type nChar = size(); if (character && nChar > 1 && operator[](nChar-1) == character) { resize(nChar-1); - changed = true; + return true; } - return changed; + return false; } @@ -245,10 +244,8 @@ bool Foam::string::removeStart(const std::string& text) this->erase(0, txtLen); return true; } - else - { - return false; - } + + return false; } @@ -266,10 +263,8 @@ bool Foam::string::removeEnd(const std::string& text) this->resize(strLen - txtLen); return true; } - else - { - return false; - } + + return false; } diff --git a/src/OpenFOAM/primitives/strings/string/string.H b/src/OpenFOAM/primitives/strings/string/string.H index e624a68456..b739965c39 100644 --- a/src/OpenFOAM/primitives/strings/string/string.H +++ b/src/OpenFOAM/primitives/strings/string/string.H @@ -190,22 +190,22 @@ public: //- Avoid masking the normal std::string replace using std::string::replace; - //- Replace first occurence of sub-string oldStr with newStr - // starting at start + //- Replace first occurence of sub-string oldStr with newStr, + // beginning at start string& replace ( const string& oldStr, const string& newStr, - size_type start = 0 + const size_type start = 0 ); - //- Replace all occurences of sub-string oldStr with newStr - // starting at start + //- Replace all occurences of sub-string oldStr with newStr, + // beginning at start. This is a no-op if oldStr is empty. string& replaceAll ( const string& oldStr, const string& newStr, - size_type start = 0 + const size_type start = 0 ); //- Expand initial tildes and all occurences of environment variables @@ -224,20 +224,23 @@ public: // Foam::findEtcFile string& expand(const bool allowEmpty = false); - //- Remove repeated characters returning true if string changed + //- Remove repeated characters + // \return True if string changed bool removeRepeated(const char character); //- Return string with repeated characters removed string removeRepeated(const char character) const; - //- Remove trailing character returning true if string changed + //- Remove trailing character, unless string is a single character + // \return True if string changed bool removeTrailing(const char character); - //- Return string with trailing character removed + //- Return string with trailing character removed, + // unless string is a single character string removeTrailing(const char character) const; //- Remove the given text from the start of the string. - // Always true if the removal occurred or the given text is empty. + // \return True if the removal occurred or the given text is empty. bool removeStart(const std::string& text); //- Remove the given text from the end of the string. diff --git a/src/OpenFOAM/primitives/strings/string/stringI.H b/src/OpenFOAM/primitives/strings/string/stringI.H index bae33b3342..96520dd758 100644 --- a/src/OpenFOAM/primitives/strings/string/stringI.H +++ b/src/OpenFOAM/primitives/strings/string/stringI.H @@ -23,7 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -76,21 +75,18 @@ inline Foam::string::string(const std::string& str) {} -// Copy character array inline Foam::string::string(const char* str) : std::string(str) {} -// Construct from a given number of characters in a character array inline Foam::string::string(const char* str, const size_type len) : std::string(str, len) {} -// Construct from a single character inline Foam::string::string(const char c) : std::string(1, c) @@ -102,13 +98,14 @@ inline Foam::string::string(const char c) template inline bool Foam::string::valid(const std::string& str) { - for (const_iterator iter = str.begin(); iter != str.end(); ++iter) + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { if (!String::valid(*iter)) { return false; } } + return true; } @@ -118,27 +115,22 @@ inline bool Foam::string::stripInvalid(std::string& str) { if (!valid(str)) { - size_type nValid = 0; - iterator iter2 = str.begin(); + size_type nChar = 0; + iterator outIter = str.begin(); - for - ( - const_iterator iter1 = iter2; - iter1 != const_cast(str).end(); - iter1++ - ) + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { - const char c = *iter1; + const char c = *iter; if (String::valid(c)) { - *iter2 = c; - ++iter2; - ++nValid; + *outIter = c; + ++outIter; + ++nChar; } } - str.resize(nValid); + str.resize(nChar); return true; } @@ -151,7 +143,7 @@ template inline bool Foam::string::meta(const std::string& str, const char quote) { int escaped = 0; - for (const_iterator iter = str.begin(); iter != str.end(); ++iter) + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { const char c = *iter; if (quote && c == quote) @@ -181,10 +173,10 @@ Foam::string::quotemeta(const std::string& str, const char quote) } string sQuoted; - sQuoted.reserve(2*str.length()); + sQuoted.reserve(2*str.size()); int escaped = 0; - for (const_iterator iter = str.begin(); iter != str.end(); ++iter) + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { const char c = *iter; if (c == quote) @@ -203,7 +195,7 @@ Foam::string::quotemeta(const std::string& str, const char quote) sQuoted += c; } - sQuoted.resize(sQuoted.length()); + sQuoted.resize(sQuoted.size()); return sQuoted; } @@ -212,9 +204,22 @@ Foam::string::quotemeta(const std::string& str, const char quote) template inline String Foam::string::validate(const std::string& str) { - string ss = str; - stripInvalid(ss); - return ss; + String out; + out.resize(str.size()); + + size_type count = 0; + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) + { + const char c = *iter; + if (String::valid(c)) + { + out[count++] = c; + } + } + + out.resize(count); + + return out; } @@ -257,4 +262,5 @@ inline unsigned Foam::string::hash::operator() return Hasher(str.data(), str.size(), seed); } + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index ea6d81ef04..b3c35d9541 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -123,12 +123,12 @@ Foam::string& Foam::stringOps::inplaceExpand } else { - string::iterator iter = s.begin() + begVar + 1; + string::const_iterator iter = s.cbegin() + begVar + 1; // more generous in accepting keywords than for env variables while ( - iter != s.end() + iter != s.cend() && ( std::isalnum(*iter) @@ -180,8 +180,7 @@ Foam::string& Foam::stringOps::inplaceExpand } - HashTable::const_iterator fnd = - mapping.find(varName); + auto fnd = mapping.cfind(varName); if (fnd.found()) { @@ -290,7 +289,9 @@ Foam::string Foam::stringOps::getVariable string::size_type altPos = 0; // check for parameter:-word or parameter:+word - int altType = findParameterAlternative(name, altPos, name.size()-1); + const int altType = + findParameterAlternative(name, altPos, name.size()-1); + if (altType) { value = getEnv @@ -414,13 +415,13 @@ Foam::string& Foam::stringOps::inplaceExpand } else { - string::iterator iter = s.begin() + begVar + 1; + string::const_iterator iter = s.cbegin() + begVar + 1; string::size_type endVar = begVar; // more generous in accepting keywords than for env variables while ( - iter != s.end() + iter != s.cend() && ( std::isalnum(*iter) @@ -552,12 +553,12 @@ Foam::string& Foam::stringOps::inplaceExpand } else { - string::iterator iter = s.begin() + begVar + 1; + string::const_iterator iter = s.cbegin() + begVar + 1; // more generous in accepting keywords than for env variables while ( - iter != s.end() + iter != s.cend() && ( std::isalnum(*iter) @@ -700,11 +701,11 @@ Foam::string& Foam::stringOps::inplaceExpand } else { - string::iterator iter = s.begin() + begVar + 1; + string::const_iterator iter = s.cbegin() + begVar + 1; while ( - iter != s.end() + iter != s.cend() && (std::isalnum(*iter) || *iter == '_') ) { diff --git a/src/OpenFOAM/primitives/strings/word/word.C b/src/OpenFOAM/primitives/strings/word/word.C index 3d829ae61e..932f10af4c 100644 --- a/src/OpenFOAM/primitives/strings/word/word.C +++ b/src/OpenFOAM/primitives/strings/word/word.C @@ -35,52 +35,28 @@ const Foam::word Foam::word::null; // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -Foam::word Foam::word::validated(const std::string& s, const bool prefix) +Foam::word Foam::word::validate(const std::string& s, const bool prefix) { - std::string::size_type count = 0; - bool extra = false; + word out; + out.resize(s.size() + (prefix ? 1 : 0)); - // Count number of valid characters and detect if the first character - // happens to be a digit, which we'd like to avoid having since this - // will cause parse issues when read back later. - for (std::string::const_iterator it = s.cbegin(); it != s.cend(); ++it) + std::string::size_type count = 0; + + // As per validate, but optionally detect if the first character + // is a digit, which we'd like to avoid having since this will + // cause parse issues when read back later. + for (auto iter = s.cbegin(); iter != s.cend(); ++iter) { - const char c = *it; + const char c = *iter; if (word::valid(c)) { - if (prefix && !count && isdigit(c)) + if (!count && prefix && isdigit(c)) { // First valid character was a digit - prefix with '_' - extra = true; - ++count; + out[count++] = '_'; } - ++count; - } - } - - if (count == s.size() && !extra) - { - return word(s, false); // Already checked, can just return as word - } - - word out; - out.resize(count); - count = 0; - - // Copy valid content. - if (extra) - { - out[count++] = '_'; - } - - for (std::string::const_iterator it = s.cbegin(); it != s.cend(); ++it) - { - const char c = *it; - - if (word::valid(c)) - { out[count++] = c; } } diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index 126d5c08c7..b92d720934 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.H @@ -64,6 +64,7 @@ class word // Private Member Functions //- Strip invalid characters from this word + // Trips an abort on invalid characters for debug 2 or greater inline void stripInvalid(); @@ -112,10 +113,10 @@ public: //- Is this character valid for a word? inline static bool valid(char c); - //- Construct a validated word, in which all invalid characters have - // been stripped out. Optionally prefix any leading digit - // with '_' to have words that work nicely as dictionary keywords. - static word validated(const std::string& s, const bool prefix=false); + //- Construct validated word (no invalid characters). + // Optionally prefix any leading digit with '_' to have words + // that work nicely as dictionary keywords. + static word validate(const std::string& s, const bool prefix=false); // File-like functions diff --git a/src/OpenFOAM/primitives/strings/word/wordI.H b/src/OpenFOAM/primitives/strings/word/wordI.H index eb17097014..2fa48801a7 100644 --- a/src/OpenFOAM/primitives/strings/word/wordI.H +++ b/src/OpenFOAM/primitives/strings/word/wordI.H @@ -24,12 +24,13 @@ License \*---------------------------------------------------------------------------*/ #include +#include // for std::cerr // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // inline void Foam::word::stripInvalid() { - // skip stripping unless debug is active (to avoid costly operations) + // Skip stripping unless debug is active (to avoid costly operations) if (debug && string::stripInvalid(*this)) { std::cerr diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H index 4df4325efd..8195abb90e 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordRe.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordRe.H @@ -107,6 +107,11 @@ public: //- Is this a meta character? inline static bool meta(const char c); + //- Is this character valid for a wordRe? + // This is largely identical with what word accepts, but also + // permit brace-brackets, which are valid for some regexs. + inline static bool valid(char c); + //- Test string for regular expression meta characters inline static bool isPattern(const std::string& str); diff --git a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H index b01c590554..658df00695 100644 --- a/src/OpenFOAM/primitives/strings/wordRe/wordReI.H +++ b/src/OpenFOAM/primitives/strings/wordRe/wordReI.H @@ -31,6 +31,12 @@ inline bool Foam::wordRe::meta(const char c) } +inline bool Foam::wordRe::valid(char c) +{ + return keyType::valid(c); +} + + inline bool Foam::wordRe::isPattern(const std::string& str) { return string::meta(str); diff --git a/src/conversion/ccm/reader/ccmReader.C b/src/conversion/ccm/reader/ccmReader.C index 302e89981d..78495c4ba5 100644 --- a/src/conversion/ccm/reader/ccmReader.C +++ b/src/conversion/ccm/reader/ccmReader.C @@ -365,7 +365,7 @@ void Foam::ccm::reader::readProblemDescription_boundaryRegion } else { - dict.add(opt, word::validated(str, true)); + dict.add(opt, word::validate(str, true)); } } @@ -407,7 +407,7 @@ void Foam::ccm::reader::readProblemDescription_boundaryRegion if (!str.empty()) { - dict.add(opt, word::validated(str, true)); + dict.add(opt, word::validate(str, true)); } } @@ -472,7 +472,7 @@ void Foam::ccm::reader::readProblemDescription_cellTable str = "zone_" + ::Foam::name(Id); } - dict.add(opt, word::validated(str, true)); + dict.add(opt, word::validate(str, true)); } @@ -484,7 +484,7 @@ void Foam::ccm::reader::readProblemDescription_cellTable if (!str.empty()) { - dict.add(opt, word::validated(str, true)); + dict.add(opt, word::validate(str, true)); } } diff --git a/src/conversion/fire/FIREMeshReader.C b/src/conversion/fire/FIREMeshReader.C index df5ee05ef7..239e6a5a87 100644 --- a/src/conversion/fire/FIREMeshReader.C +++ b/src/conversion/fire/FIREMeshReader.C @@ -155,7 +155,7 @@ void Foam::fileFormats::FIREMeshReader::readSelections(ISstream& is) // index starting at 1 const label selId = ++nCellSelections; - cellTable_.setName(selId, word::validated(name, true)); + cellTable_.setName(selId, word::validate(name, true)); cellTable_.setMaterial(selId, "fluid"); for (label i = 0; i < count; ++i) @@ -170,7 +170,7 @@ void Foam::fileFormats::FIREMeshReader::readSelections(ISstream& is) // index starting at 0 const label selId = nFaceSelections++; - faceNames.append(word::validated(name, true)); + faceNames.append(word::validate(name, true)); for (label i = 0; i < count; ++i) { diff --git a/src/fileFormats/stl/STLReaderASCII.L b/src/fileFormats/stl/STLReaderASCII.L index 46c9ab1a85..5a781d4a56 100644 --- a/src/fileFormats/stl/STLReaderASCII.L +++ b/src/fileFormats/stl/STLReaderASCII.L @@ -243,7 +243,7 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})* } {string} { - const word solidName(Foam::string::validate(YYText())); + const word solidName(word::validate(YYText())); auto iter = lookup_.cfind(solidName); if (iter.found()) diff --git a/src/meshTools/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C b/src/meshTools/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C index e0af5e0e76..e93dfead98 100644 --- a/src/meshTools/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C +++ b/src/meshTools/edgeMesh/edgeMeshFormats/obj/OBJedgeFormat.C @@ -116,10 +116,9 @@ bool Foam::fileFormats::OBJedgeFormat::read(const fileName& filename) { string line = this->getLineNoComment(is); - // handle continuations - if (line.back() == '\\') + // Handle continuations + if (line.removeEnd("\\")) { - line.resize(line.size()-1); line += this->getLineNoComment(is); } diff --git a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C index 8f9681a7dd..2340b819c0 100644 --- a/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/ac3d/AC3DsurfaceFormat.C @@ -121,10 +121,8 @@ bool Foam::fileFormats::AC3DsurfaceFormat::read if (cmd == "name") { // name %s - string str = parse(args); - string::stripInvalid(str); - - names[zoneI] = str; + const string str = parse(args); + names[zoneI] = word::validate(str); } else if (cmd == "rot") { diff --git a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C index 3bcc035188..ab37ac9a90 100644 --- a/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/nas/NASsurfaceFormat.C @@ -111,14 +111,8 @@ bool Foam::fileFormats::NASsurfaceFormat::read string rawName; is.getLine(rawName); - if (rawName.back() == '\r') - { - rawName.resize(rawName.size()-1); - } - rawName = rawName.substr(1); - - string::stripInvalid(rawName); - ansaName = rawName; + rawName.removeEnd("\r"); + ansaName = word::validate(rawName.substr(1)); // Info<< "ANSA tag for NastranID:" << ansaId // << " of type " << ansaType @@ -140,11 +134,9 @@ bool Foam::fileFormats::NASsurfaceFormat::read string rawName; lineStream >> rawName; - string::stripInvalid(rawName); - word groupName(rawName); + const word groupName = word::validate(rawName); nameLookup.insert(groupId, groupName); - // Info<< "group " << groupId << " => " << groupName << endl; } diff --git a/src/surfMesh/surfaceFormats/obj/OBJstream.C b/src/surfMesh/surfaceFormats/obj/OBJstream.C index 7c3b34c1ae..2fcf7f4305 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJstream.C +++ b/src/surfMesh/surfaceFormats/obj/OBJstream.C @@ -119,14 +119,9 @@ Foam::Ostream& Foam::OBJstream::writeQuoted OFstream::write(token::BEGIN_STRING); int backslash = 0; - for - ( - std::string::const_iterator iter = str.begin(); - iter != str.end(); - ++iter - ) + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { - char c = *iter; + const char c = *iter; if (c == '\\') { @@ -161,12 +156,7 @@ Foam::Ostream& Foam::OBJstream::writeQuoted else { // output unquoted string, only advance line number on newline - for - ( - std::string::const_iterator iter = str.begin(); - iter != str.end(); - ++iter - ) + for (auto iter = str.cbegin(); iter != str.cend(); ++iter) { writeAndCheck(*iter); } diff --git a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C index 692f2ee3bc..e7a16d3675 100644 --- a/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C +++ b/src/surfMesh/surfaceFormats/obj/OBJsurfaceFormat.C @@ -81,10 +81,9 @@ bool Foam::fileFormats::OBJsurfaceFormat::read { string line = this->getLineNoComment(is); - // handle continuations - if (line.back() == '\\') + // Handle continuations + if (line.removeEnd("\\")) { - line.resize(line.size()-1); line += this->getLineNoComment(is); } diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C index 7443771812..b6b87fc6a2 100644 --- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C @@ -64,7 +64,7 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable if (ctnameRE.match(line, groups)) { const label tableId = atoi(groups[0].c_str()); - const word tableName = word::validated(groups[1], true); + const word tableName = word::validate(groups[1], true); if (!tableName.empty()) { diff --git a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C index 385ad872ab..2c66572be9 100644 --- a/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C +++ b/src/surfMesh/surfaceFormats/tri/TRIsurfaceFormatCore.C @@ -86,12 +86,11 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read { string line = this->getLineNoComment(is); - // handle continuations ? - // if (line.back() == '\\') - // { - // line.resize(line.size()-1); - // line += this->getLineNoComment(is); - // } + // Handle continuations? + // if (line.removeEnd("\\")) + // { + // line += this->getLineNoComment(is); + // } IStringStream lineStream(line); diff --git a/src/surfMesh/triSurface/interfaces/NAS/readNAS.C b/src/surfMesh/triSurface/interfaces/NAS/readNAS.C index 0653ea8f01..f40226dc05 100644 --- a/src/surfMesh/triSurface/interfaces/NAS/readNAS.C +++ b/src/surfMesh/triSurface/interfaces/NAS/readNAS.C @@ -152,10 +152,9 @@ bool triSurface::readNAS(const fileName& fName) string nameString; is.getLine(ansaName); - if (ansaName.back() == '\r') - { - ansaName.resize(ansaName.size()-1); - } + + ansaName.removeEnd("\r"); // Possible CR-NL + ansaName = ansaName.substr(1); // Info<< "ANSA tag for NastranID:" << ansaId // << " of type " << ansaType @@ -178,8 +177,9 @@ bool triSurface::readNAS(const fileName& fName) string rawName; lineStream >> rawName; - groupToName.insert(groupId, string::validate(rawName)); - Info<< "group " << groupId << " => " << rawName << endl; + const word groupName = word::validate(rawName); + groupToName.insert(groupId, groupName); + Info<< "group " << groupId << " => " << groupName << endl; } @@ -275,8 +275,9 @@ bool triSurface::readNAS(const fileName& fName) readLabel(IStringStream(readNASToken(line, 8, linei))()); if (groupId == ansaId && ansaType == "PSHELL") { - groupToName.insert(groupId, string::validate(ansaName)); - Info<< "group " << groupId << " => " << ansaName << endl; + const word groupName = word::validate(ansaName); + groupToName.insert(groupId, groupName); + Info<< "group " << groupId << " => " << groupName << endl; } } else if (cmd == "GRID") diff --git a/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C b/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C index 42393a1af0..6218785148 100644 --- a/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C +++ b/src/surfMesh/triSurface/interfaces/OBJ/readOBJ.C @@ -51,13 +51,10 @@ bool Foam::triSurface::readOBJ(const fileName& OBJfileName) { string line = getLineNoComment(OBJfile); - const label sz = line.size(); - - if (sz) + if (line.size()) { - if (line.back() == '\\') + if (line.removeEnd("\\")) { - line.resize(sz-1); line += getLineNoComment(OBJfile); } diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L index c016113a19..80379ff868 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L @@ -65,29 +65,6 @@ int yyFlexLexer::yywrap() //! \endcond -Foam::string foamSpecieString(const char* YYText) -{ - Foam::string specieString(YYText); - return specieString; -} - - -Foam::word foamName(const char* YYText) -{ - Foam::string fn(YYText); - Foam::string::stripInvalid(fn); - return fn; -} - - -Foam::word foamName(const Foam::string& s) -{ - Foam::string fn(s); - Foam::string::stripInvalid(fn); - return fn; -} - - /* ------------------------------------------------------------------------- *\ ------ cppLexer::yylex() \* ------------------------------------------------------------------------- */ @@ -344,7 +321,7 @@ bool finishReaction = false; } {elementName} { - currentElementName = foamName(YYText()); + currentElementName = word::validate(YYText()); correctElementName(currentElementName); if (!elementIndices_.found(currentElementName)) @@ -382,7 +359,7 @@ bool finishReaction = false; } {specieName} { - const word specieName(foamName(foamSpecieString(YYText()))); + const word specieName = word::validate(YYText()); if (specieName == "THERMO") { @@ -437,7 +414,7 @@ bool finishReaction = false; } {thermoSpecieName} { - string specieString(foamSpecieString(YYText())); + string specieString(YYText()); if (newFormat_) { specieString.replaceAll(" ", "_"); @@ -474,7 +451,7 @@ bool finishReaction = false; for (int i=0; i<4; i++) { - word elementName(foamName(thermoFormula.substr(5*i, 2))); + word elementName = word::validate(thermoFormula.substr(5*i, 2)); label nAtoms = atoi(thermoFormula.substr(5*i + 2, 3).c_str()); if (elementName.size() && nAtoms) @@ -494,17 +471,9 @@ bool finishReaction = false; switch (phaseChar) { - case 'S': - speciePhase_.insert(currentSpecieName, solid); - break; - - case 'L': - speciePhase_.insert(currentSpecieName, liquid); - break; - - case 'G': - speciePhase_.insert(currentSpecieName, gas); - break; + case 'S': speciePhase_.insert(currentSpecieName, solid); break; + case 'L': speciePhase_.insert(currentSpecieName, liquid); break; + case 'G': speciePhase_.insert(currentSpecieName, gas); break; } BEGIN(readThermoTemps); @@ -526,7 +495,7 @@ bool finishReaction = false; {thermoFormula2} { const string thermoFormula(YYText()); - word elementName(foamName(thermoFormula.substr(0, 2))); + word elementName = word::validate(thermoFormula.substr(0, 2)); const label nAtoms = atoi(thermoFormula.substr(2, 3).c_str()); if @@ -695,7 +664,7 @@ bool finishReaction = false; {reactionKeyword} { - word keyword(foamName(YYText())); + const word keyword = word::validate(YYText()); HashTable::iterator reactionKeywordIter ( @@ -807,7 +776,7 @@ bool finishReaction = false; } else { - currentSpecieName = foamName(foamSpecieString(YYText())); + currentSpecieName = word::validate(YYText()); HashTable