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

Code before:
    _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...
            {
                _ActuateCurrentRun();
                if (!_run.empty())
                {
                    // Because the _run above is composed INCLUDING current, we must
                    // trim it off here since we just determined it's actionable
                    // and only pass through everything before it.
                    const auto allLeadingUpTo = _run.substr(0, _run.size() - 1);

                    _engine->ActionPrintString(allLeadingUpTo); // ... print all the chars leading up to it as part of the run...
                    _trace.DispatchPrintRunTrace(allLeadingUpTo);
                }

                _processingIndividually = true; // begin processing future characters individually...
                start = current;
                continue;
            }
            else
            {
                ++current; // Otherwise, add this char to the current run to be printed.
            }
        }
    }

    // When we leave the loop, current has been advanced to the length of the string itself
    // (or one past the array index to the final char) so this `substr` operation doesn't +1
    // to include the final character (unlike the one inside the top of the loop above.)

Review comment (suggestion):
You can write `if (_runSize > 1)` here. Then you can write:
```cpp
const auto allLeadingUpTo = _run.substr(_runOffset, _runSize - 1);
```

Code after:

    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...
            {
                if (_runSize > 0)
                {
                    // Because the run above is composed INCLUDING current, we must
                    // trim it off here since we just determined it's actionable
                    // and only pass through everything before it.
                    _runSize -= 1;
                    const auto allLeadingUpTo = _CurrentRun();

                    _engine->ActionPrintString(allLeadingUpTo); // ... print all the chars leading up to it as part of the run...
                    _trace.DispatchPrintRunTrace(allLeadingUpTo);
                }

                _processingIndividually = true; // begin processing future characters individually...
                start = current;
                continue;
            }
            else
            {
                ++current; // Otherwise, add this char to the current run to be printed.
            }
        }
    }

    // When we leave the loop, current has been advanced to the length of the string itself
    // (or one past the array index to the final char) so this `substr` operation doesn't +1
    // to include the final character (unlike the one inside the top of the loop above.)
    if (start < string.size())