Repository: LadybirdBrowser/ladybird
File: Libraries/LibRegex/RegexDebug.h (C/C++)

Code before:
        }
    }

    void print_result(OpCode<ByteCode> const& opcode, ByteCode const& bytecode, MatchInput const& input, MatchState& state, ExecutionResult result) const
    {
        StringBuilder builder;
        builder.append(execution_result_name(result));
        builder.appendff(", fc: {}, ss: {}", input.fail_counter, input.saved_positions.size());
        if (result == ExecutionResult::Succeeded) {
            builder.appendff(", ip: {}/{}, sp: {}/{}", state.instruction_position, bytecode.size() - 1, state.string_position, input.view.length() - 1);
        } else if (result == ExecutionResult::Fork_PrioHigh) {
            builder.appendff(", next ip: {}", state.fork_at_position + opcode.size());
        } else if (result != ExecutionResult::Failed) {
            builder.appendff(", next ip: {}", state.instruction_position + opcode.size());
        }

        outln(m_file, " | {:20}", builder.to_byte_string());

        if (is<OpCode_CheckSavedPosition>(opcode)) {
            auto saved = input.saved_positions.is_empty()
                ? "saved: <empty>"_string
                : MUST(String::formatted("saved: {}", input.saved_positions.last()));
            outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", saved, "");
        }
        if (is<OpCode_CheckStepBack>(opcode) || is<OpCode_IncStepBack>(opcode)) {
            auto step_string = state.step_backs.is_empty()
                ? "step: <empty>"_string
                : MUST(String::formatted("step: {}", state.step_backs.last()));
            outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", step_string, "");
        }

        if (is<OpCode_Compare>(opcode)) {
            for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_byte_string(input)) {
                outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", line, "");
            }
        }

        out(m_file, "{}", m_debug_stripline);
    }

    void print_header()
    {
        StringBuilder builder;
        builder.appendff("{:15} | {:5} | {:9} | {:35} | {:30} | {:20} | {:20}\n", "System", "Index", "Recursion", "OpCode", "Arguments", "State", "Result");
        auto length = builder.length();
        for (size_t i = 0; i < length; ++i) {
            builder.append('=');
        }
        auto str = builder.to_byte_string();
        VERIFY(!str.is_empty());


Review comment (refactor):
I don't think the variable name usually includes the 'type', instead of `step_string` wouldn't `last_step` or `last_step_back`  be a more descriptive name?  And above `last_saved` or `last_saved_position?

Pick names consistent across these and that are as descriptive as possible without being too long. :-)

Sorry for the nit-picking.

Code after:
        }
    }

    void print_result(OpCode<ByteCode> const& opcode, ByteCode const& bytecode, MatchInput const& input, MatchState& state, ExecutionResult result) const
    {
        StringBuilder builder;
        builder.append(execution_result_name(result));
        builder.appendff(", fc: {}, ss: {}", input.fail_counter, input.saved_positions.size());
        if (result == ExecutionResult::Succeeded) {
            builder.appendff(", ip: {}/{}, sp: {}/{}", state.instruction_position, bytecode.size() - 1, state.string_position, input.view.length() - 1);
        } else if (result == ExecutionResult::Fork_PrioHigh) {
            builder.appendff(", next ip: {}", state.fork_at_position + opcode.size());
        } else if (result != ExecutionResult::Failed) {
            builder.appendff(", next ip: {}", state.instruction_position + opcode.size());
        }

        outln(m_file, " | {:20}", builder.to_byte_string());

        if (is<OpCode_CheckSavedPosition>(opcode)) {
            auto last_saved = input.saved_positions.is_empty()
                ? "saved: <empty>"_string
                : MUST(String::formatted("saved: {}", input.saved_positions.last()));
            outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", last_saved, "");
        }
        if (is<OpCode_CheckStepBack>(opcode) || is<OpCode_IncStepBack>(opcode)) {
            auto last_step_back = state.step_backs.is_empty()
                ? "step: <empty>"_string
                : MUST(String::formatted("step: {}", state.step_backs.last()));
            outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", last_step_back, "");
        }

        if (is<OpCode_Compare>(opcode)) {
            for (auto& line : to<OpCode_Compare>(opcode).variable_arguments_to_byte_string(input)) {
                outln(m_file, "{:15} | {:5} | {:9} | {:35} | {:30} | {:20}", "", "", "", "", line, "");
            }
        }

        out(m_file, "{}", m_debug_stripline);
    }

    void print_header()
    {
        StringBuilder builder;
        builder.appendff("{:15} | {:5} | {:9} | {:35} | {:30} | {:20} | {:20}\n", "System", "Index", "Recursion", "OpCode", "Arguments", "State", "Result");
        auto length = builder.length();
        for (size_t i = 0; i < length; ++i) {
            builder.append('=');
        }
        auto str = builder.to_byte_string();
        VERIFY(!str.is_empty());