xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
xtd::io::text_reader Class Reference

#include <text_reader.h>

Definition

Represents a reader that can read a sequential series of characters.

Namespace
xtd::io
Library
xtd.core

Public Member Functions

virtual void close ()
 Closes the xtd::io::text_reader and releases any system resources associated with the text_reader. More...
 
virtual int32_t peek () const
 Reads the next character without changing the state of the reader or the character source. Returns the next available character without actually reading it from the input stream. More...
 
virtual int32_t read ()
 Reads the next character from the input stream and advances the character position by one character. More...
 
virtual size_t read (std::vector< char > &buffer, size_t index, size_t count)
 Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index. More...
 
virtual size_t read_block (std::vector< char > &buffer, size_t index, size_t count)
 Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index. More...
 
virtual xtd::ustring read_line ()
 Reads a line of characters from the current stream and returns the data as a string. More...
 
virtual xtd::ustring read_to_end ()
 Reads all characters from the current position to the end of the text_reader and returns them as one string. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object. More...
 

Static Public Member Functions

static null_text_readernull () noexcept
 Provides a text_reader with no data to read from. More...
 
static synchronized_text_reader synchronised (text_reader &reader) noexcept
 Creates a thread-safe (synchronized) wrapper around the specified text_reader object. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Protected Member Functions

 text_reader ()=default
 Initializes a new instance of the xtd::io::text_reader class. More...
 

Constructor & Destructor Documentation

◆ text_reader()

xtd::io::text_reader::text_reader ( )
protecteddefault

Initializes a new instance of the xtd::io::text_reader class.

Member Function Documentation

◆ close()

virtual void xtd::io::text_reader::close ( )
virtual

Closes the xtd::io::text_reader and releases any system resources associated with the text_reader.

Reimplemented in xtd::io::stream_reader.

◆ null()

static null_text_reader& xtd::io::text_reader::null ( )
staticnoexcept

Provides a text_reader with no data to read from.

Remarks
Reading from the null text reader is similar to reading from the end of a stream:
read and peek methods return EOF.
read_block method returns zero.
read_line and read_to_end methods return a string Empty.

◆ peek()

virtual int32_t xtd::io::text_reader::peek ( ) const
virtual

Reads the next character without changing the state of the reader or the character source. Returns the next available character without actually reading it from the input stream.

Returns
An integer representing the next character to be read, or EOF if no more characters are available or the stream does not support seeking.

Reimplemented in xtd::io::stream_reader, and xtd::io::string_reader.

◆ read() [1/2]

virtual int32_t xtd::io::text_reader::read ( )
virtual

Reads the next character from the input stream and advances the character position by one character.

Returns
The next character from the input stream, or EOF if no more characters are available.

Reimplemented in xtd::io::synchronized_text_reader, xtd::io::null_text_reader, xtd::io::stream_reader, and xtd::io::string_reader.

◆ read() [2/2]

virtual size_t xtd::io::text_reader::read ( std::vector< char > &  buffer,
size_t  index,
size_t  count 
)
virtual

Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.

Parameters
bufferWhen this method returns, this parameter contains the specified character array with the values between index and (index + count -1) replaced by the characters read from the current source.
indexThe position in buffer at which to begin writing.
countThe maximum number of characters to read.
Returns
The number of characters that have been read. The number will be less than or equal to count, depending on whether all input characters have been read.

◆ read_block()

virtual size_t xtd::io::text_reader::read_block ( std::vector< char > &  buffer,
size_t  index,
size_t  count 
)
virtual

Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.

Parameters
bufferWhen this method returns, this parameter contains the specified character array with the values between index and (index + count -1) replaced by the characters read from the current source.
indexThe position in buffer at which to begin writing.
countThe maximum number of characters to read.
Returns
The number of characters that have been read. The number will be less than or equal to count, depending on whether all input characters have been read.

◆ read_line()

virtual xtd::ustring xtd::io::text_reader::read_line ( )
virtual

Reads a line of characters from the current stream and returns the data as a string.

Returns
The next line from the input stream, or the empty string if all characters have been read.

◆ read_to_end()

virtual xtd::ustring xtd::io::text_reader::read_to_end ( )
virtual

Reads all characters from the current position to the end of the text_reader and returns them as one string.

Returns
A string containing all characters from the current position to the end of the text_reader.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ synchronised()

static synchronized_text_reader xtd::io::text_reader::synchronised ( text_reader reader)
staticnoexcept

Creates a thread-safe (synchronized) wrapper around the specified text_reader object.

Parameters
readerThe text_reader object to synchronize.
Returns
text_reader A thread-safe text_reader object.

The documentation for this class was generated from the following file: