1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

Everywhere: Add sv suffix to strings relying on StringView(char const*)

Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
This commit is contained in:
sin-ack 2022-07-11 17:32:29 +00:00 committed by Andreas Kling
parent e5f09ea170
commit 3f3f45580a
762 changed files with 8315 additions and 8316 deletions

View file

@ -18,9 +18,9 @@ DOMTreeModel::DOMTreeModel(JsonObject dom_tree, GUI::TreeView& tree_view)
: m_tree_view(tree_view)
, m_dom_tree(move(dom_tree))
{
m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-html.png").release_value_but_fixme_should_propagate_errors());
m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png").release_value_but_fixme_should_propagate_errors());
m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-unknown.png").release_value_but_fixme_should_propagate_errors());
m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-html.png"sv).release_value_but_fixme_should_propagate_errors());
m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png"sv).release_value_but_fixme_should_propagate_errors());
m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-unknown.png"sv).release_value_but_fixme_should_propagate_errors());
map_dom_nodes_to_parent(nullptr, &m_dom_tree);
}
@ -116,8 +116,8 @@ static String with_whitespace_collapsed(StringView string)
GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
{
auto const& node = *static_cast<JsonObject const*>(index.internal_data());
auto node_name = node.get("name").as_string();
auto type = node.get("type").as_string_or("unknown");
auto node_name = node.get("name"sv).as_string();
auto type = node.get("type"sv).as_string_or("unknown"sv);
if (role == GUI::ModelRole::ForegroundColor) {
// FIXME: Allow models to return a foreground color *role*.
@ -126,7 +126,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
return m_tree_view.palette().syntax_comment();
if (type == "pseudo-element"sv)
return m_tree_view.palette().syntax_type();
if (!node.get("visible").to_bool(true))
if (!node.get("visible"sv).to_bool(true))
return m_tree_view.palette().syntax_comment();
return {};
}
@ -141,7 +141,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
}
if (role == GUI::ModelRole::Display) {
if (type == "text")
return with_whitespace_collapsed(node.get("text").as_string());
return with_whitespace_collapsed(node.get("text"sv).as_string());
if (type == "comment"sv)
return String::formatted("<!--{}-->", node.get("data"sv).as_string());
if (type != "element")
@ -150,8 +150,8 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
StringBuilder builder;
builder.append('<');
builder.append(node_name.to_lowercase());
if (node.has("attributes")) {
auto attributes = node.get("attributes").as_object();
if (node.has("attributes"sv)) {
auto attributes = node.get("attributes"sv).as_object();
attributes.for_each_member([&builder](auto& name, JsonValue const& value) {
builder.append(' ');
builder.append(name);
@ -170,7 +170,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
void DOMTreeModel::map_dom_nodes_to_parent(JsonObject const* parent, JsonObject const* node)
{
m_dom_node_to_parent_map.set(node, parent);
m_node_id_to_dom_node_map.set(node->get("id").to_i32(), node);
m_node_id_to_dom_node_map.set(node->get("id"sv).to_i32(), node);
auto const* children = get_children(*node);
if (!children)
@ -191,10 +191,10 @@ GUI::ModelIndex DOMTreeModel::index_for_node(i32 node_id, Optional<Web::CSS::Sel
auto node_children = get_children(*node);
for (size_t i = 0; i < node_children->size(); i++) {
auto& child = node_children->at(i).as_object();
if (!child.has("pseudo-element"))
if (!child.has("pseudo-element"sv))
continue;
auto child_pseudo_element = child.get("pseudo-element");
auto child_pseudo_element = child.get("pseudo-element"sv);
if (!child_pseudo_element.is_i32())
continue;
@ -214,7 +214,7 @@ GUI::ModelIndex DOMTreeModel::index_for_node(i32 node_id, Optional<Web::CSS::Sel
}
}
dbgln("Didn't find index for node {}, pseudo-element {}!", node_id, pseudo_element.has_value() ? Web::CSS::pseudo_element_name(pseudo_element.value()) : "NONE");
dbgln("Didn't find index for node {}, pseudo-element {}!", node_id, pseudo_element.has_value() ? Web::CSS::pseudo_element_name(pseudo_element.value()) : "NONE"sv);
return {};
}

View file

@ -45,7 +45,7 @@ private:
ALWAYS_INLINE static JsonArray const* get_children(JsonObject const& o)
{
if (auto const* maybe_children = o.get_ptr("children"); maybe_children)
if (auto const* maybe_children = o.get_ptr("children"sv); maybe_children)
return &maybe_children->as_array();
return nullptr;
}

View file

@ -43,17 +43,17 @@ void OutOfProcessWebView::handle_web_content_process_crash()
handle_resize();
StringBuilder builder;
builder.append("<html><head><title>Crashed: ");
builder.append("<html><head><title>Crashed: "sv);
builder.append(escape_html_entities(m_url.to_string()));
builder.append("</title></head><body>");
builder.append("<h1>Web page crashed");
builder.append("</title></head><body>"sv);
builder.append("<h1>Web page crashed"sv);
if (!m_url.host().is_empty()) {
builder.appendff(" on {}", escape_html_entities(m_url.host()));
}
builder.append("</h1>");
builder.append("</h1>"sv);
auto escaped_url = escape_html_entities(m_url.to_string());
builder.appendff("The web page <a href=\"{}\">{}</a> has crashed.<br><br>You can reload the page to try again.", escaped_url, escaped_url);
builder.append("</body></html>");
builder.append("</body></html>"sv);
load_html(builder.to_string(), m_url);
}
@ -329,19 +329,19 @@ void OutOfProcessWebView::notify_server_did_request_image_context_menu(Badge<Web
void OutOfProcessWebView::notify_server_did_request_alert(Badge<WebContentClient>, String const& message)
{
GUI::MessageBox::show(window(), message, "Alert", GUI::MessageBox::Type::Information);
GUI::MessageBox::show(window(), message, "Alert"sv, GUI::MessageBox::Type::Information);
}
bool OutOfProcessWebView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
{
auto confirm_result = GUI::MessageBox::show(window(), message, "Confirm", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel);
auto confirm_result = GUI::MessageBox::show(window(), message, "Confirm"sv, GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel);
return confirm_result == GUI::Dialog::ExecResult::OK;
}
String OutOfProcessWebView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
{
String response { default_ };
if (GUI::InputBox::show(window(), response, message, "Prompt") == GUI::InputBox::ExecResult::OK)
if (GUI::InputBox::show(window(), response, message, "Prompt"sv) == GUI::InputBox::ExecResult::OK)
return response;
return {};
}