mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use updated ITstream for parsing strings to token lists
This commit is contained in:
@ -28,7 +28,6 @@ License
|
|||||||
#include "dictionaryEntry.H"
|
#include "dictionaryEntry.H"
|
||||||
#include "regExp.H"
|
#include "regExp.H"
|
||||||
#include "OSHA1stream.H"
|
#include "OSHA1stream.H"
|
||||||
#include "DynamicList.H"
|
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
|
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
|
||||||
|
|
||||||
@ -214,22 +213,20 @@ Foam::SHA1Digest Foam::dictionary::digest() const
|
|||||||
|
|
||||||
Foam::tokenList Foam::dictionary::tokens() const
|
Foam::tokenList Foam::dictionary::tokens() const
|
||||||
{
|
{
|
||||||
// Serialize dictionary into a string
|
// Serialize dictionary entries into a string
|
||||||
OStringStream os;
|
OStringStream os;
|
||||||
write(os, false);
|
|
||||||
|
|
||||||
IStringStream is(os.str());
|
// Process entries
|
||||||
|
forAllConstIter(parent_type, *this, iter)
|
||||||
DynamicList<token> tokens;
|
|
||||||
|
|
||||||
// Parse string as tokens
|
|
||||||
token tok;
|
|
||||||
while (is.read(tok))
|
|
||||||
{
|
{
|
||||||
tokens.append(std::move(tok));
|
os << *iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokenList(tokens.xfer());
|
// String re-parsed as a list of tokens
|
||||||
|
return static_cast<tokenList>
|
||||||
|
(
|
||||||
|
ITstream("tokens", os.str(), os.format(), os.version())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -30,24 +30,23 @@ License
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::primitiveEntry::appendTokenList(const UList<token>& varTokens)
|
void Foam::primitiveEntry::appendTokenList(const UList<token>& toks)
|
||||||
{
|
{
|
||||||
for (const token& tok : varTokens)
|
for (const token& tok : toks)
|
||||||
{
|
{
|
||||||
newElmt(tokenIndex()++) = tok; // append copy
|
newElmt(tokenIndex()++) = tok; // copy append
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::primitiveEntry::appendTokensFromString(const string& input)
|
void Foam::primitiveEntry::appendTokenList(List<token>&& toks)
|
||||||
{
|
{
|
||||||
IStringStream is(input);
|
for (token& tok : toks)
|
||||||
|
|
||||||
token tok;
|
|
||||||
while (!is.read(tok).bad() && tok.good())
|
|
||||||
{
|
{
|
||||||
newElmt(tokenIndex()++) = std::move(tok);
|
newElmt(tokenIndex()++) = std::move(tok); // move append
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -97,13 +96,16 @@ bool Foam::primitiveEntry::expandVariable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split input string into a stream of tokens and append to list
|
// String parsed as a list of tokens
|
||||||
appendTokensFromString(str);
|
ITstream its("env", str);
|
||||||
|
appendTokenList(std::move(static_cast<tokenList&>(its)));
|
||||||
}
|
}
|
||||||
else if (eptr->isDict())
|
else if (eptr->isDict())
|
||||||
{
|
{
|
||||||
// Found dictionary entry
|
// Found dictionary entry
|
||||||
appendTokenList(eptr->dict().tokens());
|
|
||||||
|
tokenList toks(eptr->dict().tokens().xfer());
|
||||||
|
appendTokenList(std::move(toks));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -73,14 +73,13 @@ class primitiveEntry
|
|||||||
Istream& is
|
Istream& is
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Append the given tokens at the current tokenIndex
|
//- Copy append the given tokens at the current tokenIndex
|
||||||
// No filtering on the tokens.
|
// No filtering on the tokens.
|
||||||
void appendTokenList(const UList<token>& varTokens);
|
void appendTokenList(const UList<token>& toks);
|
||||||
|
|
||||||
//- Split input string into a stream of tokens and append at the
|
//- Move append the given tokens at the current tokenIndex
|
||||||
//- current tokenIndex.
|
|
||||||
// No filtering on the tokens.
|
// No filtering on the tokens.
|
||||||
void appendTokensFromString(const string& input);
|
void appendTokenList(List<token>&& toks);
|
||||||
|
|
||||||
|
|
||||||
//- Expand the given variable.
|
//- Expand the given variable.
|
||||||
|
|||||||
Reference in New Issue
Block a user