Commit ba695052 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: add ITstream::toString() method

- creates a std::string with space-delimited tokens, which can be sent
  to another application or even re-parsed into tokens
parent 771410e5
......@@ -67,6 +67,14 @@ int main(int argc, char *argv[])
dictionary dict(is);
Info<< dict << endl;
for (const entry& e : dict)
{
if (e.isStream())
{
Info<< e.keyword() << " :: "
<< e.stream().toString() << nl;
}
}
}
}
......
......@@ -27,6 +27,7 @@ License
#include "error.H"
#include "ITstream.H"
#include "StringStream.H"
#include "UIListStream.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
......@@ -187,6 +188,28 @@ void Foam::ITstream::print(Ostream& os) const
}
std::string Foam::ITstream::toString() const
{
OStringStream buf;
const tokenList& tokens = *this;
label len = tokens.size();
for (const token& tok : tokens)
{
buf << tok;
if (--len)
{
buf << ' ';
}
}
return buf.str();
}
Foam::Istream& Foam::ITstream::read(token& tok)
{
// Return the put back token if it exists
......
......@@ -192,7 +192,7 @@ public:
);
// Member functions
// Member Functions
// Inquiry
......@@ -233,7 +233,7 @@ public:
}
// Read functions
// Read Functions
//- Return next token from stream
virtual Istream& read(token& tok);
......@@ -289,10 +289,14 @@ public:
}
// Print
// Output
//- Print description of stream to Ostream
void print(Ostream& os) const;
//- Concatenate tokens into a space-separated std::string.
//- The resulting string may contain quote characters.
std::string toString() const;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment