From bc20e4f71d41f2ebcc56351daecb826544b15df5 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 21 Jan 2022 23:44:50 +0330 Subject: [PATCH] LibRegex: Add some more information to Compare::Reference debug output --- Userland/Libraries/LibRegex/RegexByteCode.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp index 050f067ae0..e0e6cbe175 100644 --- a/Userland/Libraries/LibRegex/RegexByteCode.cpp +++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp @@ -900,6 +900,21 @@ Vector OpCode_Compare::variable_arguments_to_string(Optional } else if (compare_type == CharacterCompareType::Reference) { auto ref = m_bytecode->at(offset++); result.empend(String::formatted("number={}", ref)); + if (input.has_value()) { + if (state().capture_group_matches.size() > input->match_index) { + auto& match = state().capture_group_matches[input->match_index]; + if (match.size() > ref) { + auto& group = match[ref]; + result.empend(String::formatted("left={}", group.left_column)); + result.empend(String::formatted("right={}", group.left_column + group.view.length_in_code_units())); + result.empend(String::formatted("contents='{}'", group.view)); + } else { + result.empend(String::formatted("(invalid ref, max={})", match.size() - 1)); + } + } else { + result.empend(String::formatted("(invalid index {}, max={})", input->match_index, state().capture_group_matches.size() - 1)); + } + } } else if (compare_type == CharacterCompareType::String) { auto& length = m_bytecode->at(offset++); StringBuilder str_builder;