1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:18:11 +00:00

LibRegex: Support property escapes of the Unicode script property

Note that unlike binary properties and general categories, scripts must
be specified in the non-binary (Script=Value) form.
This commit is contained in:
Timothy Flynn 2021-08-04 06:35:48 -04:00 committed by Linus Groh
parent f5c1bbc00b
commit 06088df729
5 changed files with 44 additions and 4 deletions

View file

@ -569,6 +569,10 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(MatchInput const& input, M
auto general_category = static_cast<Unicode::GeneralCategory>(m_bytecode->at(offset++));
compare_general_category(input, state, general_category, current_inversion_state(), inverse_matched);
} else if (compare_type == CharacterCompareType::Script) {
auto script = static_cast<Unicode::Script>(m_bytecode->at(offset++));
compare_script(input, state, script, current_inversion_state(), inverse_matched);
} else {
warnln("Undefined comparison: {}", (int)compare_type);
VERIFY_NOT_REACHED();
@ -790,6 +794,22 @@ ALWAYS_INLINE void OpCode_Compare::compare_general_category(MatchInput const& in
}
}
ALWAYS_INLINE void OpCode_Compare::compare_script(MatchInput const& input, MatchState& state, Unicode::Script script, bool inverse, bool& inverse_matched)
{
if (state.string_position == input.view.length())
return;
u32 code_point = input.view[state.string_position_in_code_units];
bool equal = Unicode::code_point_has_script(code_point, script);
if (equal) {
if (inverse)
inverse_matched = true;
else
advance_string_position(state, input.view, code_point);
}
}
String const OpCode_Compare::arguments_string() const
{
return String::formatted("argc={}, args={} ", arguments_count(), arguments_size());