Defined in header <cparse/Cursor.hh>

void rewind();

Seeks the underlying stream to position zero and resets the cursor state: line is set to zero, column is set to zero, and the internal newLinePassed flag is set so that the next get() will start line one at column one.

Calls store() after seeking so the current (zero) position becomes the new saved position.

Parameters

None.

Return value

(none)

Exceptions

May throw subject to the underlying stream's exception mask. The constructors set the mask to throw on failbit | eofbit | badbit, so rewind() will throw on a seek failure or if the stream is in an error state that a seek does not clear.

Notes

rewind() performs seekg(0) directly on the stream. If the underlying stream does not support seeking — a stdin pipe, for example — the behaviour depends on the underlying istream implementation.

Useful for a second pass over the same input. Not typically used inside a parse; the store() / restore() pair is the intra-parse backtracking mechanism.

Example

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

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

    while (c.isValid())
    {
        auto ch = c.safeGet();
        if (ch == '\032') break;
        std::cout << ch;
    }
    // std::cout: "abc"

    c.rewind();
    std::cout << c.safeGet();   // 'a' again
}

See also