From c7ec29b2d6a66700933ede6ae2371e1d54744d67 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 30 May 2017 19:05:43 +0300 Subject: Add ifdstream::read_text() and ifdstream::read_binary() --- libbutl/fdstream.ixx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libbutl/fdstream.ixx') diff --git a/libbutl/fdstream.ixx b/libbutl/fdstream.ixx index a877699..5181903 100644 --- a/libbutl/fdstream.ixx +++ b/libbutl/fdstream.ixx @@ -3,6 +3,7 @@ // license : MIT; see accompanying LICENSE file #include +#include namespace butl { @@ -118,6 +119,28 @@ namespace butl return buf_.release (); } + inline std::string ifdstream:: + read_text () + { + std::string s; + + // Note that the eof check is important: if the stream is at eof (empty + // file) then getline() will fail. + // + if (peek () != traits_type::eof ()) + butl::getline (*this, s, '\0'); // Hidden by istream::getline(). + + return s; + } + + inline std::vector ifdstream:: + read_binary () + { + std::vector v (std::istreambuf_iterator (*this), + std::istreambuf_iterator ()); + return v; + } + // ofdstream // inline ofdstream:: -- cgit v1.1