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

A source document region. More...

#include <source_region.hpp>

Public Member Functions

TOML_NODISCARD optional< std::wstring > wide_path () const
 The path to the corresponding source document as a wide-string.
 

Public Attributes

source_position begin
 The beginning of the region (inclusive).
 
source_position end
 The end of the region (exclusive).
 
source_path_ptr path
 The path to the corresponding source document.
 

Friends

std::ostream & operator<< (std::ostream &lhs, const source_region &rhs)
 Prints a source_region to a stream.
 

Detailed Description

A source document region.

\detail \cpp auto tbl = toml::parse_file("config.toml"sv); if (auto server = tbl.get("server")) { std::cout << "begin: "sv << server->source().begin << "\n"; std::cout << "end: "sv << server->source().end << "\n"; std::cout << "path: "sv << *server->source().path << "\n"; } \ecpp

\out begin: line 3, column 1 end: line 3, column 22 path: config.toml \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

◆ wide_path()

TOML_NODISCARD optional< std::wstring > source_region::wide_path ( ) const
inline

The path to the corresponding source document as a wide-string.

\availability This function is only available when TOML_ENABLE_WINDOWS_COMPAT is enabled.

Remarks
This will return an empty optional if no path was provided to toml::parse().

Friends And Related Symbol Documentation

◆ operator<<

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

Prints a source_region to a stream.

\detail \cpp auto tbl = toml::parse("bar = 42", "config.toml");

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

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

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

Member Data Documentation

◆ begin

source_position source_region::begin

The beginning of the region (inclusive).

◆ end

source_position source_region::end

The end of the region (exclusive).

◆ path

source_path_ptr source_region::path

The path to the corresponding source document.

Remarks
This will be nullptr if no path was provided to toml::parse().

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