Defined in header <cparse/Cursor.hh>

stream_type::char_type safeGet() noexcept;

Same as get() but catches every exception and returns the EOF sentinel '\032' (^Z, ASCII SUB) if the stream cannot be read.

Line and column counters are updated before the read attempt, and are updated even on the read that returns the sentinel — the caller must check the return value to know whether a real character was consumed.

If the internal stream pointer is null, returns '\032' immediately without touching the counters.

Parameters

None.

Return value

The consumed character on success. '\032' if the stream cannot be read (null stream, exception from stream->get(), or bad/fail state).

Exceptions

noexcept. All exceptions from the underlying stream are caught and translated to the sentinel return value.

Notes

The EOF sentinel value is '\032' (ASCII SUB, ^Z), chosen because it is a control character with no meaningful role in any text-based grammar. If your grammar could legitimately contain '\032' bytes, use isValid() in your loop condition or fall back to the throwing get() wrapped in a try block.

Example

#include <cparse/Cursor.hh>
#include <cctype>
#include <sstream>

int main()
{
    auto ss = std::make_shared<std::istringstream>("42abc");
    fedem::parser::Cursor c("<memory>", ss);

    std::string digits;
    while (std::isdigit(static_cast<unsigned char>(c.safePeek())))
        digits += c.safeGet();

    // digits == "42"; c now positioned at 'a'
}

See also