1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:47:34 +00:00

Everywhere: Use _{short_,}string to create Strings from literals

This commit is contained in:
Linus Groh 2023-02-25 16:40:37 +01:00
parent 85414d9338
commit 09d40bfbb2
92 changed files with 334 additions and 310 deletions

View file

@ -111,7 +111,7 @@ ErrorOr<String> Process::get_name()
return String::from_utf8(StringView { buffer, strlen(buffer) });
#else
// FIXME: Implement Process::get_name() for other platforms.
return String::from_utf8_short_string("???"sv);
return "???"_short_string;
#endif
}

View file

@ -116,14 +116,14 @@ ErrorOr<Vector<String>> StandardPaths::font_directories()
{
return Vector { {
#if defined(AK_OS_SERENITY)
TRY(String::from_utf8("/res/fonts"sv)),
TRY("/res/fonts"_string),
#elif defined(AK_OS_MACOS)
TRY(String::from_utf8("/System/Library/Fonts"sv)),
TRY(String::from_utf8("/Library/Fonts"sv)),
TRY("/System/Library/Fonts"_string),
TRY("/Library/Fonts"_string),
TRY(String::formatted("{}/Library/Fonts"sv, home_directory())),
#else
TRY(String::from_utf8("/usr/share/fonts"sv)),
TRY(String::from_utf8("/usr/local/share/fonts"sv)),
TRY("/usr/share/fonts"_string),
TRY("/usr/local/share/fonts"_string),
TRY(String::formatted("{}/.local/share/fonts"sv, home_directory())),
#endif
} };

View file

@ -150,7 +150,7 @@ ErrorOr<String> UnsignedBigInteger::to_base(u16 N) const
{
VERIFY(N <= 36);
if (*this == UnsignedBigInteger { 0 })
return String::from_utf8_short_string("0"sv);
return "0"_short_string;
StringBuilder builder;
UnsignedBigInteger temp(*this);

View file

@ -12,9 +12,9 @@ namespace DSP::Effects {
Delay::Delay(NonnullRefPtr<Transport> transport)
: EffectProcessor(move(transport))
, m_delay_decay(String::from_utf8_short_string("Decay"sv), 0.01, 0.99, 0.33, Logarithmic::No)
, m_delay_time(String::from_utf8("Delay Time"sv), 3, 2000, 900, Logarithmic::Yes)
, m_dry_gain(String::from_utf8_short_string("Dry"sv), 0, 1, 0.9, Logarithmic::No)
, m_delay_decay("Decay"_short_string, 0.01, 0.99, 0.33, Logarithmic::No)
, m_delay_time("Delay Time"_string, 3, 2000, 900, Logarithmic::Yes)
, m_dry_gain("Dry"_short_string, 0, 1, 0.9, Logarithmic::No)
{
m_parameters.append(m_delay_decay);
@ -59,9 +59,9 @@ void Delay::process_impl(Signal const& input_signal, Signal& output_signal)
Mastering::Mastering(NonnullRefPtr<Transport> transport)
: EffectProcessor(move(transport))
, m_pan(String::from_utf8_short_string("Pan"sv), -1, 1, 0, Logarithmic::No)
, m_volume(String::from_utf8_short_string("Volume"sv), 0, 1, 1, Logarithmic::No)
, m_muted(String::from_utf8_short_string("Mute"sv), false)
, m_pan("Pan"_short_string, -1, 1, 0, Logarithmic::No)
, m_volume("Volume"_short_string, 0, 1, 1, Logarithmic::No)
, m_muted("Mute"_short_string, false)
{
m_parameters.append(m_muted);
m_parameters.append(m_volume);

View file

@ -19,11 +19,11 @@ namespace DSP::Synthesizers {
Classic::Classic(NonnullRefPtr<Transport> transport)
: DSP::SynthesizerProcessor(move(transport))
, m_waveform(String::from_utf8("Waveform"sv), Waveform::Saw)
, m_attack(String::from_utf8_short_string("Attack"sv), 0.01, 2000, 5, Logarithmic::Yes)
, m_decay(String::from_utf8_short_string("Decay"sv), 0.01, 20'000, 80, Logarithmic::Yes)
, m_sustain(String::from_utf8_short_string("Sustain"sv), 0.001, 1, 0.725, Logarithmic::No)
, m_release(String::from_utf8_short_string("Release"sv), 0.01, 6'000, 120, Logarithmic::Yes)
, m_waveform("Waveform"_string, Waveform::Saw)
, m_attack("Attack"_short_string, 0.01, 2000, 5, Logarithmic::Yes)
, m_decay("Decay"_short_string, 0.01, 20'000, 80, Logarithmic::Yes)
, m_sustain("Sustain"_short_string, 0.001, 1, 0.725, Logarithmic::No)
, m_release("Release"_short_string, 0.01, 6'000, 120, Logarithmic::Yes)
{
m_parameters.append(m_waveform);
m_parameters.append(m_attack);

View file

@ -15,8 +15,8 @@ ErrorOr<NonnullOwnPtr<LinkedShader>> Linker::link(Vector<ObjectFile const*> cons
GPU::IR::Shader shader;
auto input_name = TRY(String::from_utf8("input0"sv));
auto output_name = TRY(String::from_utf8("output0"sv));
auto input_name = TRY("input0"_string);
auto output_name = TRY("output0"_string);
TRY(shader.inputs.try_append({ move(input_name), GPU::IR::StorageType::Vector4 }));
TRY(shader.outputs.try_append({ move(output_name), GPU::IR::StorageType::Vector4 }));
GPU::IR::Instruction instruction {

View file

@ -228,14 +228,14 @@ void ColorPicker::build_ui()
button_container.add_spacer().release_value_but_fixme_should_propagate_errors();
auto& ok_button = button_container.add<DialogButton>();
ok_button.set_text(String::from_utf8_short_string("OK"sv));
ok_button.set_text("OK"_short_string);
ok_button.on_click = [this](auto) {
done(ExecResult::OK);
};
ok_button.set_default(true);
auto& cancel_button = button_container.add<DialogButton>();
cancel_button.set_text(String::from_utf8_short_string("Cancel"sv));
cancel_button.set_text("Cancel"_short_string);
cancel_button.on_click = [this](auto) {
done(ExecResult::Cancel);
};
@ -407,7 +407,7 @@ void ColorPicker::build_ui_custom(Widget& root_container)
make_spinbox(Blue, m_color.blue());
make_spinbox(Alpha, m_color.alpha());
m_selector_button = vertical_container.add<GUI::Button>(String::from_utf8("Select on screen"sv).release_value_but_fixme_should_propagate_errors());
m_selector_button = vertical_container.add<GUI::Button>("Select on screen"_string.release_value_but_fixme_should_propagate_errors());
m_selector_button->on_click = [this](auto) {
auto selector = ColorSelectOverlay::construct();
auto original_color = m_color;

View file

@ -224,7 +224,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
ok_button.set_enabled(m_mode == Mode::OpenFolder || !m_filename_textbox->text().is_empty());
auto& cancel_button = *widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button.set_text(String::from_utf8_short_string("Cancel"sv));
cancel_button.set_text("Cancel"_short_string);
cancel_button.on_click = [this](auto) {
done(ExecResult::Cancel);
};

View file

@ -54,11 +54,11 @@ private:
case Mode::Open:
case Mode::OpenMultiple:
case Mode::OpenFolder:
return String::from_utf8_short_string("Open"sv);
return "Open"_short_string;
case Mode::Save:
return String::from_utf8_short_string("Save"sv);
return "Save"_short_string;
default:
return String::from_utf8_short_string("OK"sv);
return "OK"_short_string;
}
}

View file

@ -37,7 +37,7 @@ IncrementalSearchBanner::IncrementalSearchBanner(TextEditor& editor)
};
m_close_button = find_descendant_of_type_named<Button>("incremental_search_banner_close_button");
m_close_button->set_text(String::from_utf8_short_string("\xE2\x9D\x8C"sv));
m_close_button->set_text("\xE2\x9D\x8C"_short_string);
m_close_button->on_click = [this](auto) {
hide();
};

View file

@ -103,7 +103,7 @@ void InputBox::build()
button_container_inner.add_spacer().release_value_but_fixme_should_propagate_errors();
m_ok_button = button_container_inner.add<DialogButton>();
m_ok_button->set_text(String::from_utf8_short_string("OK"sv));
m_ok_button->set_text("OK"_short_string);
m_ok_button->on_click = [this](auto) {
dbgln("GUI::InputBox: OK button clicked");
done(ExecResult::OK);
@ -111,7 +111,7 @@ void InputBox::build()
m_ok_button->set_default(true);
m_cancel_button = button_container_inner.add<DialogButton>();
m_cancel_button->set_text(String::from_utf8_short_string("Cancel"sv));
m_cancel_button->set_text("Cancel"_short_string);
m_cancel_button->on_click = [this](auto) {
dbgln("GUI::InputBox: Cancel button clicked");
done(ExecResult::Cancel);

View file

@ -50,11 +50,11 @@ Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window,
box->set_icon(parent_window->icon());
if (path.is_empty())
box->m_yes_button->set_text(String::from_utf8("Save As..."sv).release_value_but_fixme_should_propagate_errors());
box->m_yes_button->set_text("Save As..."_string.release_value_but_fixme_should_propagate_errors());
else
box->m_yes_button->set_text(String::from_utf8_short_string("Save"sv));
box->m_no_button->set_text(String::from_utf8_short_string("Discard"sv));
box->m_cancel_button->set_text(String::from_utf8_short_string("Cancel"sv));
box->m_yes_button->set_text("Save"_short_string);
box->m_no_button->set_text("Discard"_short_string);
box->m_cancel_button->set_text("Cancel"_short_string);
return box->exec();
}
@ -162,13 +162,13 @@ void MessageBox::build()
button_container.add_spacer().release_value_but_fixme_should_propagate_errors();
if (should_include_ok_button())
m_ok_button = add_button(String::from_utf8_short_string("OK"sv), ExecResult::OK);
m_ok_button = add_button("OK"_short_string, ExecResult::OK);
if (should_include_yes_button())
m_yes_button = add_button(String::from_utf8_short_string("Yes"sv), ExecResult::Yes);
m_yes_button = add_button("Yes"_short_string, ExecResult::Yes);
if (should_include_no_button())
m_no_button = add_button(String::from_utf8_short_string("No"sv), ExecResult::No);
m_no_button = add_button("No"_short_string, ExecResult::No);
if (should_include_cancel_button())
m_cancel_button = add_button(String::from_utf8_short_string("Cancel"sv), ExecResult::Cancel);
m_cancel_button = add_button("Cancel"_short_string, ExecResult::Cancel);
button_container.add_spacer().release_value_but_fixme_should_propagate_errors();
int width = (button_count * button_width) + ((button_count - 1) * button_container.layout()->spacing()) + 32;

View file

@ -61,7 +61,7 @@ ProcessChooser::ProcessChooser(StringView window_title, String button_label, Gfx
auto index = m_table_view->selection().first();
set_pid_from_index_and_close(index);
};
auto& cancel_button = button_container.add<GUI::Button>(String::from_utf8_short_string("Cancel"sv));
auto& cancel_button = button_container.add<GUI::Button>("Cancel"_short_string);
cancel_button.set_fixed_width(80);
cancel_button.on_click = [this](auto) {
done(ExecResult::Cancel);

View file

@ -23,7 +23,7 @@ public:
pid_t pid() const { return m_pid; }
private:
ProcessChooser(StringView window_title = "Process Chooser"sv, String button_label = String::from_utf8_short_string("Select"sv), Gfx::Bitmap const* window_icon = nullptr, GUI::Window* parent_window = nullptr);
ProcessChooser(StringView window_title = "Process Chooser"sv, String button_label = "Select"_short_string, Gfx::Bitmap const* window_icon = nullptr, GUI::Window* parent_window = nullptr);
void set_pid_from_index_and_close(ModelIndex const&);

View file

@ -43,7 +43,7 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(DeprecatedString t
TRY(button_container->try_set_layout<GUI::HorizontalBoxLayout>(GUI::Margins {}, 6));
if (show_defaults_button == ShowDefaultsButton::Yes) {
window->m_reset_button = TRY(button_container->try_add<GUI::DialogButton>(TRY(String::from_utf8("Defaults"sv))));
window->m_reset_button = TRY(button_container->try_add<GUI::DialogButton>(TRY("Defaults"_string)));
window->m_reset_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {
window->reset_default_values();
};
@ -51,19 +51,19 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(DeprecatedString t
TRY(button_container->add_spacer());
window->m_ok_button = TRY(button_container->try_add<GUI::DialogButton>(String::from_utf8_short_string("OK"sv)));
window->m_ok_button = TRY(button_container->try_add<GUI::DialogButton>("OK"_short_string));
window->m_ok_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {
window->apply_settings();
GUI::Application::the()->quit();
};
window->m_cancel_button = TRY(button_container->try_add<GUI::DialogButton>(String::from_utf8_short_string("Cancel"sv)));
window->m_cancel_button = TRY(button_container->try_add<GUI::DialogButton>("Cancel"_short_string));
window->m_cancel_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {
window->cancel_settings();
GUI::Application::the()->quit();
};
window->m_apply_button = TRY(button_container->try_add<GUI::DialogButton>(String::from_utf8_short_string("Apply"sv)));
window->m_apply_button = TRY(button_container->try_add<GUI::DialogButton>("Apply"_short_string));
window->m_apply_button->set_enabled(false);
window->m_apply_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {
window->apply_settings();

View file

@ -43,12 +43,12 @@ WizardDialog::WizardDialog(Window* parent_window)
nav_container_widget.set_fixed_height(42);
nav_container_widget.add_spacer().release_value_but_fixme_should_propagate_errors();
m_back_button = nav_container_widget.add<DialogButton>(String::from_utf8_short_string("< Back"sv));
m_back_button = nav_container_widget.add<DialogButton>("< Back"_short_string);
m_back_button->on_click = [&](auto) {
pop_page();
};
m_next_button = nav_container_widget.add<DialogButton>(String::from_utf8_short_string("Next >"sv));
m_next_button = nav_container_widget.add<DialogButton>("Next >"_short_string);
m_next_button->on_click = [&](auto) {
VERIFY(has_pages());
@ -65,7 +65,7 @@ WizardDialog::WizardDialog(Window* parent_window)
auto& button_spacer = nav_container_widget.add<Widget>();
button_spacer.set_fixed_width(10);
m_cancel_button = nav_container_widget.add<DialogButton>(String::from_utf8_short_string("Cancel"sv));
m_cancel_button = nav_container_widget.add<DialogButton>("Cancel"_short_string);
m_cancel_button->on_click = [&](auto) {
handle_cancel();
};
@ -120,11 +120,11 @@ void WizardDialog::update_navigation()
if (has_pages()) {
m_next_button->set_enabled(current_page().is_final_page() || current_page().can_go_next());
if (current_page().is_final_page())
m_next_button->set_text(String::from_utf8_short_string("Finish"sv));
m_next_button->set_text("Finish"_short_string);
else
m_next_button->set_text(String::from_utf8_short_string("Next >"sv));
m_next_button->set_text("Next >"_short_string);
} else {
m_next_button->set_text(String::from_utf8_short_string("Next >"sv));
m_next_button->set_text("Next >"_short_string);
m_next_button->set_enabled(false);
}
}

View file

@ -147,7 +147,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable const& e
for (size_t i = 0; i < registers().size(); ++i) {
String value_string;
if (registers()[i].is_empty())
value_string = MUST(String::from_utf8("(empty)"sv));
value_string = MUST("(empty)"_string);
else
value_string = MUST(registers()[i].to_string_without_side_effects());
dbgln("[{:3}] {}", i, value_string);

View file

@ -104,7 +104,7 @@ ThrowCompletionOr<Value> Console::trace()
for (ssize_t i = execution_context_stack.size() - 2; i >= 0; --i) {
auto const& function_name = execution_context_stack[i]->function_name;
trace.stack.append(function_name.is_empty()
? TRY_OR_THROW_OOM(vm, String::from_utf8("<anonymous>"sv))
? TRY_OR_THROW_OOM(vm, "<anonymous>"_string)
: TRY_OR_THROW_OOM(vm, String::from_deprecated_string(function_name)));
}
@ -253,7 +253,7 @@ ThrowCompletionOr<Value> Console::group()
}
// ... Otherwise, let groupLabel be an implementation-chosen label representing a group.
else {
group_label = TRY_OR_THROW_OOM(vm, String::from_utf8("Group"sv));
group_label = TRY_OR_THROW_OOM(vm, "Group"_string);
}
// 3. Incorporate groupLabel as a label for group.
@ -289,7 +289,7 @@ ThrowCompletionOr<Value> Console::group_collapsed()
}
// ... Otherwise, let groupLabel be an implementation-chosen label representing a group.
else {
group_label = TRY_OR_THROW_OOM(vm, String::from_utf8("Group"sv));
group_label = TRY_OR_THROW_OOM(vm, "Group"_string);
}
// 3. Incorporate groupLabel as a label for group.

View file

@ -836,7 +836,7 @@ Token Lexer::next()
if (m_hit_invalid_unicode.has_value()) {
value_start = m_hit_invalid_unicode.value() - 1;
m_current_token = Token(TokenType::Invalid, String::from_utf8("Invalid unicode codepoint in source"sv).release_value_but_fixme_should_propagate_errors(),
m_current_token = Token(TokenType::Invalid, "Invalid unicode codepoint in source"_string.release_value_but_fixme_should_propagate_errors(),
""sv, // Since the invalid unicode can occur anywhere in the current token the trivia is not correct
m_source.substring_view(value_start + 1, min(4u, m_source.length() - value_start - 2)),
m_filename,

View file

@ -47,7 +47,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
// 4. If name is undefined, set name to "Error"; otherwise set name to ? ToString(name).
auto name = name_property.is_undefined()
? TRY_OR_THROW_OOM(vm, String::from_utf8("Error"sv))
? TRY_OR_THROW_OOM(vm, "Error"_string)
: TRY(name_property.to_string(vm));
// 5. Let msg be ? Get(O, "message").
@ -90,7 +90,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_getter)
if (auto name_property = TRY(error.get(vm.names.name)); !name_property.is_undefined())
name = TRY(name_property.to_string(vm));
else
name = TRY_OR_THROW_OOM(vm, String::from_utf8("Error"sv));
name = TRY_OR_THROW_OOM(vm, "Error"_string);
String message {};
if (auto message_property = TRY(error.get(vm.names.message)); !message_property.is_undefined())

View file

@ -464,7 +464,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
// 4. Else if keyLocaleData contains "true", then
else if (key_locale_data.contains_slow("true"sv)) {
// a. Let value be "true".
value = TRY_OR_THROW_OOM(vm, String::from_utf8("true"sv));
value = TRY_OR_THROW_OOM(vm, "true"_string);
// b. Let supportedExtensionAddition be the string-concatenation of "-" and key.
supported_extension_addition = ::Locale::Keyword { TRY_OR_THROW_OOM(vm, String::from_utf8(key)), {} };
@ -487,7 +487,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
// 3. If optionsValue is the empty String, then
if (options_value->is_empty()) {
// a. Let optionsValue be "true".
options_value = TRY_OR_THROW_OOM(vm, String::from_utf8("true"sv));
options_value = TRY_OR_THROW_OOM(vm, "true"_string);
}
}

View file

@ -83,7 +83,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// 21. Let collation be r.[[co]].
// 22. If collation is null, let collation be "default".
// 23. Set collator.[[Collation]] to collation.
collator.set_collation(result.co.has_value() ? result.co.release_value() : TRY_OR_THROW_OOM(vm, String::from_utf8("default"sv)));
collator.set_collation(result.co.has_value() ? result.co.release_value() : TRY_OR_THROW_OOM(vm, "default"_string));
// 24. If relevantExtensionKeys contains "kn", then
if (relevant_extension_keys.span().contains_slow("kn"sv) && result.kn.has_value()) {

View file

@ -1241,7 +1241,7 @@ ThrowCompletionOr<RawFormatResult> to_raw_fixed(VM& vm, MathematicalValue const&
// 7. If n = 0, let m be "0". Otherwise, let m be the String consisting of the digits of the decimal representation of n (in order, with no leading zeroes).
result.formatted_string = n.is_zero()
? String::from_utf8_short_string("0"sv)
? "0"_short_string
: MUST_OR_THROW_OOM(n.to_string(vm));
// 8. If f ≠ 0, then

View file

@ -450,9 +450,9 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
if (number_value.is_negative_infinity())
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, "-Infinity"sv));
if (number_value.is_nan())
return PrimitiveString::create(vm, String::from_utf8_short_string("NaN"sv));
return PrimitiveString::create(vm, "NaN"_short_string);
if (number_value.is_positive_zero() || number_value.is_negative_zero())
return PrimitiveString::create(vm, String::from_utf8_short_string("0"sv));
return PrimitiveString::create(vm, "0"_short_string);
double number = number_value.as_double();
bool negative = number < 0;

View file

@ -494,7 +494,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
auto string = TRY(this_object.to_utf16_string(vm));
auto rx = TRY(regexp_create(vm, regexp, PrimitiveString::create(vm, String::from_utf8_short_string("g"sv))));
auto rx = TRY(regexp_create(vm, regexp, PrimitiveString::create(vm, "g"_short_string)));
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_match_all(), PrimitiveString::create(vm, move(string))));
}
@ -509,7 +509,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::normalize)
// 3. If form is undefined, let f be "NFC".
if (auto form_value = vm.argument(0); form_value.is_undefined()) {
form = String::from_utf8_short_string("NFC"sv);
form = "NFC"_short_string;
}
// 4. Else, let f be ? ToString(form).
else {

View file

@ -159,7 +159,7 @@ ThrowCompletionOr<String> to_temporal_overflow(VM& vm, Object const* options)
{
// 1. If options is undefined, return "constrain".
if (options == nullptr)
return TRY_OR_THROW_OOM(vm, String::from_utf8("constrain"sv));
return TRY_OR_THROW_OOM(vm, "constrain"_string);
// 2. Return ? GetOption(options, "overflow", "string", « "constrain", "reject" », "constrain").
auto option = TRY(get_option(vm, *options, vm.names.overflow, OptionType::String, { "constrain"sv, "reject"sv }, "constrain"sv));
@ -173,7 +173,7 @@ ThrowCompletionOr<String> to_temporal_disambiguation(VM& vm, Object const* optio
{
// 1. If options is undefined, return "compatible".
if (options == nullptr)
return TRY_OR_THROW_OOM(vm, String::from_utf8("compatible"sv));
return TRY_OR_THROW_OOM(vm, "compatible"_string);
// 2. Return ? GetOption(options, "disambiguation", "string", « "compatible", "earlier", "later", "reject" », "compatible").
auto option = TRY(get_option(vm, *options, vm.names.disambiguation, OptionType::String, { "compatible"sv, "earlier"sv, "later"sv, "reject"sv }, "compatible"sv));
@ -1269,7 +1269,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM& vm, ParseResult const& pa
}
// 7. Let yearMV be ! ToIntegerOrInfinity(CodePointsToString(year)).
auto year_mv = *normalized_year.value_or(String::from_utf8_short_string("0"sv)).to_number<i32>();
auto year_mv = *normalized_year.value_or("0"_short_string).to_number<i32>();
// 8. If month is empty, then
// a. Let monthMV be 1.
@ -1425,7 +1425,7 @@ ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM& vm, StringV
// 4. If result.[[TimeZone]].[[Z]] is true, then
if (result.time_zone.z) {
// a. Set offsetString to "+00:00".
offset_string = TRY_OR_THROW_OOM(vm, String::from_utf8("+00:00"sv));
offset_string = TRY_OR_THROW_OOM(vm, "+00:00"_string);
}
// 6. Assert: offsetString is not undefined.
@ -1460,7 +1460,7 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(VM& vm, StringView iso_
// b. If calendar is undefined, return "iso8601".
if (!calendar.has_value())
return TRY_OR_THROW_OOM(vm, String::from_utf8("iso8601"sv));
return TRY_OR_THROW_OOM(vm, "iso8601"_string);
// c. Else, return calendar.
else
return calendar.release_value();

View file

@ -99,7 +99,7 @@ ThrowCompletionOr<Calendar*> get_builtin_calendar(VM& vm, String const& identifi
Calendar* get_iso8601_calendar(VM& vm)
{
// 1. Return ! GetBuiltinCalendar("iso8601").
return MUST(get_builtin_calendar(vm, String::from_utf8("iso8601"sv).release_value_but_fixme_should_propagate_errors()));
return MUST(get_builtin_calendar(vm, "iso8601"_string.release_value_but_fixme_should_propagate_errors()));
}
// 12.2.4 CalendarFields ( calendar, fieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-calendarfields
@ -824,10 +824,10 @@ ThrowCompletionOr<ISODateRecord> iso_date_from_fields(VM& vm, Object const& fiel
// 2. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "year", "day" »).
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
{ String::from_utf8_short_string("day"sv),
TRY_OR_THROW_OOM(vm, String::from_utf8("month"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("monthCode"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("year"sv)) },
{ "day"_short_string,
TRY_OR_THROW_OOM(vm, "month"_string),
TRY_OR_THROW_OOM(vm, "monthCode"_string),
TRY_OR_THROW_OOM(vm, "year"_string) },
Vector<StringView> { "year"sv, "day"sv }));
// 3. Let overflow be ? ToTemporalOverflow(options).
@ -859,9 +859,9 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(VM& vm, Object const&
// 2. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », « "year" »).
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
{ TRY_OR_THROW_OOM(vm, String::from_utf8("month"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("monthCode"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("year"sv)) },
{ TRY_OR_THROW_OOM(vm, "month"_string),
TRY_OR_THROW_OOM(vm, "monthCode"_string),
TRY_OR_THROW_OOM(vm, "year"_string) },
Vector<StringView> { "year"sv }));
// 3. Let overflow be ? ToTemporalOverflow(options).
@ -890,10 +890,10 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(VM& vm, Object const& f
// 2. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
{ String::from_utf8_short_string("day"sv),
TRY_OR_THROW_OOM(vm, String::from_utf8("month"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("monthCode"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("year"sv)) },
{ "day"_short_string,
TRY_OR_THROW_OOM(vm, "month"_string),
TRY_OR_THROW_OOM(vm, "monthCode"_string),
TRY_OR_THROW_OOM(vm, "year"_string) },
Vector<StringView> { "day"sv }));
// 3. Let overflow be ? ToTemporalOverflow(options).

View file

@ -216,7 +216,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_until)
// 8. If largestUnit is "auto", set largestUnit to "day".
if (largest_unit == "auto")
largest_unit = String::from_utf8_short_string("day"sv);
largest_unit = "day"_short_string;
// 9. Let result be DifferenceISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], largestUnit).
auto result = difference_iso_date(vm, one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day(), *largest_unit);

View file

@ -369,7 +369,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
smallest_unit_present = false;
// b. Set smallestUnit to "nanosecond".
smallest_unit = TRY_OR_THROW_OOM(vm, String::from_utf8("nanosecond"sv));
smallest_unit = TRY_OR_THROW_OOM(vm, "nanosecond"_string);
}
// 10. Let defaultLargestUnit be ! DefaultTemporalLargestUnit(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]]).

View file

@ -267,7 +267,7 @@ ThrowCompletionOr<String> temporal_instant_to_string(VM& vm, Instant& instant, V
// 8. If timeZone is undefined, then
if (time_zone.is_undefined()) {
// a. Let timeZoneString be "Z".
time_zone_string = String::from_utf8_short_string("Z"sv);
time_zone_string = "Z"_short_string;
}
// 9. Else,
else {

View file

@ -344,12 +344,12 @@ ThrowCompletionOr<TemporalTimeLikeRecord> to_temporal_time_record(VM& vm, Object
// 2. Let partial be ? PrepareTemporalFields(temporalTimeLike, « "hour", "microsecond", "millisecond", "minute", "nanosecond", "second" », partial).
auto* partial = TRY(prepare_temporal_fields(vm, temporal_time_like,
{ TRY_OR_THROW_OOM(vm, String::from_utf8("hour"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("microsecond"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("millisecond"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("minute"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("nanosecond"sv)),
TRY_OR_THROW_OOM(vm, String::from_utf8("second"sv)) },
{ TRY_OR_THROW_OOM(vm, "hour"_string),
TRY_OR_THROW_OOM(vm, "microsecond"_string),
TRY_OR_THROW_OOM(vm, "millisecond"_string),
TRY_OR_THROW_OOM(vm, "minute"_string),
TRY_OR_THROW_OOM(vm, "nanosecond"_string),
TRY_OR_THROW_OOM(vm, "second"_string) },
PrepareTemporalFieldsPartial {}));
TemporalTimeLikeRecord result;

View file

@ -150,10 +150,10 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
auto field_names = TRY(calendar_fields(vm, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// d. Append "timeZone" to fieldNames.
field_names.append(TRY_OR_THROW_OOM(vm, String::from_utf8("timeZone"sv)));
field_names.append(TRY_OR_THROW_OOM(vm, "timeZone"_string));
// e. Append "offset" to fieldNames.
field_names.append(TRY_OR_THROW_OOM(vm, String::from_utf8("offset"sv)));
field_names.append(TRY_OR_THROW_OOM(vm, "offset"_string));
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, « "timeZone" »).
auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector<StringView> { "timeZone"sv }));

View file

@ -769,7 +769,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// 7. Append "offset" to fieldNames.
field_names.append(TRY_OR_THROW_OOM(vm, String::from_utf8("offset"sv)));
field_names.append(TRY_OR_THROW_OOM(vm, "offset"_string));
// 8. Let partialZonedDateTime be ? PrepareTemporalFields(temporalZonedDateTimeLike, fieldNames, partial).
auto* partial_zoned_date_time = TRY(prepare_temporal_fields(vm, temporal_zoned_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
@ -787,7 +787,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
auto& time_zone = zoned_date_time->time_zone();
// 13. Append "timeZone" to fieldNames.
field_names.append(TRY_OR_THROW_OOM(vm, String::from_utf8("timeZone"sv)));
field_names.append(TRY_OR_THROW_OOM(vm, "timeZone"_string));
// 14. Let fields be ? PrepareTemporalFields(zonedDateTime, fieldNames, « "timeZone", "offset" »).
auto* fields = TRY(prepare_temporal_fields(vm, *zoned_date_time, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));

View file

@ -362,11 +362,11 @@ ErrorOr<String> Value::to_string_without_side_effects() const
switch (m_value.tag) {
case UNDEFINED_TAG:
return String::from_utf8("undefined"sv);
return "undefined"_string;
case NULL_TAG:
return String::from_utf8("null"sv);
return "null"_string;
case BOOLEAN_TAG:
return String::from_utf8(as_bool() ? "true"sv : "false"sv);
return as_bool() ? "true"_string : "false"_string;
case INT32_TAG:
return String::number(as_i32());
case STRING_TAG:
@ -389,7 +389,7 @@ ErrorOr<String> Value::to_string_without_side_effects() const
case OBJECT_TAG:
return String::formatted("[object {}]", as_object().class_name());
case ACCESSOR_TAG:
return String::from_utf8("<accessor>"sv);
return "<accessor>"_string;
default:
VERIFY_NOT_REACHED();
}
@ -418,14 +418,14 @@ ThrowCompletionOr<String> Value::to_string(VM& vm) const
return vm.throw_completion<TypeError>(ErrorType::Convert, "symbol", "string");
// 3. If argument is undefined, return "undefined".
case UNDEFINED_TAG:
return TRY_OR_THROW_OOM(vm, String::from_utf8("undefined"sv));
return TRY_OR_THROW_OOM(vm, "undefined"_string);
// 4. If argument is null, return "null".
case NULL_TAG:
return TRY_OR_THROW_OOM(vm, String::from_utf8("null"sv));
return TRY_OR_THROW_OOM(vm, "null"_string);
// 5. If argument is true, return "true".
// 6. If argument is false, return "false".
case BOOLEAN_TAG:
return TRY_OR_THROW_OOM(vm, String::from_utf8(as_bool() ? "true"sv : "false"sv));
return TRY_OR_THROW_OOM(vm, as_bool() ? "true"_string : "false"_string);
// 7. If argument is a Number, return Number::toString(argument, 10).
case INT32_TAG:
return TRY_OR_THROW_OOM(vm, String::number(as_i32()));

View file

@ -29,7 +29,7 @@ ErrorOr<String> PageNode::path() const
ErrorOr<NonnullRefPtr<PageNode>> PageNode::help_index_page()
{
static NonnullRefPtr<PageNode> const help_index_page = TRY(try_make_ref_counted<PageNode>(sections[7 - 1], TRY(String::from_utf8("Help-index"sv))));
static NonnullRefPtr<PageNode> const help_index_page = TRY(try_make_ref_counted<PageNode>(sections[7 - 1], TRY("Help-index"_string)));
return help_index_page;
}

View file

@ -61,9 +61,9 @@ ErrorOr<String> GridSize::to_string() const
case Type::FlexibleLength:
return String::formatted("{}fr", m_flexible_length);
case Type::MaxContent:
return String::from_utf8("max-content"sv);
return "max-content"_string;
case Type::MinContent:
return String::from_utf8("min-content"sv);
return "min-content"_string;
}
VERIFY_NOT_REACHED();
}

View file

@ -117,7 +117,7 @@ ErrorOr<String> Length::to_string() const
if (is_calculated())
return m_calculated_style->to_string();
if (is_auto())
return String::from_utf8("auto"sv);
return "auto"_string;
return String::formatted("{}{}", m_value, unit_name());
}

View file

@ -39,7 +39,7 @@ ErrorOr<String> Token::to_string() const
case Type::Url:
return serialize_a_url(url());
case Type::BadUrl:
return String::from_utf8("url()"sv);
return "url()"_string;
case Type::Delim:
return String { m_value };
case Type::Number:
@ -49,29 +49,29 @@ ErrorOr<String> Token::to_string() const
case Type::Dimension:
return String::formatted("{}{}", m_number_value.value(), dimension_unit());
case Type::Whitespace:
return String::from_utf8_short_string(" "sv);
return " "_short_string;
case Type::CDO:
return String::from_utf8("<!--"sv);
return "<!--"_string;
case Type::CDC:
return String::from_utf8_short_string("-->"sv);
return "-->"_short_string;
case Type::Colon:
return String::from_utf8_short_string(":"sv);
return ":"_short_string;
case Type::Semicolon:
return String::from_utf8_short_string(";"sv);
return ";"_short_string;
case Type::Comma:
return String::from_utf8_short_string(","sv);
return ","_short_string;
case Type::OpenSquare:
return String::from_utf8_short_string("["sv);
return "["_short_string;
case Type::CloseSquare:
return String::from_utf8_short_string("]"sv);
return "]"_short_string;
case Type::OpenParen:
return String::from_utf8_short_string("("sv);
return "("_short_string;
case Type::CloseParen:
return String::from_utf8_short_string(")"sv);
return ")"_short_string;
case Type::OpenCurly:
return String::from_utf8_short_string("{"sv);
return "{"_short_string;
case Type::CloseCurly:
return String::from_utf8_short_string("}"sv);
return "}"_short_string;
case Type::Invalid:
default:
VERIFY_NOT_REACHED();
@ -85,7 +85,7 @@ ErrorOr<String> Token::to_debug_string() const
VERIFY_NOT_REACHED();
case Type::EndOfFile:
return String::from_utf8("__EOF__"sv);
return "__EOF__"_string;
case Type::Ident:
return String::formatted("Ident: {}", ident());
case Type::Function:
@ -97,11 +97,11 @@ ErrorOr<String> Token::to_debug_string() const
case Type::String:
return String::formatted("String: {}", string());
case Type::BadString:
return String::from_utf8("BadString"sv);
return "BadString"_string;
case Type::Url:
return String::formatted("Url: {}", url());
case Type::BadUrl:
return String::from_utf8("BadUrl"sv);
return "BadUrl"_string;
case Type::Delim:
return String::formatted("Delim: {}", m_value);
case Type::Number:
@ -111,29 +111,29 @@ ErrorOr<String> Token::to_debug_string() const
case Type::Dimension:
return String::formatted("Dimension: {}{} (number_type: {})", dimension_value(), dimension_unit(), m_number_value.is_integer() ? "Integer" : "Number");
case Type::Whitespace:
return String::from_utf8("Whitespace"sv);
return "Whitespace"_string;
case Type::CDO:
return String::from_utf8("CDO"sv);
return "CDO"_string;
case Type::CDC:
return String::from_utf8("CDC"sv);
return "CDC"_string;
case Type::Colon:
return String::from_utf8("Colon"sv);
return "Colon"_string;
case Type::Semicolon:
return String::from_utf8("Semicolon"sv);
return "Semicolon"_string;
case Type::Comma:
return String::from_utf8("Comma"sv);
return "Comma"_string;
case Type::OpenSquare:
return String::from_utf8("OpenSquare"sv);
return "OpenSquare"_string;
case Type::CloseSquare:
return String::from_utf8("CloseSquare"sv);
return "CloseSquare"_string;
case Type::OpenParen:
return String::from_utf8("OpenParen"sv);
return "OpenParen"_string;
case Type::CloseParen:
return String::from_utf8("CloseParen"sv);
return "CloseParen"_string;
case Type::OpenCurly:
return String::from_utf8("OpenCurly"sv);
return "OpenCurly"_string;
case Type::CloseCurly:
return String::from_utf8("CloseCurly"sv);
return "CloseCurly"_string;
}
VERIFY_NOT_REACHED();
}

View file

@ -78,18 +78,18 @@ ErrorOr<String> Size::to_string() const
{
switch (m_type) {
case Type::Auto:
return String::from_utf8("auto"sv);
return "auto"_string;
case Type::Length:
case Type::Percentage:
return m_length_percentage.to_string();
case Type::MinContent:
return String::from_utf8("min-content"sv);
return "min-content"_string;
case Type::MaxContent:
return String::from_utf8("max-content"sv);
return "max-content"_string;
case Type::FitContent:
return String::formatted("fit-content({})", TRY(m_length_percentage.to_string()));
case Type::None:
return String::from_utf8("none"sv);
return "none"_string;
}
VERIFY_NOT_REACHED();
}

View file

@ -1591,7 +1591,7 @@ public:
}
virtual ~InheritStyleValue() override = default;
ErrorOr<String> to_string() const override { return String::from_utf8("inherit"sv); }
ErrorOr<String> to_string() const override { return "inherit"_string; }
bool properties_equal(InheritStyleValue const&) const { return true; }
@ -1611,7 +1611,7 @@ public:
}
virtual ~InitialStyleValue() override = default;
ErrorOr<String> to_string() const override { return String::from_utf8("initial"sv); }
ErrorOr<String> to_string() const override { return "initial"_string; }
bool properties_equal(InitialStyleValue const&) const { return true; }
@ -2029,7 +2029,7 @@ public:
}
virtual ~UnsetStyleValue() override = default;
ErrorOr<String> to_string() const override { return String::from_utf8("unset"sv); }
ErrorOr<String> to_string() const override { return "unset"_string; }
bool properties_equal(UnsetStyleValue const&) const { return true; }

View file

@ -599,7 +599,7 @@ void dump_font_face_rule(StringBuilder& builder, CSS::CSSFontFaceRule const& rul
builder.append("sources:\n"sv);
for (auto const& source : font_face.sources()) {
indent(builder, indent_levels + 2);
builder.appendff("url={}, format={}\n", source.url, source.format.value_or(String::from_utf8_short_string("???"sv)));
builder.appendff("url={}, format={}\n", source.url, source.format.value_or("???"_short_string));
}
indent(builder, indent_levels + 1);

View file

@ -35,7 +35,7 @@ WebIDL::ExceptionOr<XHR::FormDataEntry> create_entry(JS::Realm& realm, String co
if (filename.has_value())
name_attribute = filename.value();
else
name_attribute = TRY_OR_THROW_OOM(vm, String::from_utf8("blob"sv));
name_attribute = TRY_OR_THROW_OOM(vm, "blob"_string);
return JS::make_handle(TRY(FileAPI::File::create(realm, { JS::make_handle(*blob) }, name_attribute.to_deprecated_string(), {})));
}));

View file

@ -26,8 +26,8 @@
namespace Web::HTML {
struct WorkerOptions {
String type { String::from_utf8("classic"sv).release_value_but_fixme_should_propagate_errors() };
String credentials { String::from_utf8("same-origin"sv).release_value_but_fixme_should_propagate_errors() };
String type { "classic"_string.release_value_but_fixme_should_propagate_errors() };
String credentials { "same-origin"_string.release_value_but_fixme_should_propagate_errors() };
String name { String {} };
};