FE 0.13.1
Header-only C++ frontend library
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 44 of file src.h.

Constructor & Destructor Documentation

◆ Src()

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

Definition at line 46 of file src.h.

References buf(), and path().

Member Function Documentation

◆ begin()

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

Definition at line 62 of file src.h.

References fe::Pos::Pos().

Referenced by line(), and rowcol().

◆ buf()

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

Definition at line 58 of file src.h.

Referenced by Src().

◆ col()

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

Definition at line 85 of file src.h.

References rowcol().

◆ contains()

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

Definition at line 64 of file src.h.

References fe::Pos::off.

Referenced by rowcol().

◆ end()

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

Definition at line 63 of file src.h.

References fe::Pos::Pos().

Referenced by line(), fe::SrcMap::lookup(), and prev().

◆ line()

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

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

Definition at line 89 of file src.h.

References begin(), end(), num_rows(), and row().

Referenced by rowcol().

◆ num_rows()

uint32_t fe::Src::num_rows ( ) const
inline

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.

Definition at line 61 of file src.h.

Referenced by line(), and rowcol().

◆ path()

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

Definition at line 57 of file src.h.

Referenced by Src().

◆ prev()

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

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

Definition at line 98 of file src.h.

References fe::utf8::decode(), end(), fe::utf8::is_valid234(), fe::Pos::off, and fe::Pos::Pos().

◆ row()

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

Definition at line 84 of file src.h.

References rowcol().

Referenced by line(), and rowcol().

◆ rowcol()

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

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.

Definition at line 72 of file src.h.

References begin(), contains(), line(), fe::utf8::num_code_points(), num_rows(), fe::Pos::off, and row().

Referenced by col(), and row().


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