mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'style-string-access' into 'develop'
Consistent use of string methods See merge request !128
This commit is contained in:
@ -83,7 +83,8 @@ int main(int argc, char *argv[])
|
|||||||
Info<<"camel-case => " << (word("camel") & "case") << nl;
|
Info<<"camel-case => " << (word("camel") & "case") << nl;
|
||||||
for (const auto& s : { " text with \"spaces'", "08/15 value" })
|
for (const auto& s : { " text with \"spaces'", "08/15 value" })
|
||||||
{
|
{
|
||||||
Info<<"validated \"" << s << "\" => " << word::validated(s) << nl;
|
Info<<"validated \"" << s << "\" => "
|
||||||
|
<< word::validated(s, true) << nl;
|
||||||
}
|
}
|
||||||
Info<< nl;
|
Info<< nl;
|
||||||
|
|
||||||
|
|||||||
3
applications/test/stringSplit/Make/files
Normal file
3
applications/test/stringSplit/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-stringSplit.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-stringSplit
|
||||||
0
applications/test/stringSplit/Make/options
Normal file
0
applications/test/stringSplit/Make/options
Normal file
81
applications/test/stringSplit/Test-stringSplit.C
Normal file
81
applications/test/stringSplit/Test-stringSplit.C
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Application
|
||||||
|
Test-stringSplit
|
||||||
|
|
||||||
|
Description
|
||||||
|
Test string splitting
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "argList.H"
|
||||||
|
#include "fileName.H"
|
||||||
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
using namespace Foam;
|
||||||
|
|
||||||
|
template<class String>
|
||||||
|
void printSplitting(const String& str, const char delimiter)
|
||||||
|
{
|
||||||
|
auto split = stringOps::split(str, delimiter);
|
||||||
|
|
||||||
|
Info<< "string {" << str.size() << " chars} = " << str << nl
|
||||||
|
<< split.size() << " elements {" << split.length() << " chars}"
|
||||||
|
<< nl;
|
||||||
|
|
||||||
|
unsigned i = 0;
|
||||||
|
for (const auto s : split)
|
||||||
|
{
|
||||||
|
Info<< "[" << i++ << "] {" << s.length() << " chars} = "
|
||||||
|
<< s.str() << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
// Main program:
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
argList::noBanner();
|
||||||
|
argList::noParallel();
|
||||||
|
|
||||||
|
argList args(argc, argv, false, true);
|
||||||
|
|
||||||
|
if (args.size() <= 1 && args.options().empty())
|
||||||
|
{
|
||||||
|
args.printUsage();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (label argi=1; argi < args.size(); ++argi)
|
||||||
|
{
|
||||||
|
printSplitting(args[argi], '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< "\nEnd\n" << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -221,6 +221,7 @@ redundantBlock {space}({comment}|{unknownPeriodicFace}|{periodicFace
|
|||||||
endOfSection {space}")"{space}
|
endOfSection {space}")"{space}
|
||||||
|
|
||||||
|
|
||||||
|
/* balance "-quoted for editor */
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------ *\
|
/* ------------------------------------------------------------------------ *\
|
||||||
----- Exclusive start states -----
|
----- Exclusive start states -----
|
||||||
@ -693,7 +694,7 @@ endOfSection {space}")"{space}
|
|||||||
{lbrac}{label} {
|
{lbrac}{label} {
|
||||||
Warning
|
Warning
|
||||||
<< "Found unknown block of type: "
|
<< "Found unknown block of type: "
|
||||||
<< Foam::string(YYText())(1, YYLeng()-1) << nl
|
<< std::string(YYText()).substr(1, YYLeng()-1) << nl
|
||||||
<< " on line " << lineNo << endl;
|
<< " on line " << lineNo << endl;
|
||||||
|
|
||||||
yy_push_state(ignoreBlock);
|
yy_push_state(ignoreBlock);
|
||||||
|
|||||||
@ -903,10 +903,10 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Strip off anything after #
|
// Strip off anything after #
|
||||||
string::size_type i = rawLine.find_first_of("#");
|
string::size_type i = rawLine.find('#');
|
||||||
if (i != string::npos)
|
if (i != string::npos)
|
||||||
{
|
{
|
||||||
rawLine = rawLine(0, i);
|
rawLine.resize(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rawLine.empty())
|
if (rawLine.empty())
|
||||||
|
|||||||
@ -254,7 +254,7 @@ bool merge
|
|||||||
|
|
||||||
if (key[0] == '~')
|
if (key[0] == '~')
|
||||||
{
|
{
|
||||||
word eraseKey = key(1, key.size()-1);
|
const word eraseKey = key.substr(1);
|
||||||
if (thisDict.remove(eraseKey))
|
if (thisDict.remove(eraseKey))
|
||||||
{
|
{
|
||||||
// Mark thisDict entry as having been match for wildcard
|
// Mark thisDict entry as having been match for wildcard
|
||||||
@ -325,7 +325,7 @@ bool merge
|
|||||||
|
|
||||||
if (key[0] == '~')
|
if (key[0] == '~')
|
||||||
{
|
{
|
||||||
word eraseKey = key(1, key.size()-1);
|
const word eraseKey = key.substr(1);
|
||||||
|
|
||||||
// List of indices into thisKeys
|
// List of indices into thisKeys
|
||||||
labelList matches
|
labelList matches
|
||||||
|
|||||||
@ -88,7 +88,7 @@ static inline bool isBackupName(const Foam::fileName& name)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (name[name.size()-1] == '~')
|
else if (name.back() == '~')
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,10 +42,9 @@ 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");
|
FILE *cmdPipe = popen(cmd.c_str(), "r");
|
||||||
|
|
||||||
if (cmdPipe)
|
if (cmdPipe)
|
||||||
{
|
{
|
||||||
char *buf = nullptr;
|
char *buf = nullptr;
|
||||||
@ -54,8 +53,7 @@ string pOpen(const string &cmd, label line=0)
|
|||||||
for (label cnt = 0; cnt <= line; cnt++)
|
for (label cnt = 0; cnt <= line; cnt++)
|
||||||
{
|
{
|
||||||
size_t linecap = 0;
|
size_t linecap = 0;
|
||||||
ssize_t linelen;
|
ssize_t linelen = ::getline(&buf, &linecap, cmdPipe);
|
||||||
linelen = ::getline(&buf, &linecap, cmdPipe);
|
|
||||||
|
|
||||||
if (linelen < 0)
|
if (linelen < 0)
|
||||||
{
|
{
|
||||||
@ -65,6 +63,11 @@ string pOpen(const string &cmd, label line=0)
|
|||||||
if (cnt == line)
|
if (cnt == line)
|
||||||
{
|
{
|
||||||
res = string(buf);
|
res = string(buf);
|
||||||
|
// Trim trailing newline
|
||||||
|
if (res.size())
|
||||||
|
{
|
||||||
|
res.resize(res.size()-1);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +80,7 @@ string pOpen(const string &cmd, label line=0)
|
|||||||
pclose(cmdPipe);
|
pclose(cmdPipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.substr(0, res.size() - 1);
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -604,13 +604,14 @@ Foam::Istream& Foam::ISstream::readVariable(string& str)
|
|||||||
// Read, counting brackets
|
// Read, counting brackets
|
||||||
buf[nChar++] = c;
|
buf[nChar++] = c;
|
||||||
|
|
||||||
|
// Also allow '/' between ${...} blocks for slash-scoping of entries
|
||||||
while
|
while
|
||||||
(
|
(
|
||||||
get(c)
|
get(c)
|
||||||
&& (
|
&& (
|
||||||
c == token::BEGIN_BLOCK
|
c == token::BEGIN_BLOCK
|
||||||
|| c == token::END_BLOCK
|
|| c == token::END_BLOCK
|
||||||
|| word::valid(c)
|
|| word::valid(c) || c == '/'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -620,7 +621,7 @@ Foam::Istream& Foam::ISstream::readVariable(string& str)
|
|||||||
buf[errLen] = '\0';
|
buf[errLen] = '\0';
|
||||||
|
|
||||||
FatalIOErrorInFunction(*this)
|
FatalIOErrorInFunction(*this)
|
||||||
<< "word '" << buf << "...'\n"
|
<< "variable '" << buf << "...'\n"
|
||||||
<< " is too long (max. " << maxLen << " characters)"
|
<< " is too long (max. " << maxLen << " characters)"
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
|
|
||||||
@ -656,7 +657,7 @@ Foam::Istream& Foam::ISstream::readVariable(string& str)
|
|||||||
buf[errLen] = '\0';
|
buf[errLen] = '\0';
|
||||||
|
|
||||||
FatalIOErrorInFunction(*this)
|
FatalIOErrorInFunction(*this)
|
||||||
<< "word '" << buf << "...'\n"
|
<< "variable '" << buf << "...'\n"
|
||||||
<< " is too long (max. " << maxLen << " characters)"
|
<< " is too long (max. " << maxLen << " characters)"
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
|
|
||||||
|
|||||||
@ -130,7 +130,7 @@ bool Foam::dictionary::read(Istream& is)
|
|||||||
|
|
||||||
bool Foam::dictionary::substituteKeyword(const word& keyword, bool mergeEntry)
|
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
|
// Lookup the variable name in the given dictionary
|
||||||
const entry* ePtr = lookupEntryPtr(varName, true, true);
|
const entry* ePtr = lookupEntryPtr(varName, true, true);
|
||||||
|
|||||||
@ -210,7 +210,7 @@ bool Foam::functionObjectList::readFunctionObject
|
|||||||
{
|
{
|
||||||
if (argLevel == 0)
|
if (argLevel == 0)
|
||||||
{
|
{
|
||||||
funcName = funcNameArgs(start, i - start);
|
funcName = funcNameArgs.substr(start, i - start);
|
||||||
start = i+1;
|
start = i+1;
|
||||||
}
|
}
|
||||||
++argLevel;
|
++argLevel;
|
||||||
@ -226,7 +226,7 @@ bool Foam::functionObjectList::readFunctionObject
|
|||||||
Tuple2<word, string>
|
Tuple2<word, string>
|
||||||
(
|
(
|
||||||
argName,
|
argName,
|
||||||
funcNameArgs(start, i - start)
|
funcNameArgs.substr(start, i - start)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
namedArg = false;
|
namedArg = false;
|
||||||
@ -235,7 +235,10 @@ bool Foam::functionObjectList::readFunctionObject
|
|||||||
{
|
{
|
||||||
args.append
|
args.append
|
||||||
(
|
(
|
||||||
string::validate<word>(funcNameArgs(start, i - start))
|
string::validate<word>
|
||||||
|
(
|
||||||
|
funcNameArgs.substr(start, i - start)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
start = i+1;
|
start = i+1;
|
||||||
@ -252,7 +255,11 @@ bool Foam::functionObjectList::readFunctionObject
|
|||||||
}
|
}
|
||||||
else if (c == '=')
|
else if (c == '=')
|
||||||
{
|
{
|
||||||
argName = string::validate<word>(funcNameArgs(start, i - start));
|
argName = string::validate<word>
|
||||||
|
(
|
||||||
|
funcNameArgs.substr(start, i - start)
|
||||||
|
);
|
||||||
|
|
||||||
start = i+1;
|
start = i+1;
|
||||||
namedArg = true;
|
namedArg = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,7 +140,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
|
|||||||
{
|
{
|
||||||
if (i > start)
|
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)
|
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
|
||||||
{
|
{
|
||||||
push(token(readScalar(IStringStream(subWord)())));
|
push(token(readScalar(IStringStream(subWord)())));
|
||||||
@ -166,7 +166,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
|
|||||||
}
|
}
|
||||||
if (start < w.size())
|
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)
|
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
|
||||||
{
|
{
|
||||||
push(token(readScalar(IStringStream(subWord)())));
|
push(token(readScalar(IStringStream(subWord)())));
|
||||||
@ -524,9 +524,9 @@ Foam::Istream& Foam::dimensionSet::read
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
word symbolPow = nextToken.wordToken();
|
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;
|
continueParsing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,8 +537,8 @@ Foam::Istream& Foam::dimensionSet::read
|
|||||||
size_t index = symbolPow.find('^');
|
size_t index = symbolPow.find('^');
|
||||||
if (index != string::npos)
|
if (index != string::npos)
|
||||||
{
|
{
|
||||||
word symbol = symbolPow(0, index);
|
const word symbol = symbolPow.substr(0, index);
|
||||||
word exp = symbolPow(index+1, symbolPow.size()-index+1);
|
const word exp = symbolPow.substr(index+1);
|
||||||
scalar exponent = readScalar(IStringStream(exp)());
|
scalar exponent = readScalar(IStringStream(exp)());
|
||||||
|
|
||||||
dimensionedScalar s;
|
dimensionedScalar s;
|
||||||
@ -580,9 +580,9 @@ Foam::Istream& Foam::dimensionSet::read
|
|||||||
{
|
{
|
||||||
// Read first five dimensions
|
// Read first five dimensions
|
||||||
exponents_[dimensionSet::MASS] = nextToken.number();
|
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
|
// Read next token
|
||||||
|
|||||||
@ -76,17 +76,14 @@ void Foam::solution::read(const dictionary& dict)
|
|||||||
const word& e = entryNames[i];
|
const word& e = entryNames[i];
|
||||||
scalar value = readScalar(relaxDict.lookup(e));
|
scalar value = readScalar(relaxDict.lookup(e));
|
||||||
|
|
||||||
if (e(0, 1) == "p")
|
if (e.startsWith("p"))
|
||||||
{
|
{
|
||||||
fieldRelaxDict_.add(e, value);
|
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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
127
src/OpenFOAM/primitives/strings/lists/SubStrings.H
Normal file
127
src/OpenFOAM/primitives/strings/lists/SubStrings.H
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::SubStrings
|
||||||
|
|
||||||
|
Description
|
||||||
|
Sub-ranges of a string with a structure similar to std::match_results,
|
||||||
|
but without the underlying regular expression matching.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef SubStrings_H
|
||||||
|
#define SubStrings_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <regex>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class SubStrings Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
template<class String>
|
||||||
|
class SubStrings
|
||||||
|
:
|
||||||
|
public std::vector<std::sub_match<typename String::const_iterator>>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Typedefs
|
||||||
|
|
||||||
|
//- The element type
|
||||||
|
using value_type =
|
||||||
|
typename std::sub_match<typename String::const_iterator>;
|
||||||
|
|
||||||
|
//- The const_iterator for the underlying string type
|
||||||
|
using string_iterator = typename String::const_iterator;
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
SubStrings()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- The total length of all sub-elements.
|
||||||
|
// Use size() for the number elements.
|
||||||
|
std::string::size_type length() const
|
||||||
|
{
|
||||||
|
std::string::size_type len = 0;
|
||||||
|
|
||||||
|
for (const auto& elem : *this)
|
||||||
|
{
|
||||||
|
len += elem.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Append sub-string defined by begin/end iterators
|
||||||
|
void append(string_iterator b, string_iterator e)
|
||||||
|
{
|
||||||
|
value_type range;
|
||||||
|
range.first = b;
|
||||||
|
range.second = e;
|
||||||
|
range.matched = true;
|
||||||
|
|
||||||
|
this->push_back(range);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Const reference to the first element,
|
||||||
|
// for consistency with other OpenFOAM containers
|
||||||
|
auto first() const -> decltype(this->front())
|
||||||
|
{
|
||||||
|
return this->front();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Const reference to the last element,
|
||||||
|
// for consistency with other OpenFOAM containers
|
||||||
|
auto last() const -> decltype(this->back())
|
||||||
|
{
|
||||||
|
return this->back();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -30,12 +30,14 @@ Description
|
|||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
stringOps.C
|
stringOps.C
|
||||||
|
stringOpsTemplates.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
#ifndef stringOps_H
|
#ifndef stringOps_H
|
||||||
#define stringOps_H
|
#define stringOps_H
|
||||||
|
|
||||||
#include "string.H"
|
#include "string.H"
|
||||||
|
#include "SubStrings.H"
|
||||||
#include "word.H"
|
#include "word.H"
|
||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
@ -302,14 +304,21 @@ namespace stringOps
|
|||||||
Foam::word name(const std::string& fmt, const PrimitiveType& val);
|
Foam::word name(const std::string& fmt, const PrimitiveType& val);
|
||||||
|
|
||||||
|
|
||||||
} // End namespace stringOps
|
//- Split a string into sub-strings at the delimiter character.
|
||||||
|
// An empty sub-strings are suppressed.
|
||||||
|
template<class StringType>
|
||||||
|
Foam::SubStrings<StringType> split
|
||||||
|
(
|
||||||
|
const StringType& str,
|
||||||
|
const char delimiter
|
||||||
|
);
|
||||||
|
|
||||||
|
} // End namespace stringOps
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#ifdef NoRepository
|
#ifdef NoRepository
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -65,4 +65,36 @@ Foam::word Foam::stringOps::name
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class StringType>
|
||||||
|
Foam::SubStrings<StringType> Foam::stringOps::split
|
||||||
|
(
|
||||||
|
const StringType& str,
|
||||||
|
const char delimiter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Foam::SubStrings<StringType> lst;
|
||||||
|
lst.reserve(20);
|
||||||
|
|
||||||
|
std::string::size_type beg = 0, end = 0;
|
||||||
|
|
||||||
|
while ((end = str.find(delimiter, beg)) != std::string::npos)
|
||||||
|
{
|
||||||
|
if (beg < end)
|
||||||
|
{
|
||||||
|
// (Non-empty) intermediate element
|
||||||
|
lst.append(str.cbegin() + beg, str.cbegin() + end);
|
||||||
|
}
|
||||||
|
beg = end + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (Non-empty) trailing element
|
||||||
|
if (beg < str.size())
|
||||||
|
{
|
||||||
|
lst.append(str.cbegin() + beg, str.cbegin() + str.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
return lst;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -113,9 +113,9 @@ public:
|
|||||||
inline static bool valid(char c);
|
inline static bool valid(char c);
|
||||||
|
|
||||||
//- Construct a validated word, in which all invalid characters have
|
//- Construct a validated word, in which all invalid characters have
|
||||||
// been stripped out. Normally also prefix any leading digit
|
// been stripped out. Optionally prefix any leading digit
|
||||||
// with '_' to have words that work nicely as dictionary keywords.
|
// with '_' to have words that work nicely as dictionary keywords.
|
||||||
static word validated(const std::string& s, const bool prefix=true);
|
static word validated(const std::string& s, const bool prefix=false);
|
||||||
|
|
||||||
|
|
||||||
// File-like functions
|
// File-like functions
|
||||||
|
|||||||
@ -34,16 +34,15 @@ Foam::autoPtr<Foam::reactionRateFlameArea> Foam::reactionRateFlameArea::New
|
|||||||
const combustionModel& combModel
|
const combustionModel& combModel
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
word reactionRateFlameAreaType
|
const word modelType
|
||||||
(
|
(
|
||||||
dict.lookup("reactionRateFlameArea")
|
dict.lookup("reactionRateFlameArea")
|
||||||
);
|
);
|
||||||
|
|
||||||
Info<< "Selecting reaction rate flame area correlation "
|
Info<< "Selecting reaction rate flame area correlation "
|
||||||
<< reactionRateFlameAreaType << endl;
|
<< modelType << endl;
|
||||||
|
|
||||||
auto cstrIter =
|
auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
|
||||||
dictionaryConstructorTablePtr_->cfind(reactionRateFlameAreaType);
|
|
||||||
|
|
||||||
if (!cstrIter.found())
|
if (!cstrIter.found())
|
||||||
{
|
{
|
||||||
@ -51,15 +50,13 @@ Foam::autoPtr<Foam::reactionRateFlameArea> Foam::reactionRateFlameArea::New
|
|||||||
(
|
(
|
||||||
dict
|
dict
|
||||||
) << "Unknown reactionRateFlameArea type "
|
) << "Unknown reactionRateFlameArea type "
|
||||||
<< reactionRateFlameAreaType << nl << nl
|
<< modelType << nl << nl
|
||||||
<< "Valid reaction rate flame area types :" << endl
|
<< "Valid reaction rate flame area types :" << endl
|
||||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
const label tempOpen = reactionRateFlameAreaType.find('<');
|
const word className = modelType.substr(0, modelType.find('<'));
|
||||||
|
|
||||||
const word className = reactionRateFlameAreaType(0, tempOpen);
|
|
||||||
|
|
||||||
return autoPtr<reactionRateFlameArea>
|
return autoPtr<reactionRateFlameArea>
|
||||||
(cstrIter()(className, dict, mesh, combModel));
|
(cstrIter()(className, dict, mesh, combModel));
|
||||||
|
|||||||
@ -35,7 +35,7 @@ Foam::combustionModels::psiCombustionModel::New
|
|||||||
const word& phaseName
|
const word& phaseName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const word combModelName
|
const word modelType
|
||||||
(
|
(
|
||||||
IOdictionary
|
IOdictionary
|
||||||
(
|
(
|
||||||
@ -51,21 +51,21 @@ Foam::combustionModels::psiCombustionModel::New
|
|||||||
).lookup("combustionModel")
|
).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())
|
if (!cstrIter.found())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Unknown psiCombustionModel type "
|
<< "Unknown psiCombustionModel type "
|
||||||
<< combModelName << endl << endl
|
<< modelType << nl << nl
|
||||||
<< "Valid combustionModel types :" << endl
|
<< "Valid combustionModel types :" << nl
|
||||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
const word className = combModelName(0, combModelName.find('<'));
|
const word className = modelType.substr(0, modelType.find('<'));
|
||||||
|
|
||||||
return autoPtr<psiCombustionModel>
|
return autoPtr<psiCombustionModel>
|
||||||
(
|
(
|
||||||
|
|||||||
@ -35,7 +35,7 @@ Foam::combustionModels::rhoCombustionModel::New
|
|||||||
const word& phaseName
|
const word& phaseName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
const word combTypeName
|
const word modelType
|
||||||
(
|
(
|
||||||
IOdictionary
|
IOdictionary
|
||||||
(
|
(
|
||||||
@ -51,23 +51,21 @@ Foam::combustionModels::rhoCombustionModel::New
|
|||||||
).lookup("combustionModel")
|
).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())
|
if (!cstrIter.found())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Unknown rhoCombustionModel type "
|
<< "Unknown rhoCombustionModel type "
|
||||||
<< combTypeName << endl << endl
|
<< modelType << nl << nl
|
||||||
<< "Valid combustionModel types :" << endl
|
<< "Valid combustionModel types :" << nl
|
||||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
const label tempOpen = combTypeName.find('<');
|
const word className = modelType.substr(0, modelType.find('<'));
|
||||||
|
|
||||||
const word className = combTypeName(0, tempOpen);
|
|
||||||
|
|
||||||
return autoPtr<rhoCombustionModel>
|
return autoPtr<rhoCombustionModel>
|
||||||
(
|
(
|
||||||
|
|||||||
@ -365,7 +365,7 @@ void Foam::ccm::reader::readProblemDescription_boundaryRegion
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dict.add(opt, word::validated(str));
|
dict.add(opt, word::validated(str, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +407,7 @@ void Foam::ccm::reader::readProblemDescription_boundaryRegion
|
|||||||
|
|
||||||
if (!str.empty())
|
if (!str.empty())
|
||||||
{
|
{
|
||||||
dict.add(opt, word::validated(str));
|
dict.add(opt, word::validated(str, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,7 +472,7 @@ void Foam::ccm::reader::readProblemDescription_cellTable
|
|||||||
str = "zone_" + ::Foam::name(Id);
|
str = "zone_" + ::Foam::name(Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
dict.add(opt, word::validated(str));
|
dict.add(opt, word::validated(str, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -484,7 +484,7 @@ void Foam::ccm::reader::readProblemDescription_cellTable
|
|||||||
|
|
||||||
if (!str.empty())
|
if (!str.empty())
|
||||||
{
|
{
|
||||||
dict.add(opt, word::validated(str));
|
dict.add(opt, word::validated(str, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -155,7 +155,7 @@ void Foam::fileFormats::FIREMeshReader::readSelections(ISstream& is)
|
|||||||
// index starting at 1
|
// index starting at 1
|
||||||
const label selId = ++nCellSelections;
|
const label selId = ++nCellSelections;
|
||||||
|
|
||||||
cellTable_.setName(selId, word::validated(name));
|
cellTable_.setName(selId, word::validated(name, true));
|
||||||
cellTable_.setMaterial(selId, "fluid");
|
cellTable_.setMaterial(selId, "fluid");
|
||||||
|
|
||||||
for (label i = 0; i < count; ++i)
|
for (label i = 0; i < count; ++i)
|
||||||
@ -170,7 +170,7 @@ void Foam::fileFormats::FIREMeshReader::readSelections(ISstream& is)
|
|||||||
// index starting at 0
|
// index starting at 0
|
||||||
const label selId = nFaceSelections++;
|
const label selId = nFaceSelections++;
|
||||||
|
|
||||||
faceNames.append(word::validated(name));
|
faceNames.append(word::validated(name, true));
|
||||||
|
|
||||||
for (label i = 0; i < count; ++i)
|
for (label i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -74,7 +74,7 @@ bool Foam::fileFormats::NASedgeFormat::read
|
|||||||
// Check if character 72 is continuation
|
// Check if character 72 is continuation
|
||||||
if (line.size() > 72 && line[72] == '+')
|
if (line.size() > 72 && line[72] == '+')
|
||||||
{
|
{
|
||||||
line = line.substr(0, 72);
|
line.resize(72);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -87,7 +87,7 @@ bool Foam::fileFormats::NASedgeFormat::read
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
line += buf.substr(8, buf.size()-8);
|
line += buf.substr(8);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,9 +117,9 @@ bool Foam::fileFormats::OBJedgeFormat::read(const fileName& filename)
|
|||||||
string line = this->getLineNoComment(is);
|
string line = this->getLineNoComment(is);
|
||||||
|
|
||||||
// handle continuations
|
// 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);
|
line += this->getLineNoComment(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -191,9 +191,8 @@ void thermalBaffleFvPatchScalarField::createPatchMesh()
|
|||||||
dicts[bottomPatchID].add("inGroups", inGroups);
|
dicts[bottomPatchID].add("inGroups", inGroups);
|
||||||
dicts[bottomPatchID].add("sampleMode", mpp.sampleModeNames_[mpp.mode()]);
|
dicts[bottomPatchID].add("sampleMode", mpp.sampleModeNames_[mpp.mode()]);
|
||||||
|
|
||||||
const label sepPos = coupleGroup.find('_');
|
const word coupleGroupSlave =
|
||||||
|
coupleGroup.substr(0, coupleGroup.find('_')) + "_slave";
|
||||||
const word coupleGroupSlave = coupleGroup(0, sepPos) + "_slave";
|
|
||||||
|
|
||||||
inGroups[0] = coupleGroupSlave;
|
inGroups[0] = coupleGroupSlave;
|
||||||
dicts[topPatchID].add("coupleGroup", coupleGroupSlave);
|
dicts[topPatchID].add("coupleGroup", coupleGroupSlave);
|
||||||
|
|||||||
@ -186,7 +186,7 @@ void Foam::ensightSurfaceReader::readCase(IFstream& is)
|
|||||||
// surfaceName.****.fieldName
|
// surfaceName.****.fieldName
|
||||||
// This is not parser friendly - simply take remainder of buffer
|
// This is not parser friendly - simply take remainder of buffer
|
||||||
label iPos = iss.stdStream().tellg();
|
label iPos = iss.stdStream().tellg();
|
||||||
fieldFileName = buffer(iPos, buffer.size() - iPos);
|
fieldFileName = buffer.substr(iPos);
|
||||||
size_t p0 = fieldFileName.find_first_not_of(' ');
|
size_t p0 = fieldFileName.find_first_not_of(' ');
|
||||||
if (p0 == string::npos)
|
if (p0 == string::npos)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -89,8 +89,8 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
string line;
|
string line;
|
||||||
is.getLine(line);
|
is.getLine(line);
|
||||||
|
|
||||||
// Ansa extension
|
// ANSA extension
|
||||||
if (line.substr(0, 10) == "$ANSA_NAME")
|
if (line.startsWith("$ANSA_NAME"))
|
||||||
{
|
{
|
||||||
string::size_type sem0 = line.find(';', 0);
|
string::size_type sem0 = line.find(';', 0);
|
||||||
string::size_type sem1 = line.find(';', sem0+1);
|
string::size_type sem1 = line.find(';', sem0+1);
|
||||||
@ -111,14 +111,11 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
|
|
||||||
string rawName;
|
string rawName;
|
||||||
is.getLine(rawName);
|
is.getLine(rawName);
|
||||||
if (rawName[rawName.size()-1] == '\r')
|
if (rawName.back() == '\r')
|
||||||
{
|
{
|
||||||
rawName = rawName.substr(1, rawName.size()-2);
|
rawName.resize(rawName.size()-1);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rawName = rawName.substr(1, rawName.size()-1);
|
|
||||||
}
|
}
|
||||||
|
rawName = rawName.substr(1);
|
||||||
|
|
||||||
string::stripInvalid<word>(rawName);
|
string::stripInvalid<word>(rawName);
|
||||||
ansaName = rawName;
|
ansaName = rawName;
|
||||||
@ -132,11 +129,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
|
|
||||||
// Hypermesh extension
|
// Hypermesh extension
|
||||||
// $HMNAME COMP 1"partName"
|
// $HMNAME COMP 1"partName"
|
||||||
if
|
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
|
||||||
(
|
|
||||||
line.substr(0, 12) == "$HMNAME COMP"
|
|
||||||
&& line.find ('"') != string::npos
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
label groupId = readLabel
|
label groupId = readLabel
|
||||||
(
|
(
|
||||||
@ -165,7 +158,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
// Check if character 72 is continuation
|
// Check if character 72 is continuation
|
||||||
if (line.size() > 72 && line[72] == '+')
|
if (line.size() > 72 && line[72] == '+')
|
||||||
{
|
{
|
||||||
line = line.substr(0, 72);
|
line.resize(72);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -178,7 +171,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
line += buf.substr(8, buf.size()-8);
|
line += buf.substr(8);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,9 +82,9 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
|
|||||||
string line = this->getLineNoComment(is);
|
string line = this->getLineNoComment(is);
|
||||||
|
|
||||||
// handle continuations
|
// 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);
|
line += this->getLineNoComment(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -64,7 +64,7 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
|
|||||||
if (ctnameRE.match(line, groups))
|
if (ctnameRE.match(line, groups))
|
||||||
{
|
{
|
||||||
const label tableId = atoi(groups[0].c_str());
|
const label tableId = atoi(groups[0].c_str());
|
||||||
const word tableName = word::validated(groups[1]);
|
const word tableName = word::validated(groups[1], true);
|
||||||
|
|
||||||
if (!tableName.empty())
|
if (!tableName.empty())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -87,9 +87,9 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
|
|||||||
string line = this->getLineNoComment(is);
|
string line = this->getLineNoComment(is);
|
||||||
|
|
||||||
// handle continuations ?
|
// 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);
|
// line += this->getLineNoComment(is);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@ -128,14 +128,14 @@ bool Foam::fileFormats::TRIsurfaceFormatCore::read
|
|||||||
// ie, instead of having 0xFF, skip 0 and leave xFF to
|
// ie, instead of having 0xFF, skip 0 and leave xFF to
|
||||||
// get read as a word and name it "zoneFF"
|
// get read as a word and name it "zoneFF"
|
||||||
|
|
||||||
char zero;
|
char zeroChar;
|
||||||
lineStream >> zero;
|
lineStream >> zeroChar;
|
||||||
|
|
||||||
word rawName(lineStream);
|
const word rawName(lineStream);
|
||||||
word name("zone" + rawName(1, rawName.size()-1));
|
const word name("zone" + rawName.substr(1));
|
||||||
|
|
||||||
HashTable<label>::const_iterator fnd = lookup.find(name);
|
HashTable<label>::const_iterator fnd = lookup.cfind(name);
|
||||||
if (fnd != lookup.end())
|
if (fnd.found())
|
||||||
{
|
{
|
||||||
if (zoneI != fnd())
|
if (zoneI != fnd())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -32,7 +32,6 @@ Description
|
|||||||
GRID 28 10.20269-.030265-2.358-8
|
GRID 28 10.20269-.030265-2.358-8
|
||||||
\endverbatim
|
\endverbatim
|
||||||
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "triSurface.H"
|
#include "triSurface.H"
|
||||||
@ -78,11 +77,8 @@ static std::string readNASToken
|
|||||||
size_t& index
|
size_t& index
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
size_t indexStart, indexEnd;
|
size_t indexStart = index;
|
||||||
|
size_t indexEnd = line.find(',', indexStart);
|
||||||
indexStart = index;
|
|
||||||
|
|
||||||
indexEnd = line.find(',', indexStart);
|
|
||||||
index = indexEnd + 1;
|
index = indexEnd + 1;
|
||||||
|
|
||||||
if (indexEnd == std::string::npos)
|
if (indexEnd == std::string::npos)
|
||||||
@ -134,8 +130,8 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
string line;
|
string line;
|
||||||
is.getLine(line);
|
is.getLine(line);
|
||||||
|
|
||||||
// Ansa extension
|
// ANSA extension
|
||||||
if (line.substr(0, 10) == "$ANSA_NAME")
|
if (line.startsWith("$ANSA_NAME"))
|
||||||
{
|
{
|
||||||
string::size_type sem0 = line.find(';', 0);
|
string::size_type sem0 = line.find(';', 0);
|
||||||
string::size_type sem1 = line.find(';', sem0+1);
|
string::size_type sem1 = line.find(';', sem0+1);
|
||||||
@ -156,15 +152,11 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
|
|
||||||
string nameString;
|
string nameString;
|
||||||
is.getLine(ansaName);
|
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 = ansaName.substr(1, ansaName.size()-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info<< "ANSA tag for NastranID:" << ansaId
|
// Info<< "ANSA tag for NastranID:" << ansaId
|
||||||
// << " of type " << ansaType
|
// << " of type " << ansaType
|
||||||
// << " name " << ansaName << endl;
|
// << " name " << ansaName << endl;
|
||||||
@ -174,11 +166,7 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
|
|
||||||
// Hypermesh extension
|
// Hypermesh extension
|
||||||
// $HMNAME COMP 1"partName"
|
// $HMNAME COMP 1"partName"
|
||||||
if
|
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
|
||||||
(
|
|
||||||
line.substr(0, 12) == "$HMNAME COMP"
|
|
||||||
&& line.find ('"') != string::npos
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
label groupId = readLabel
|
label groupId = readLabel
|
||||||
(
|
(
|
||||||
@ -204,7 +192,7 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
// Check if character 72 is continuation
|
// Check if character 72 is continuation
|
||||||
if (line.size() > 72 && line[72] == '+')
|
if (line.size() > 72 && line[72] == '+')
|
||||||
{
|
{
|
||||||
line = line.substr(0, 72);
|
line.resize(72);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -217,7 +205,7 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
line += buf.substr(8, buf.size()-8);
|
line += buf.substr(8);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,13 +51,13 @@ bool Foam::triSurface::readOBJ(const fileName& OBJfileName)
|
|||||||
{
|
{
|
||||||
string line = getLineNoComment(OBJfile);
|
string line = getLineNoComment(OBJfile);
|
||||||
|
|
||||||
label sz = line.size();
|
const label sz = line.size();
|
||||||
|
|
||||||
if (sz)
|
if (sz)
|
||||||
{
|
{
|
||||||
if (line[sz-1] == '\\')
|
if (line.back() == '\\')
|
||||||
{
|
{
|
||||||
line.substr(0, sz-1);
|
line.resize(sz-1);
|
||||||
line += getLineNoComment(OBJfile);
|
line += getLineNoComment(OBJfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -99,19 +99,18 @@ bool Foam::triSurface::readTRI(const fileName& TRIfileName)
|
|||||||
|
|
||||||
// Region/colour in .tri file starts with 0x. Skip.
|
// Region/colour in .tri file starts with 0x. Skip.
|
||||||
|
|
||||||
char zero;
|
char zeroChar;
|
||||||
lineStream >> zero;
|
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;
|
label region = -1;
|
||||||
|
|
||||||
HashTable<label, string>::const_iterator fnd =
|
auto fnd = STLsolidNames.cfind(solidName);
|
||||||
STLsolidNames.find(solidName);
|
|
||||||
|
|
||||||
if (fnd != STLsolidNames.end())
|
if (fnd.found())
|
||||||
{
|
{
|
||||||
region = fnd();
|
region = fnd();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -531,11 +531,11 @@ void Foam::radiation::fvDOM::setRayIdLambdaId
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// assuming name is in the form: CHARS_rayId_lambdaId
|
// assuming name is in the form: CHARS_rayId_lambdaId
|
||||||
size_type i1 = name.find_first_of("_");
|
const size_type i1 = name.find('_');
|
||||||
size_type i2 = name.find_last_of("_");
|
const size_type i2 = name.rfind('_');
|
||||||
|
|
||||||
rayId = readLabel(IStringStream(name.substr(i1+1, i2-1))());
|
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))());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -56,9 +56,7 @@ Foam::radiation::sootModel::New
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
const label tempOpen = modelType.find('<');
|
const word className = modelType.substr(0, modelType.find('<'));
|
||||||
|
|
||||||
const word className = modelType(0, tempOpen);
|
|
||||||
|
|
||||||
return autoPtr<sootModel>(cstrIter()(dict, mesh, className));
|
return autoPtr<sootModel>(cstrIter()(dict, mesh, className));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -382,7 +382,7 @@ bool finishReaction = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
<readSpecies>{specieName} {
|
<readSpecies>{specieName} {
|
||||||
word specieName(foamName(foamSpecieString(YYText())));
|
const word specieName(foamName(foamSpecieString(YYText())));
|
||||||
|
|
||||||
if (specieName == "THERMO")
|
if (specieName == "THERMO")
|
||||||
{
|
{
|
||||||
@ -429,10 +429,10 @@ bool finishReaction = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
<readThermoAll>{thermoTemp}{thermoTemp}{thermoTemp} {
|
<readThermoAll>{thermoTemp}{thermoTemp}{thermoTemp} {
|
||||||
string temperaturesString(YYText());
|
const string temperaturesString(YYText());
|
||||||
//scalar lowestT(stringToScalar(temperaturesString(0, 10)));
|
//scalar lowestT(stringToScalar(temperaturesString.substr(0, 10)));
|
||||||
allCommonT = stringToScalar(temperaturesString(10, 10));
|
allCommonT = stringToScalar(temperaturesString.substr(10, 10));
|
||||||
//scalar highestT(stringToScalar(temperaturesString(20, 10)));
|
//scalar highestT(stringToScalar(temperaturesString.substr(20, 10)));
|
||||||
BEGIN(readThermoSpecieName);
|
BEGIN(readThermoSpecieName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,7 +449,7 @@ bool finishReaction = false;
|
|||||||
size_t spacePos = specieString.find(' ');
|
size_t spacePos = specieString.find(' ');
|
||||||
if (spacePos != string::npos)
|
if (spacePos != string::npos)
|
||||||
{
|
{
|
||||||
currentSpecieName = specieString(0, spacePos);
|
currentSpecieName = specieString.substr(0, spacePos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -467,15 +467,15 @@ bool finishReaction = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
<readThermoFormula>{thermoFormula} {
|
<readThermoFormula>{thermoFormula} {
|
||||||
string thermoFormula(YYText());
|
const string thermoFormula(YYText());
|
||||||
|
|
||||||
nSpecieElements = 0;
|
nSpecieElements = 0;
|
||||||
currentSpecieComposition.setSize(5);
|
currentSpecieComposition.setSize(5);
|
||||||
|
|
||||||
for (int i=0; i<4; i++)
|
for (int i=0; i<4; i++)
|
||||||
{
|
{
|
||||||
word elementName(foamName(thermoFormula(5*i, 2)));
|
word elementName(foamName(thermoFormula.substr(5*i, 2)));
|
||||||
label nAtoms = atoi(thermoFormula(5*i + 2, 3).c_str());
|
label nAtoms = atoi(thermoFormula.substr(5*i + 2, 3).c_str());
|
||||||
|
|
||||||
if (elementName.size() && nAtoms)
|
if (elementName.size() && nAtoms)
|
||||||
{
|
{
|
||||||
@ -490,7 +490,7 @@ bool finishReaction = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
<readThermoPhase>{thermoPhase} {
|
<readThermoPhase>{thermoPhase} {
|
||||||
char phaseChar = YYText()[0];
|
const char phaseChar = YYText()[0];
|
||||||
|
|
||||||
switch (phaseChar)
|
switch (phaseChar)
|
||||||
{
|
{
|
||||||
@ -511,10 +511,10 @@ bool finishReaction = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
<readThermoTemps>{thermoLowTemp}{thermoHighTemp}{thermoCommonTemp} {
|
<readThermoTemps>{thermoLowTemp}{thermoHighTemp}{thermoCommonTemp} {
|
||||||
string temperaturesString(YYText());
|
const string temperaturesString(YYText());
|
||||||
currentLowT = stringToScalar(temperaturesString(0, 10));
|
currentLowT = stringToScalar(temperaturesString.substr(0, 10));
|
||||||
currentHighT = stringToScalar(temperaturesString(10, 10));
|
currentHighT = stringToScalar(temperaturesString.substr(10, 10));
|
||||||
currentCommonT = stringToScalar(temperaturesString(20, 8));
|
currentCommonT = stringToScalar(temperaturesString.substr(20, 8));
|
||||||
|
|
||||||
if (currentCommonT < SMALL)
|
if (currentCommonT < SMALL)
|
||||||
{
|
{
|
||||||
@ -525,9 +525,9 @@ bool finishReaction = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
<readThermoFormula2>{thermoFormula2} {
|
<readThermoFormula2>{thermoFormula2} {
|
||||||
string thermoFormula(YYText());
|
const string thermoFormula(YYText());
|
||||||
word elementName(foamName(thermoFormula(0, 2)));
|
word elementName(foamName(thermoFormula.substr(0, 2)));
|
||||||
label nAtoms = atoi(thermoFormula(2, 3).c_str());
|
const label nAtoms = atoi(thermoFormula.substr(2, 3).c_str());
|
||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
@ -568,13 +568,13 @@ bool finishReaction = false;
|
|||||||
}
|
}
|
||||||
|
|
||||||
<readThermoCoeff1>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
|
<readThermoCoeff1>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
|
||||||
string thermoCoeffString(YYText());
|
const string thermoCoeffString(YYText());
|
||||||
|
|
||||||
highCpCoeffs[0] = stringToScalar(thermoCoeffString(0, 15));
|
highCpCoeffs[0] = stringToScalar(thermoCoeffString.substr(0, 15));
|
||||||
highCpCoeffs[1] = stringToScalar(thermoCoeffString(15, 15));
|
highCpCoeffs[1] = stringToScalar(thermoCoeffString.substr(15, 15));
|
||||||
highCpCoeffs[2] = stringToScalar(thermoCoeffString(30, 15));
|
highCpCoeffs[2] = stringToScalar(thermoCoeffString.substr(30, 15));
|
||||||
highCpCoeffs[3] = stringToScalar(thermoCoeffString(45, 15));
|
highCpCoeffs[3] = stringToScalar(thermoCoeffString.substr(45, 15));
|
||||||
highCpCoeffs[4] = stringToScalar(thermoCoeffString(60, 15));
|
highCpCoeffs[4] = stringToScalar(thermoCoeffString.substr(60, 15));
|
||||||
|
|
||||||
BEGIN(readThermoLineLabel2);
|
BEGIN(readThermoLineLabel2);
|
||||||
}
|
}
|
||||||
@ -586,12 +586,12 @@ bool finishReaction = false;
|
|||||||
<readThermoCoeff2>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
|
<readThermoCoeff2>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
|
||||||
string thermoCoeffString(YYText());
|
string thermoCoeffString(YYText());
|
||||||
|
|
||||||
highCpCoeffs[5] = stringToScalar(thermoCoeffString(0, 15));
|
highCpCoeffs[5] = stringToScalar(thermoCoeffString.substr(0, 15));
|
||||||
highCpCoeffs[6] = stringToScalar(thermoCoeffString(15, 15));
|
highCpCoeffs[6] = stringToScalar(thermoCoeffString.substr(15, 15));
|
||||||
|
|
||||||
lowCpCoeffs[0] = stringToScalar(thermoCoeffString(30, 15));
|
lowCpCoeffs[0] = stringToScalar(thermoCoeffString.substr(30, 15));
|
||||||
lowCpCoeffs[1] = stringToScalar(thermoCoeffString(45, 15));
|
lowCpCoeffs[1] = stringToScalar(thermoCoeffString.substr(45, 15));
|
||||||
lowCpCoeffs[2] = stringToScalar(thermoCoeffString(60, 15));
|
lowCpCoeffs[2] = stringToScalar(thermoCoeffString.substr(60, 15));
|
||||||
|
|
||||||
BEGIN(readThermoLineLabel3);
|
BEGIN(readThermoLineLabel3);
|
||||||
}
|
}
|
||||||
@ -603,10 +603,10 @@ bool finishReaction = false;
|
|||||||
<readThermoCoeff3>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
|
<readThermoCoeff3>{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff}{thermoCoeff} {
|
||||||
string thermoCoeffString(YYText());
|
string thermoCoeffString(YYText());
|
||||||
|
|
||||||
lowCpCoeffs[3] = stringToScalar(thermoCoeffString(0, 15));
|
lowCpCoeffs[3] = stringToScalar(thermoCoeffString.substr(0, 15));
|
||||||
lowCpCoeffs[4] = stringToScalar(thermoCoeffString(15, 15));
|
lowCpCoeffs[4] = stringToScalar(thermoCoeffString.substr(15, 15));
|
||||||
lowCpCoeffs[5] = stringToScalar(thermoCoeffString(30, 15));
|
lowCpCoeffs[5] = stringToScalar(thermoCoeffString.substr(30, 15));
|
||||||
lowCpCoeffs[6] = stringToScalar(thermoCoeffString(45, 15));
|
lowCpCoeffs[6] = stringToScalar(thermoCoeffString.substr(45, 15));
|
||||||
|
|
||||||
BEGIN(readThermoLineLabel4);
|
BEGIN(readThermoLineLabel4);
|
||||||
}
|
}
|
||||||
@ -1327,11 +1327,10 @@ bool finishReaction = false;
|
|||||||
|
|
||||||
<readPDependentSpecie>{pDependentSpecie} {
|
<readPDependentSpecie>{pDependentSpecie} {
|
||||||
|
|
||||||
word rhsPDependentSpecieName = pDependentSpecieName;
|
const word rhsPDependentSpecieName = pDependentSpecieName;
|
||||||
pDependentSpecieName =
|
pDependentSpecieName =
|
||||||
foamName(foamSpecieString(YYText()));
|
foamName(foamSpecieString(YYText()));
|
||||||
pDependentSpecieName =
|
pDependentSpecieName.resize(pDependentSpecieName.size()-1);
|
||||||
pDependentSpecieName(0, pDependentSpecieName.size() - 1);
|
|
||||||
|
|
||||||
if (rrType == thirdBodyArrhenius)
|
if (rrType == thirdBodyArrhenius)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -211,17 +211,12 @@ Foam::Reaction<ReactionThermo>::specieCoeffs::specieCoeffs
|
|||||||
{
|
{
|
||||||
word specieName = t.wordToken();
|
word specieName = t.wordToken();
|
||||||
|
|
||||||
size_t i = specieName.find('^');
|
const size_t i = specieName.find('^');
|
||||||
|
|
||||||
if (i != word::npos)
|
if (i != word::npos)
|
||||||
{
|
{
|
||||||
string exponentStr = specieName
|
exponent = atof(specieName.substr(i + 1).c_str());
|
||||||
(
|
specieName.resize(i);
|
||||||
i + 1,
|
|
||||||
specieName.size() - i - 1
|
|
||||||
);
|
|
||||||
exponent = atof(exponentStr.c_str());
|
|
||||||
specieName = specieName(0, i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (species.contains(specieName))
|
if (species.contains(specieName))
|
||||||
|
|||||||
Reference in New Issue
Block a user