Streams.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_UTIL__STREAMS
18 #define COM_BORA_SOFTWARE__BALAU_UTIL__STREAMS
19 
20 #include <Balau/Type/StdTypes.hpp>
21 
22 #include <iostream>
23 #include <sstream>
24 
26 
30 template <typename AllocatorT>
31 inline Balau::U8String<AllocatorT> toString(std::istream & inputStream) {
32  std::istreambuf_iterator<char> eof;
33  return Balau::U8String<AllocatorT>(std::istreambuf_iterator<char>(inputStream), eof);
34 }
35 
39 inline std::string toString(std::istream & inputStream) {
40  std::istreambuf_iterator<char> eof;
41  return std::string(std::istreambuf_iterator<char>(inputStream), eof);
42 }
43 
47 template <typename AllocatorT>
48 inline Balau::U32String<AllocatorT> toString32(std::u32istream & inputStream) {
49  std::istreambuf_iterator<char32_t> eof;
50  return Balau::U32String<AllocatorT>(std::istreambuf_iterator<char32_t>(inputStream), eof);
51 }
52 
56 inline std::u32string toString32(std::u32istream & inputStream) {
57  std::istreambuf_iterator<char32_t> eof;
58  return std::u32string(std::istreambuf_iterator<char32_t>(inputStream), eof);
59 }
60 
61 namespace Balau::Util {
62 
66 class Streams final {
70  public: static std::vector<std::string> readLinesToVector(std::istream & inputStream) {
71  std::vector<std::string> lines;
72  std::string s;
73 
74  while (std::getline(inputStream, s)) {
75  lines.push_back(s);
76  }
77 
78  return lines;
79  }
80 
85  public: static void consume(std::ostream & dst, std::istream & src) {
86  dst << src.rdbuf();
87  }
88 
90 
91  Streams() = delete;
92  Streams(const Streams &) = delete;
93  Streams & operator = (const Streams &) = delete;
94 };
95 
96 } // namespace Balau::Util
97 
98 #endif // COM_BORA_SOFTWARE__BALAU_UTIL__STREAMS
Utility functions.
static std::vector< std::string > readLinesToVector(std::istream &inputStream)
Read all lines of text from the supplied input stream into a vector.
Definition: Streams.hpp:70
static void consume(std::ostream &dst, std::istream &src)
Consume all the data from the supplied input stream into the supplied output stream.
Definition: Streams.hpp:85
Utilities for streams.
Definition: Streams.hpp:66
Core includes, typedefs and functions.
std::basic_string< char32_t, std::char_traits< char32_t >, AllocatorT > U32String
UTF-32 string type with selectable allocator.
Definition: ToStringA.hpp:53
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
Balau::U32String< AllocatorT > toString32(std::u32istream &inputStream)
Read all the text into a UTF-32 string from the supplied UTF-32 input stream.
Definition: Streams.hpp:48
Balau::U8String< AllocatorT > toString(std::istream &inputStream)
Read all the text into a UTF-8 string from the supplied UTF-8 input stream.
Definition: Streams.hpp:31