mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: refine SpanStream and CharStream methods
- support std::string_view (c++17) or span view (older c++) of stream
buffer contents. This simplifies formatting + reparsing.
Example,
OCharStream os;
os << ...;
ISpanStream is(os.view());
is >> ...;
- additional release() method for ICharStream, OCharStream
that returns the contents as a DynamicList<char> and resets the stream.
- provide a str() method for API compatibility with older
std::ostringstream etc.
This commit is contained in:
committed by
Andrew Heather
parent
1ddcad820f
commit
3693d61e6c
@ -39,12 +39,28 @@ Description
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
Ostream& writeList(Ostream& os, const UList<char>& list)
|
||||
Ostream& printString(Ostream& os, const char* first, const char* last)
|
||||
{
|
||||
os << '"';
|
||||
for (; first != last; (void)++first)
|
||||
{
|
||||
os << *first;
|
||||
}
|
||||
os << '"';
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
Ostream& printView(Ostream& os, const char* first, const char* last)
|
||||
{
|
||||
char buf[4];
|
||||
os << list.size() << '(';
|
||||
for (const char c : list)
|
||||
os << label(last-first) << '(';
|
||||
|
||||
for (; first != last; (void)++first)
|
||||
{
|
||||
const char c = *first;
|
||||
|
||||
if (isprint(c))
|
||||
{
|
||||
os << c;
|
||||
@ -69,29 +85,41 @@ Ostream& writeList(Ostream& os, const UList<char>& list)
|
||||
}
|
||||
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
Ostream& printView(Ostream& os, std::string_view s)
|
||||
{
|
||||
return printView(os, s.begin(), s.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Ostream& printView(Ostream& os, stdFoam::span<char> s)
|
||||
{
|
||||
return printView(os, s.begin(), s.end());
|
||||
}
|
||||
|
||||
|
||||
Ostream& printView(Ostream& os, const UList<char>& list)
|
||||
{
|
||||
return printView(os, list.begin(), list.end());
|
||||
}
|
||||
|
||||
|
||||
Ostream& writeList(Ostream& os, const UList<char>& list)
|
||||
{
|
||||
return printView(os, list.begin(), list.end());
|
||||
}
|
||||
|
||||
|
||||
Ostream& toString(Ostream& os, const UList<char>& list)
|
||||
{
|
||||
os << '"';
|
||||
for (const char c : list)
|
||||
{
|
||||
os << c;
|
||||
}
|
||||
os << '"';
|
||||
|
||||
return os;
|
||||
return printString(os, list.begin(), list.end());
|
||||
}
|
||||
|
||||
|
||||
Ostream& toString(Ostream& os, const std::vector<char>& list)
|
||||
{
|
||||
os << '"';
|
||||
for (const char c : list)
|
||||
{
|
||||
os << c;
|
||||
}
|
||||
os << '"';
|
||||
|
||||
return os;
|
||||
return printString(os, list.data(), list.data() + list.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user