Repository: microsoft/terminal
File: src/terminal/parser/stateMachine.cpp (C++)

Code before:
    {
        // _pwchCurr is incremented after a call to ProcessCharacter to indicate
        //      that pwchCurr was processed.
        // However, if we're here, then the processing of pwchChar triggered the
        //      engine to request the entire sequence get passed through, including pwchCurr.
        _ActuateCurrentRun();
        success = _engine->ActionPassThroughString(_run);
    }

    return success;
}

// Routine Description:
// - Helper for entry to the state machine. Will take an array of characters
//     and print as many as it can without encountering a character indicating
//     a escape sequence, then feed characters into the state machine one at a
//     time until we return to the ground state.
// Arguments:
// - string - Characters to operate upon
// Return Value:
// - <none>
void StateMachine::ProcessString(const std::wstring_view string)
{
    size_t start = 0;
    size_t current = start;

    _currentString = string;
    _runOffset = 0;
    _runSize = 0;

    while (current < string.size())
    {
        // The run will be everything from the start INCLUDING the current one
        // in case we process the current character and it turns into a passthrough
        // fallback that picks up this _run inside `FlushToTerminal` above.
        _runOffset = start;
        _runSize = current - start + 1;

        if (_processingIndividually)
        {
            // If we're processing characters individually, send it to the state machine.
            ProcessCharacter(string.at(current));
            ++current;
            if (_state == VTStates::Ground) // Then check if we're back at ground. If we are, the next character (pwchCurr)
            { //   is the start of the next run of characters that might be printable.
                _processingIndividually = false;
                start = current;
            }
        }
        else
        {

Review comment (suggestion):
Do I need to reset these in `_EnterGround` ? Feels like I should.

Code after:
    {
        // _pwchCurr is incremented after a call to ProcessCharacter to indicate
        //      that pwchCurr was processed.
        // However, if we're here, then the processing of pwchChar triggered the
        //      engine to request the entire sequence get passed through, including pwchCurr.
        success = _engine->ActionPassThroughString(_CurrentRun());
    }

    return success;
}

// Routine Description:
// - Helper for entry to the state machine. Will take an array of characters
//     and print as many as it can without encountering a character indicating
//     a escape sequence, then feed characters into the state machine one at a
//     time until we return to the ground state.
// Arguments:
// - string - Characters to operate upon
// Return Value:
// - <none>
void StateMachine::ProcessString(const std::wstring_view string)
{
    size_t start = 0;
    size_t current = start;

    _currentString = string;
    _runOffset = 0;
    _runSize = 0;

    while (current < string.size())
    {
        // The run will be everything from the start INCLUDING the current one
        // in case we process the current character and it turns into a passthrough
        // fallback that picks up this _run inside `FlushToTerminal` above.
        _runOffset = start;
        _runSize = current - start + 1;

        if (_processingIndividually)
        {
            // If we're processing characters individually, send it to the state machine.
            ProcessCharacter(til::at(string, current));
            ++current;
            if (_state == VTStates::Ground) // Then check if we're back at ground. If we are, the next character (pwchCurr)
            { //   is the start of the next run of characters that might be printable.
                _processingIndividually = false;
                start = current;
            }
        }
        else
        {
            if (_isActionableFromGround(til::at(string, current))) // If the current char is the start of an escape sequence, or should be executed in ground state...