mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
AK+Everywhere: Prepare Utf16View for integration with a UTF-16 string
To prepare for an upcoming Utf16String, this migrates Utf16View to store its data as a char16_t. Most function definitions are moved inline and made constexpr. This also adds a UDL to construct a Utf16View from a string literal: auto string = u"hello"sv; This let's us remove the NTTP Utf16View constructor, as we have found that such constructors bloat binary size quite a bit.
This commit is contained in:
parent
c17b067e1d
commit
86b1c78c1a
Notes:
github-actions[bot]
2025-07-03 13:53:23 +00:00
Author: https://github.com/trflynn89
Commit: 86b1c78c1a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5228
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/shannonbooth
17 changed files with 406 additions and 421 deletions
|
@ -1271,33 +1271,33 @@ ThrowCompletionOr<String> get_substitution(VM& vm, Utf16View const& matched, Utf
|
|||
Optional<Utf16String> capture_string;
|
||||
|
||||
// b. If templateRemainder starts with "$$", then
|
||||
if (template_remainder.starts_with(u"$$")) {
|
||||
if (template_remainder.starts_with(u"$$"sv)) {
|
||||
// i. Let ref be "$$".
|
||||
ref = u"$$";
|
||||
ref = u"$$"sv;
|
||||
|
||||
// ii. Let refReplacement be "$".
|
||||
ref_replacement = u"$";
|
||||
ref_replacement = u"$"sv;
|
||||
}
|
||||
// c. Else if templateRemainder starts with "$`", then
|
||||
else if (template_remainder.starts_with(u"$`")) {
|
||||
else if (template_remainder.starts_with(u"$`"sv)) {
|
||||
// i. Let ref be "$`".
|
||||
ref = u"$`";
|
||||
ref = u"$`"sv;
|
||||
|
||||
// ii. Let refReplacement be the substring of str from 0 to position.
|
||||
ref_replacement = str.substring_view(0, position);
|
||||
}
|
||||
// d. Else if templateRemainder starts with "$&", then
|
||||
else if (template_remainder.starts_with(u"$&")) {
|
||||
else if (template_remainder.starts_with(u"$&"sv)) {
|
||||
// i. Let ref be "$&".
|
||||
ref = u"$&";
|
||||
ref = u"$&"sv;
|
||||
|
||||
// ii. Let refReplacement be matched.
|
||||
ref_replacement = matched;
|
||||
}
|
||||
// e. Else if templateRemainder starts with "$'" (0x0024 (DOLLAR SIGN) followed by 0x0027 (APOSTROPHE)), then
|
||||
else if (template_remainder.starts_with(u"$'")) {
|
||||
else if (template_remainder.starts_with(u"$'"sv)) {
|
||||
// i. Let ref be "$'".
|
||||
ref = u"$'";
|
||||
ref = u"$'"sv;
|
||||
|
||||
// ii. Let matchLength be the length of matched.
|
||||
auto match_length = matched.length_in_code_units();
|
||||
|
@ -1311,7 +1311,7 @@ ThrowCompletionOr<String> get_substitution(VM& vm, Utf16View const& matched, Utf
|
|||
// v. NOTE: tailPos can exceed stringLength only if this abstract operation was invoked by a call to the intrinsic @@replace method of %RegExp.prototype% on an object whose "exec" property is not the intrinsic %RegExp.prototype.exec%.
|
||||
}
|
||||
// f. Else if templateRemainder starts with "$" followed by 1 or more decimal digits, then
|
||||
else if (template_remainder.starts_with(u"$") && template_remainder.length_in_code_units() > 1 && is_ascii_digit(template_remainder.code_unit_at(1))) {
|
||||
else if (template_remainder.starts_with(u"$"sv) && template_remainder.length_in_code_units() > 1 && is_ascii_digit(template_remainder.code_unit_at(1))) {
|
||||
// i. If templateRemainder starts with "$" followed by 2 or more decimal digits, let digitCount be 2. Otherwise, let digitCount be 1.
|
||||
size_t digit_count = 1;
|
||||
|
||||
|
@ -1373,15 +1373,15 @@ ThrowCompletionOr<String> get_substitution(VM& vm, Utf16View const& matched, Utf
|
|||
}
|
||||
}
|
||||
// g. Else if templateRemainder starts with "$<", then
|
||||
else if (template_remainder.starts_with(u"$<")) {
|
||||
else if (template_remainder.starts_with(u"$<"sv)) {
|
||||
// i. Let gtPos be StringIndexOf(templateRemainder, ">", 0).
|
||||
// NOTE: We can actually start at index 2 because we know the string starts with "$<".
|
||||
auto greater_than_position = string_index_of(template_remainder, u">", 2);
|
||||
auto greater_than_position = string_index_of(template_remainder, u">"sv, 2);
|
||||
|
||||
// ii. If gtPos = -1 or namedCaptures is undefined, then
|
||||
if (!greater_than_position.has_value() || named_captures.is_undefined()) {
|
||||
// 1. Let ref be "$<".
|
||||
ref = u"$<";
|
||||
ref = u"$<"sv;
|
||||
|
||||
// 2. Let refReplacement be ref.
|
||||
ref_replacement = ref;
|
||||
|
@ -1427,7 +1427,7 @@ ThrowCompletionOr<String> get_substitution(VM& vm, Utf16View const& matched, Utf
|
|||
auto ref_length = ref.length_in_code_units();
|
||||
|
||||
// k. Set result to the string-concatenation of result and refReplacement.
|
||||
result.append(ref_replacement.data(), ref_replacement.length_in_code_points());
|
||||
result.append(ref_replacement.span().data(), ref_replacement.length_in_code_units());
|
||||
|
||||
// j. Set templateRemainder to the substring of templateRemainder from refLength.
|
||||
// NOTE: We do this step last because refReplacement may point to templateRemainder.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue