mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 19:29:16 +00:00
LibRegex: Make ^ and $ accept all LineTerminators instead of just '\n'
Also adds a couple tests.
This commit is contained in:
committed by
Andreas Kling
parent
59a76b1279
commit
6fc9f5fa28
@@ -11,6 +11,11 @@
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibUnicode/CharacterTypes.h>
|
||||
|
||||
// U+2028 LINE SEPARATOR
|
||||
constexpr static u32 const LineSeparator { 0x2028 };
|
||||
// U+2029 PARAGRAPH SEPARATOR
|
||||
constexpr static u32 const ParagraphSeparator { 0x2029 };
|
||||
|
||||
namespace regex {
|
||||
|
||||
StringView OpCode::name(OpCodeId opcode_id)
|
||||
@@ -277,7 +282,7 @@ ALWAYS_INLINE ExecutionResult OpCode_CheckBegin::execute(MatchInput const& input
|
||||
|
||||
if (input.regex_options.has_flag_set(AllFlags::Multiline) && input.regex_options.has_flag_set(AllFlags::Internal_ConsiderNewline)) {
|
||||
auto input_view = input.view.substring_view(state.string_position - 1, 1)[0];
|
||||
return input_view == '\n';
|
||||
return input_view == '\r' || input_view == '\n' || input_view == LineSeparator || input_view == ParagraphSeparator;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -330,7 +335,7 @@ ALWAYS_INLINE ExecutionResult OpCode_CheckEnd::execute(MatchInput const& input,
|
||||
|
||||
if (input.regex_options.has_flag_set(AllFlags::Multiline) && input.regex_options.has_flag_set(AllFlags::Internal_ConsiderNewline)) {
|
||||
auto input_view = input.view.substring_view(state.string_position, 1)[0];
|
||||
return input_view == '\n';
|
||||
return input_view == '\r' || input_view == '\n' || input_view == LineSeparator || input_view == ParagraphSeparator;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -499,11 +504,6 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(MatchInput const& input, M
|
||||
if (input.view.length() <= state.string_position)
|
||||
return ExecutionResult::Failed_ExecuteLowPrioForks;
|
||||
|
||||
// U+2028 LINE SEPARATOR
|
||||
constexpr static u32 const LineSeparator { 0x2028 };
|
||||
// U+2029 PARAGRAPH SEPARATOR
|
||||
constexpr static u32 const ParagraphSeparator { 0x2029 };
|
||||
|
||||
auto input_view = input.view.substring_view(state.string_position, 1)[0];
|
||||
auto is_equivalent_to_newline = input_view == '\n'
|
||||
|| (input.regex_options.has_flag_set(AllFlags::Internal_ECMA262DotSemantics)
|
||||
|
||||
Reference in New Issue
Block a user