8 #ifndef MOD_SERVLET_IO_STRING_H
9 #define MOD_SERVLET_IO_STRING_H
25 template<
typename CharT,
typename Traits = std::
char_traits<CharT>>
43 string_sink(std::size_t max_size = std::string::npos) : _max_size{max_size} {}
52 std::streamsize
write(
const CharT* s, std::streamsize n)
54 if (_max_size <= _chars_written)
return 0;
55 if (_chars_written + n > _max_size)
57 std::streamsize ln = _max_size - _chars_written;
58 _buffer.append(s, ln);
59 _chars_written = _max_size;
69 void flush() { _flushed =
true; }
74 void reset() { _buffer.clear(); _flushed =
false; _chars_written = 0; }
99 std::size_t _max_size;
100 std::size_t _chars_written = 0;
101 bool _flushed =
false;
107 template<
typename CharT,
typename Traits = std::
char_traits<CharT>>
108 using basic_inplace_ostream = basic_outstream<string_sink<CharT, Traits>, non_buffered, CharT, Traits>;
112 typedef basic_inplace_ostream<char> inplace_ostream;
116 #endif //MOD_SERVLET_IO_STRING_H
string_type & str()
Returns the reference to the destination std::string
Definition: io_string.h:84
std::streamsize write(const CharT *s, std::streamsize n)
Writes first n character from the array s into destination string
Definition: io_string.h:52
std::basic_string< CharT, Traits > string_type
Type of the underlying string.
Definition: io_string.h:32
string_view_type view() const
Returns string_view to the destination std::string
Definition: io_string.h:79
bool was_flushed() const
Return flag which indicates whether this sink was flushed since last reset.
Definition: io_string.h:89
Definitions for custom implementation of std::istream and std::ostream objects.
string_sink(std::size_t max_size=std::string::npos)
Constructs object with optional argument to specify maximum size of the destination string_type...
Definition: io_string.h:43
Implementation of sink to std::string Besides to having similar functionality to std::basic_ostringst...
Definition: io_string.h:26
std::experimental::basic_string_view< CharT, Traits > string_view_type
string_view for string_type
Definition: io_string.h:36
void reset()
Resets the sink.
Definition: io_string.h:74
std::size_t characters_written() const
Return the number of character which were written into this sink since last reset.
Definition: io_string.h:95
void flush()
Sets flushed flag to true
Definition: io_string.h:69