C++ Utilities
Loading...
Searching...
No Matches
Stream Utilities

The <utilities/stream.h> header provides utility functions for streams.

Readers

The functions differ from std::getline in a few ways:

  1. They ignore blank lines in the input stream.
  2. They allow for long lines by assuming that lines that end with a "\\" continue to the next. 3. They strip out comment lines and trailing comments where comment lines begin with "#" by default. @icode{c++} std::string utilities::read_line(std::istream &s, std::string_view comment_begin = "#"); @endicode reads a "line" from a stream and returns that as a string. @icode{c++} std::size_t utilities::read_line(std::istream &s, std::string &line, std::string_view comment_begin = "#"); @endicode overwrites the 'line' argument with the contents of a stream and returns the number of characters read into 'line’. @section other-functions Other Functions We supply a method that rewinds an input stream to the start. @icode{c++} std::istream & rewind(std::istream &is); @endicode and another that returns the number of non-comment lines in the stream. @icode{c++} std::size_t line_count(std::istream &is, std::string_view comment_begin = "#"); @endicode If the <tt>comment_begin</tt> argument is empty, <tt>line_count</tt> uses <a href="https://en.cppreference.com/w/cpp/string/basic_string/getline" >std::getline

to read the lines. Otherwise, we use our read_line(...) function, so comment lines are excluded, etc.

Warning
These two functions only work with file streams, etc.