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

Represents a contiguous region within a Source More...

#include <span.hpp>

Public Member Functions

 Span (const std::shared_ptr< Source > &source, const Location &start, const Location &end)
 Constructs a span from explicit start and end locations within the same source. More...
 
 Span (const std::shared_ptr< Source > &source, size_t start_row, size_t start_column, size_t end_row, size_t end_column)
 Constructs a span from row/column coordinates. More...
 
 Span (const std::shared_ptr< Source > &source, size_t start_index, size_t end_index)
 Constructs a span from 0-based character indices into the source content. More...
 
Span join (const Span &other) const
 Combines this span with another span into a single continuous span. More...
 
bool intersects (const Span &other) const
 Returns true if this span intersects the other span. More...
 
std::string substr () const
 Extracts the substring of the source covered by this span. More...
 
size_t width () const
 Returns the number of characters covered by this span. More...
 
size_t line () const
 Returns the 1-based line number of the span's start. More...
 
const std::shared_ptr< Source > & source () const
 Returns the backing source of this span. More...
 
Location start () const
 Returns the starting location of the span. More...
 
Location end () const
 Returns the end location of the span. More...
 

Friends

bool operator< (const Span &lhs, const Span &rhs)
 Orders spans by their start location. More...
 
bool operator<= (const Span &lhs, const Span &rhs)
 Less-than-or-equal comparison derived from >= More...
 
bool operator> (const Span &lhs, const Span &rhs)
 Greater-than comparison derived from < More...
 
bool operator>= (const Span &lhs, const Span &rhs)
 Greater-than-or-equal comparison derived from < More...
 
bool operator== (const Span &lhs, const Span &rhs)
 Equality compares source, start and end. More...
 
bool operator!= (const Span &lhs, const Span &rhs)
 Inequality based on == More...
 

Detailed Description

Represents a contiguous region within a Source

A span is defined by start and end Locations and can be constructed from coordinates or linear indices. Spans are comparable by their start location

Constructor & Destructor Documentation

◆ Span() [1/3]

pretty_diagnostics::Span::Span ( const std::shared_ptr< Source > &  source,
const Location start,
const Location end 
)

Constructs a span from explicit start and end locations within the same source.

Parameters
sourceBacking source shared pointer
startStart location (inclusive)
endEnd location (exclusive)

◆ Span() [2/3]

pretty_diagnostics::Span::Span ( const std::shared_ptr< Source > &  source,
size_t  start_row,
size_t  start_column,
size_t  end_row,
size_t  end_column 
)

Constructs a span from row/column coordinates.

Parameters
sourceBacking source shared pointer
start_row0-based start line number
start_column0-based start column number
end_row0-based end line number
end_column0-based end column number

◆ Span() [3/3]

pretty_diagnostics::Span::Span ( const std::shared_ptr< Source > &  source,
size_t  start_index,
size_t  end_index 
)

Constructs a span from 0-based character indices into the source content.

Parameters
sourceBacking source shared pointer
start_index0-based start index (inclusive)
end_index0-based end index (exclusive)

Member Function Documentation

◆ end()

Location pretty_diagnostics::Span::end ( ) const
inline

Returns the end location of the span.

Returns
End location (exclusive)

◆ intersects()

bool pretty_diagnostics::Span::intersects ( const Span other) const

Returns true if this span intersects the other span.

Parameters
otherOther span to test against
Returns
True if the spans overlap; otherwise false

◆ join()

Span pretty_diagnostics::Span::join ( const Span other) const

Combines this span with another span into a single continuous span.

The resulting span starts at the earliest start location of the two spans and ends at the latest end location of the two spans.

Parameters
otherThe span to combine with
Returns
A new span that encompasses both spans

◆ line()

size_t pretty_diagnostics::Span::line ( ) const

Returns the 1-based line number of the span's start.

Returns
1-based start line number

◆ source()

const std::shared_ptr< Source > & pretty_diagnostics::Span::source ( ) const
inline

Returns the backing source of this span.

Returns
Shared pointer to the backing source

◆ start()

Location pretty_diagnostics::Span::start ( ) const
inline

Returns the starting location of the span.

Returns
Start location (inclusive)

◆ substr()

std::string pretty_diagnostics::Span::substr ( ) const

Extracts the substring of the source covered by this span.

Returns
The substring of the backing source covered by this span

◆ width()

size_t pretty_diagnostics::Span::width ( ) const

Returns the number of characters covered by this span.

Returns
Span width in characters

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Span lhs,
const Span rhs 
)
friend

Inequality based on ==

Parameters
lhsLeft-hand span
rhsRight-hand span
Returns
True if the spans differ

◆ operator<

bool operator< ( const Span lhs,
const Span rhs 
)
friend

Orders spans by their start location.

Parameters
lhsLeft-hand span
rhsRight-hand span
Returns
True if lhs starts before rhs

◆ operator<=

bool operator<= ( const Span lhs,
const Span rhs 
)
friend

Less-than-or-equal comparison derived from >=

Parameters
lhsLeft-hand span
rhsRight-hand span
Returns
True if lhs is not greater than rhs

◆ operator==

bool operator== ( const Span lhs,
const Span rhs 
)
friend

Equality compares source, start and end.

Parameters
lhsLeft-hand span
rhsRight-hand span
Returns
True if both spans refer to the same source and coordinates

◆ operator>

bool operator> ( const Span lhs,
const Span rhs 
)
friend

Greater-than comparison derived from <

Parameters
lhsLeft-hand span
rhsRight-hand span
Returns
True if lhs starts after rhs

◆ operator>=

bool operator>= ( const Span lhs,
const Span rhs 
)
friend

Greater-than-or-equal comparison derived from <

Parameters
lhsLeft-hand span
rhsRight-hand span
Returns
True if lhs is not less than rhs

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