NeBuild dev
Loading...
Searching...
No Matches
source_position Struct Reference

A source document line-and-column pair. More...

#include <source_region.hpp>

Public Member Functions

TOML_PURE_GETTER constexpr operator bool () const noexcept
 Returns true if both line and column numbers are non-zero.
 

Public Attributes

source_index line
 The line number.
 
source_index column
 The column number.
 

Friends

TOML_PURE_GETTER friend constexpr bool operator== (const source_position &lhs, const source_position &rhs) noexcept
 Equality operator.
 
TOML_PURE_INLINE_GETTER friend constexpr bool operator!= (const source_position &lhs, const source_position &rhs) noexcept
 Inequality operator.
 
TOML_PURE_GETTER friend constexpr bool operator< (const source_position &lhs, const source_position &rhs) noexcept
 Less-than operator.
 
TOML_PURE_GETTER friend constexpr bool operator<= (const source_position &lhs, const source_position &rhs) noexcept
 Less-than-or-equal-to operator.
 
TOML_PURE_GETTER friend constexpr bool operator> (const source_position &lhs, const source_position &rhs) noexcept
 Greater-than operator.
 
TOML_PURE_GETTER friend constexpr bool operator>= (const source_position &lhs, const source_position &rhs) noexcept
 Greater-than-or-equal-to operator.
 
std::ostream & operator<< (std::ostream &lhs, const source_position &rhs)
 Prints a source_position to a stream.
 

Detailed Description

A source document line-and-column pair.

\detail \cpp auto table = toml::parse_file("config.toml"sv); std::cout << "The node 'description' was defined at "sv << table.get("description")->source().begin() << "\n"; \ecpp

\out The value 'description' was defined at line 7, column 15 \eout

Remarks
toml++'s parser is unicode-aware insofar as it knows how to handle non-ASCII whitespace and newline characters, but it doesn't give much thought to combining marks, grapheme clusters vs. characters, et cetera. If a TOML document contains lots of codepoints outside of the ASCII range you may find that your source_positions don't match those given by a text editor (typically the line numbers will be accurate but column numbers will be too high). This is not an error. I've chosen this behaviour as a deliberate trade-off between parser complexity and correctness.

Member Function Documentation

◆ operator bool()

TOML_PURE_GETTER constexpr source_position::operator bool ( ) const
inlineexplicitconstexprnoexcept

Returns true if both line and column numbers are non-zero.

Friends And Related Symbol Documentation

◆ operator!=

TOML_PURE_INLINE_GETTER friend constexpr bool operator!= ( const source_position lhs,
const source_position rhs 
)
friend

Inequality operator.

◆ operator<

TOML_PURE_GETTER friend constexpr bool operator< ( const source_position lhs,
const source_position rhs 
)
friend

Less-than operator.

◆ operator<<

std::ostream & operator<< ( std::ostream &  lhs,
const source_position rhs 
)
friend

Prints a source_position to a stream.

\detail \cpp auto tbl = toml::parse("bar = 42"sv);

std::cout << "The value for 'bar' was found on "sv << tbl.get("bar")->source().begin() << "\n"; \ecpp

\out The value for 'bar' was found on line 1, column 7 \eout

Parameters
lhsThe stream.
rhsThe source_position.
Returns
The input stream.

◆ operator<=

TOML_PURE_GETTER friend constexpr bool operator<= ( const source_position lhs,
const source_position rhs 
)
friend

Less-than-or-equal-to operator.

◆ operator==

TOML_PURE_GETTER friend constexpr bool operator== ( const source_position lhs,
const source_position rhs 
)
friend

Equality operator.

◆ operator>

TOML_PURE_GETTER friend constexpr bool operator> ( const source_position lhs,
const source_position rhs 
)
friend

Greater-than operator.

◆ operator>=

TOML_PURE_GETTER friend constexpr bool operator>= ( const source_position lhs,
const source_position rhs 
)
friend

Greater-than-or-equal-to operator.

Member Data Documentation

◆ column

source_index source_position::column

The column number.

Remarks
Valid column numbers start at 1.

◆ line

source_index source_position::line

The line number.

Remarks
Valid line numbers start at 1.

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