0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-02 21:59:02 +02:00

ircd::util: Abstract stringstream utils into template; add view hack.

This commit is contained in:
Jason Volk 2018-03-25 23:15:26 -07:00
parent e4194e3589
commit 15c65924ee

View file

@ -219,8 +219,18 @@ operator!(const std::string_view &str)
// stringstream buffer set macros // stringstream buffer set macros
// //
inline std::string & template<class stringstream>
pubsetbuf(std::stringstream &ss, stringstream &
pubsetbuf(stringstream &ss,
const mutable_buffer &buf)
{
ss.rdbuf()->pubsetbuf(data(buf), size(buf));
return ss;
}
template<class stringstream>
stringstream &
pubsetbuf(stringstream &ss,
std::string &s) std::string &s)
{ {
auto *const &data auto *const &data
@ -229,11 +239,12 @@ pubsetbuf(std::stringstream &ss,
}; };
ss.rdbuf()->pubsetbuf(data, s.size()); ss.rdbuf()->pubsetbuf(data, s.size());
return s; return ss;
} }
inline std::string & template<class stringstream>
pubsetbuf(std::stringstream &ss, stringstream &
pubsetbuf(stringstream &ss,
std::string &s, std::string &s,
const size_t &size) const size_t &size)
{ {
@ -241,12 +252,28 @@ pubsetbuf(std::stringstream &ss,
return pubsetbuf(ss, s); return pubsetbuf(ss, s);
} }
inline std::string & template<class stringstream>
resizebuf(std::stringstream &ss, stringstream &
resizebuf(stringstream &ss,
std::string &s) std::string &s)
{ {
s.resize(ss.tellp()); s.resize(ss.tellp());
return s; return ss;
}
/// buf has to match the rdbuf you gave the stringstream
template<class stringstream>
string_view
view(stringstream &ss,
const const_buffer &buf)
{
assert(size_t(ss.tellp()) <= size(buf));
ss.flush();
ss.rdbuf()->pubsync();
return
{
data(buf), size_t(ss.tellp())
};
} }
// //