Userland: Prefer _short_string over String::from_utf8_short_string

This user-defined literal is a strictly equivalent but shorter alias to
`String::from_utf8_short_string`.
This commit is contained in:
Lucas CHOLLET 2023-08-07 22:01:45 -04:00 committed by Andreas Kling
parent 66645cdc94
commit a5edc9cdfc
Notes: sideshowbarker 2024-07-17 18:13:59 +09:00
7 changed files with 8 additions and 8 deletions

View file

@ -60,7 +60,7 @@ ErrorOr<void> BackgroundSettingsWidget::create_frame()
m_wallpaper_view->set_model(GUI::FileSystemModel::create("/res/wallpapers"));
m_wallpaper_view->set_model_column(GUI::FileSystemModel::Column::Name);
m_wallpaper_view->on_selection_change = [this] {
String path = String::from_utf8_short_string(""sv);
String path;
if (!m_wallpaper_view->selection().is_empty()) {
auto index = m_wallpaper_view->selection().first();
auto path_or_error = String::from_deprecated_string(static_cast<GUI::FileSystemModel*>(m_wallpaper_view->model())->full_path(index));

View file

@ -123,7 +123,7 @@ HelpWindow::HelpWindow(GUI::Window* parent)
widget->add_sheet(sheet.release_nonnull());
window->show();
} else if (url.host() == String::from_utf8_short_string("doc"sv)) {
} else if (url.host() == "doc"_short_string) {
auto entry = LexicalPath::basename(url.serialize_path());
m_webview->load(URL::create_with_data("text/html"sv, render(entry)));
} else {

View file

@ -264,7 +264,7 @@ Optional<Position> Sheet::position_from_url(const URL& url) const
return {};
}
if (url.scheme() != "spreadsheet" || url.host() != String::from_utf8_short_string("cell"sv)) {
if (url.scheme() != "spreadsheet" || url.host() != "cell"_short_string) {
dbgln("Bad url: {}", url.to_deprecated_string());
return {};
}
@ -757,7 +757,7 @@ URL Position::to_url(Sheet const& sheet) const
{
URL url;
url.set_scheme("spreadsheet");
url.set_host(String::from_utf8_short_string("cell"sv));
url.set_host("cell"_short_string);
url.set_paths({ DeprecatedString::number(getpid()) });
url.set_fragment(to_cell_identifier(sheet));
return url;

View file

@ -82,7 +82,7 @@ ErrorOr<NonnullRefPtr<PageNode const>> Node::try_create_from_query(Vector<String
ErrorOr<NonnullRefPtr<Node const>> Node::try_find_from_help_url(URL const& url)
{
if (url.host() != String::from_utf8_short_string("man"sv))
if (url.host() != "man"_short_string)
return Error::from_string_view("Bad help operation"sv);
if (url.path_segment_count() < 2)
return Error::from_string_view("Bad help page URL"sv);

View file

@ -1142,7 +1142,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::navigate(
} else {
// Otherwise let navigation id be the result of generating a random UUID. [UUID]
// FIXME: Generate a UUID.
navigation_id = String::from_utf8_short_string("FIXME"sv);
navigation_id = "FIXME"_short_string;
}
}

View file

@ -191,7 +191,7 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no
return RecursionDecision::Recurse;
}
if (url.scheme() == "help") {
if (url.host() != String::from_utf8_short_string("man"sv)) {
if (url.host() != "man"_short_string) {
warnln("help:// URL without 'man': {}", href);
m_has_invalid_link = true;
return RecursionDecision::Recurse;

View file

@ -138,7 +138,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto get_formatted_user = [&](i32 uid) -> ErrorOr<String> {
if (uid == -1)
return String::from_utf8_short_string("-"sv);
return "-"_short_string;
return String::number(uid);
};