parse-integer

xod/stream/parse-integer

Read an integer number from a stream of characters. Stop when a non-numeric character was encountered
parse-integer
@/parse-integer
Read an integer number from a stream of characters. Stop when a non-numeric character was encountered
CHARbyte
The next character to be processed
PUSHpulse
Push a new character to process
RSTpulse
Reset the parsed number to 0 and start over
parse-integer
NUM
END
CHAR
PUSH
RST
ENDpulse
Pulses when the non-numerical character was encountered
NUMnumber
The resulting integer

C++ implementation

node {
    Number n = 0;
    bool isDone = false;

    void evaluate(Context ctx) {
        if (isInputDirty<input_RST>(ctx)) {
            isDone = false;
            n = 0;
        }

        if (!isInputDirty<input_PUSH>(ctx) || isDone)
            return;

        auto c = getValue<input_CHAR>(ctx);
        if (c >= '0' && c <= '9') {
            n *= 10;
            n += c - '0';
        } else {
            isDone = true;
            emitValue<output_END>(ctx, 1);
        }

        emitValue<output_NUM>(ctx, n);
    }
}