Pretty Diagnostics
Create your own pretty diagnostics
Loading...
Searching...
No Matches
pretty_diagnostics::StringSource Class Reference

A Source implementation that reads from an in-memory string. More...

#include <source.hpp>

Inheritance diagram for pretty_diagnostics::StringSource:
[legend]

Public Member Functions

 StringSource (std::string contents, std::string display_path="<memory>")
 Creates a string source with an optional display path. More...
 
Location from_coords (size_t row, size_t column) const override
 Maps (row, column) to a Location within the string. More...
 
Location from_index (size_t index) const override
 Maps an absolute index to a Location within the string. More...
 
std::string substr (const Location &start, const Location &end) const override
 Extracts a substring delimited by two locations. More...
 
std::string line (const Location &location) const override
 Returns the contents of the line containing the given location. More...
 
std::string line (size_t line_number) const override
 Returns the contents of the specified line number. More...
 
size_t line_count () const override
 Returns the total number of lines in the string. More...
 
const std::string & contents () const override
 Returns the entire contents of the source. More...
 
std::string path () const override
 Returns a displayable path or identifier of the source. More...
 
size_t size () const override
 Returns the total size (in characters) of the source. More...
 
- Public Member Functions inherited from pretty_diagnostics::Source
virtual ~Source ()=default
 
virtual Location from_coords (size_t row, size_t column) const =0
 Returns a location corresponding to the given row and column. More...
 
virtual Location from_index (size_t index) const =0
 Returns a location for the given absolute character index. More...
 
virtual std::string substr (const Location &start, const Location &end) const =0
 Returns the substring between two locations. More...
 
virtual std::string line (const Location &location) const =0
 Returns the full line at the given location. More...
 
virtual std::string line (size_t line_number) const =0
 Returns the contents of the specified line number. More...
 
virtual size_t line_count () const =0
 Returns the total number of lines in the source. More...
 
virtual const std::string & contents () const =0
 Returns the entire contents of the source. More...
 
virtual std::string path () const =0
 Returns a displayable path or identifier of the source. More...
 
virtual size_t size () const =0
 Returns the total size (in characters) of the source. More...
 

Detailed Description

A Source implementation that reads from an in-memory string.

Constructor & Destructor Documentation

◆ StringSource()

pretty_diagnostics::StringSource::StringSource ( std::string  contents,
std::string  display_path = "<memory>" 
)
explicit

Creates a string source with an optional display path.

Parameters
contentsSource contents held in memory
display_pathOptional display identifier for diagnostics output

Member Function Documentation

◆ contents()

const std::string & pretty_diagnostics::StringSource::contents ( ) const
overridevirtual

Returns the entire contents of the source.

Returns
Full source contents

Implements pretty_diagnostics::Source.

◆ from_coords()

Location pretty_diagnostics::StringSource::from_coords ( size_t  row,
size_t  column 
) const
overridevirtual

Maps (row, column) to a Location within the string.

Parameters
row0-based line number
column0-based column number
Returns
Location corresponding to the given coordinates

Implements pretty_diagnostics::Source.

◆ from_index()

Location pretty_diagnostics::StringSource::from_index ( size_t  index) const
overridevirtual

Maps an absolute index to a Location within the string.

Parameters
index0-based absolute character index
Returns
Location corresponding to the given index

Implements pretty_diagnostics::Source.

◆ line() [1/2]

std::string pretty_diagnostics::StringSource::line ( const Location location) const
overridevirtual

Returns the contents of the line containing the given location.

Parameters
locationA location within the desired line
Returns
The entire line contents without a trailing newline

Implements pretty_diagnostics::Source.

◆ line() [2/2]

std::string pretty_diagnostics::StringSource::line ( size_t  line_number) const
overridevirtual

Returns the contents of the specified line number.

Parameters
line_number0-based line number
Returns
The entire line contents without a trailing newline

Implements pretty_diagnostics::Source.

◆ line_count()

size_t pretty_diagnostics::StringSource::line_count ( ) const
overridevirtual

Returns the total number of lines in the string.

Returns
Line count

Implements pretty_diagnostics::Source.

◆ path()

std::string pretty_diagnostics::StringSource::path ( ) const
overridevirtual

Returns a displayable path or identifier of the source.

Returns
Display path or identifier

Implements pretty_diagnostics::Source.

◆ size()

size_t pretty_diagnostics::StringSource::size ( ) const
overridevirtual

Returns the total size (in characters) of the source.

Returns
Size in characters

Implements pretty_diagnostics::Source.

◆ substr()

std::string pretty_diagnostics::StringSource::substr ( const Location start,
const Location end 
) const
overridevirtual

Extracts a substring delimited by two locations.

Parameters
startInclusive start location
endExclusive end location
Returns
Substring between start and end

Implements pretty_diagnostics::Source.


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