Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
bertini::node::DecodingCursor Class Reference

A read position over one canonical-encoding text, with the small lexical helpers the grammar needs (literals, words, netstrings, numbers). More...

#include <canonical_decoding.hpp>

Public Member Functions

 DecodingCursor (std::string const &text)
 Start reading text from its first byte.
bool AtEnd () const
 Whether every byte has been consumed.
std::size_t Offset () const
 The byte offset of the next unread character.
char Peek () const
 The next unread character (throws at end of text).
void Expect (char c)
 Consume exactly the character c, or throw.
void Expect (std::string_view lit)
 Consume exactly the literal lit, or throw.
bool TryConsume (char c)
 Consume c if it is next; report whether it was.
void SkipWhitespace ()
 Skip any run of spaces and newlines.
std::string ReadWord ()
 Read a maximal run of characters that are not whitespace or a parenthesis.
std::string ReadNetstring ()
 Read a netstring name: <byte-length>:<bytes>.
unsigned long long ReadUnsigned ()
 Read a non-negative decimal integer.
long long ReadInt ()
 Read a decimal integer with an optional sign.
void Fail (std::string const &what) const
 Throw std::runtime_error describing what at the current position.

Detailed Description

A read position over one canonical-encoding text, with the small lexical helpers the grammar needs (literals, words, netstrings, numbers).

The cursor does not own the text: keep the string alive for the cursor's lifetime. Every helper throws std::runtime_error with the byte offset and a snippet of the text when the input does not match, so a malformed or truncated encoding fails loudly at the first wrong byte instead of producing a wrong object.

Constructor & Destructor Documentation

◆ DecodingCursor()

bertini::node::DecodingCursor::DecodingCursor ( std::string const & text)
inlineexplicit

Start reading text from its first byte.

Member Function Documentation

◆ AtEnd()

bool bertini::node::DecodingCursor::AtEnd ( ) const
inline

Whether every byte has been consumed.

◆ Expect() [1/2]

void bertini::node::DecodingCursor::Expect ( char c)

Consume exactly the character c, or throw.

◆ Expect() [2/2]

void bertini::node::DecodingCursor::Expect ( std::string_view lit)

Consume exactly the literal lit, or throw.

◆ Fail()

void bertini::node::DecodingCursor::Fail ( std::string const & what) const

Throw std::runtime_error describing what at the current position.

◆ Offset()

std::size_t bertini::node::DecodingCursor::Offset ( ) const
inline

The byte offset of the next unread character.

◆ Peek()

char bertini::node::DecodingCursor::Peek ( ) const

The next unread character (throws at end of text).

◆ ReadInt()

long long bertini::node::DecodingCursor::ReadInt ( )

Read a decimal integer with an optional sign.

◆ ReadNetstring()

std::string bertini::node::DecodingCursor::ReadNetstring ( )

Read a netstring name: <byte-length>:<bytes>.

◆ ReadUnsigned()

unsigned long long bertini::node::DecodingCursor::ReadUnsigned ( )

Read a non-negative decimal integer.

◆ ReadWord()

std::string bertini::node::DecodingCursor::ReadWord ( )

Read a maximal run of characters that are not whitespace or a parenthesis.

◆ SkipWhitespace()

void bertini::node::DecodingCursor::SkipWhitespace ( )

Skip any run of spaces and newlines.

◆ TryConsume()

bool bertini::node::DecodingCursor::TryConsume ( char c)

Consume c if it is next; report whether it was.