FE 0.15.0
A C++23 toolkit for writing compiler/interpreter frontends.
Loading...
Searching...
No Matches
fe::Src Class Reference

The content of one source file together with the offsets its rows start at. More...

#include <fe/src.h>

Public Member Functions

 Src (std::filesystem::path path, std::string buf)
Getters
const std::filesystem::path & path () const
std::string_view buf () const
uint32_t num_rows () const
 The number of rows the file actually has.
Pos begin () const
Pos end () const
bool contains (Pos pos) const
Resolve a Pos
std::pair< uint32_t, uint32_t > rowcol (Pos pos) const
uint32_t row (Pos pos) const
uint32_t col (Pos pos) const
std::string_view line (uint32_t row) const
 Text of the 1-based row without its line terminator - or a leading utf8::Bom; empty if row is out of range.
Pos prev (Pos pos) const
 Start of the last code point before pos - the character a half-open Loc::end points past.

Detailed Description

The content of one source file together with the offsets its rows start at.

This is what turns a Pos back into the row/column a human wants to read.

Definition at line 40 of file src.h.

Constructor & Destructor Documentation

◆ Src()

fe::Src::Src ( std::filesystem::path path,
std::string buf )

References buf(), and path().

Member Function Documentation

◆ begin()

Pos fe::Src::begin ( ) const
inline

Definition at line 51 of file src.h.

References fe::Pos::Pos().

◆ buf()

std::string_view fe::Src::buf ( ) const
inline

Definition at line 47 of file src.h.

Referenced by Src().

◆ col()

uint32_t fe::Src::col ( Pos pos) const
inline

Definition at line 64 of file src.h.

References rowcol().

◆ contains()

bool fe::Src::contains ( Pos pos) const
inline

Definition at line 53 of file src.h.

References fe::Pos::off.

◆ end()

Pos fe::Src::end ( ) const
inline

Definition at line 52 of file src.h.

References fe::Pos::Pos().

◆ line()

std::string_view fe::Src::line ( uint32_t row) const

Text of the 1-based row without its line terminator - or a leading utf8::Bom; empty if row is out of range.

References row().

◆ num_rows()

uint32_t fe::Src::num_rows ( ) const

The number of rows the file actually has.

Note
A trailing line terminator does not open one more, empty row - it ends the last one.

◆ path()

const std::filesystem::path & fe::Src::path ( ) const
inline

Definition at line 46 of file src.h.

Referenced by Src().

◆ prev()

Pos fe::Src::prev ( Pos pos) const

Start of the last code point before pos - the character a half-open Loc::end points past.

◆ row()

uint32_t fe::Src::row ( Pos pos) const
inline

Definition at line 63 of file src.h.

References rowcol().

Referenced by line().

◆ rowcol()

std::pair< uint32_t, uint32_t > fe::Src::rowcol ( Pos pos) const

1-based row and column pos sits at, or {0, 0} if pos does not belong to this file. The column counts code points, not bytes, and a leading utf8::Bom occupies none.

Note
Never names a row Src::num_rows does not count - see there.

Referenced by col(), and row().


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