mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 02:27:19 +02:00
LibRegex: Support UTF-16 RegexStringView and improve Unicode matching
When the Unicode option is not set, regular expressions should match based on code units; when it is set, they should match based on code points. To do so, the regex parser must combine surrogate pairs when the Unicode option is set. Further, RegexStringView needs to know if the flag is set in order to return code point vs. code unit based string lengths and substrings.
This commit is contained in:
committed by
Linus Groh
parent
2e45e52993
commit
47f6bb38a1
Notes:
sideshowbarker
2024-07-18 08:26:31 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/47f6bb38a1b Pull-request: https://github.com/SerenityOS/serenity/pull/8931 Reviewed-by: https://github.com/linusg ✅
@@ -465,12 +465,13 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(MatchInput const& input, M
|
||||
return ExecutionResult::Failed_ExecuteLowPrioForks;
|
||||
|
||||
Optional<String> str;
|
||||
Vector<u16> utf16;
|
||||
Vector<u32> data;
|
||||
data.ensure_capacity(length);
|
||||
for (size_t i = offset; i < offset + length; ++i)
|
||||
data.unchecked_append(m_bytecode->at(i));
|
||||
|
||||
auto view = input.view.construct_as_same(data, str);
|
||||
auto view = input.view.construct_as_same(data, str, utf16);
|
||||
offset += length;
|
||||
if (!compare_string(input, state, view, had_zero_length_match))
|
||||
return ExecutionResult::Failed_ExecuteLowPrioForks;
|
||||
@@ -553,7 +554,8 @@ ALWAYS_INLINE void OpCode_Compare::compare_char(MatchInput const& input, MatchSt
|
||||
|
||||
auto input_view = input.view.substring_view(state.string_position, 1);
|
||||
Optional<String> str;
|
||||
auto compare_view = input_view.construct_as_same({ &ch1, 1 }, str);
|
||||
Vector<u16> utf16;
|
||||
auto compare_view = input_view.construct_as_same({ &ch1, 1 }, str, utf16);
|
||||
bool equal;
|
||||
if (input.regex_options & AllFlags::Insensitive)
|
||||
equal = input_view.equals_ignoring_case(compare_view);
|
||||
|
||||
Reference in New Issue
Block a user