mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
Browser: Use format functions instead of printf.
This commit is contained in:
parent
b23f66e151
commit
616af36d91
|
@ -102,7 +102,7 @@ JS::Value BrowserConsoleClient::trace()
|
|||
for (auto& function_name : trace) {
|
||||
if (function_name.is_empty())
|
||||
function_name = "<anonymous>";
|
||||
html.appendf(" -> %s<br>", function_name.characters());
|
||||
html.appendff(" -> {}<br>", function_name);
|
||||
}
|
||||
m_console_widget.print_html(html.string_view());
|
||||
return JS::js_undefined();
|
||||
|
@ -112,7 +112,7 @@ JS::Value BrowserConsoleClient::count()
|
|||
{
|
||||
auto label = vm().argument_count() ? vm().argument(0).to_string_without_side_effects() : "default";
|
||||
auto counter_value = m_console.counter_increment(label);
|
||||
m_console_widget.print_html(String::format("%s: %u", label.characters(), counter_value));
|
||||
m_console_widget.print_html(String::formatted("{}: {}", label, counter_value));
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
|
@ -120,9 +120,9 @@ JS::Value BrowserConsoleClient::count_reset()
|
|||
{
|
||||
auto label = vm().argument_count() ? vm().argument(0).to_string_without_side_effects() : "default";
|
||||
if (m_console.counter_reset(label)) {
|
||||
m_console_widget.print_html(String::format("%s: 0", label.characters()));
|
||||
m_console_widget.print_html(String::formatted("{}: 0", label));
|
||||
} else {
|
||||
m_console_widget.print_html(String::format("\"%s\" doesn't have a count", label.characters()));
|
||||
m_console_widget.print_html(String::formatted("\"{}\" doesn't have a count", label));
|
||||
}
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ ConsoleWidget::ConsoleWidget()
|
|||
auto error = parser.errors()[0];
|
||||
auto hint = error.source_location_hint(js_source);
|
||||
if (!hint.is_empty())
|
||||
output_html.append(String::format("<pre>%s</pre>", escape_html_entities(hint).characters()));
|
||||
output_html.append(String::formatted("<pre>{}</pre>", escape_html_entities(hint)));
|
||||
m_interpreter->vm().throw_exception<JS::SyntaxError>(m_interpreter->global_object(), error.to_string());
|
||||
} else {
|
||||
m_interpreter->run(m_interpreter->global_object(), *program);
|
||||
|
|
|
@ -78,7 +78,7 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
browser_image.load_from_file("/res/graphics/download-animation.gif");
|
||||
animation_layout.add_spacer();
|
||||
|
||||
auto& source_label = add<GUI::Label>(String::format("From: %s", url.to_string().characters()));
|
||||
auto& source_label = add<GUI::Label>(String::formatted("From: {}", url));
|
||||
source_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
source_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
source_label.set_preferred_size(0, 16);
|
||||
|
@ -92,7 +92,7 @@ DownloadWidget::DownloadWidget(const URL& url)
|
|||
m_progress_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
m_progress_label->set_preferred_size(0, 16);
|
||||
|
||||
auto& destination_label = add<GUI::Label>(String::format("To: %s", m_destination_path.characters()));
|
||||
auto& destination_label = add<GUI::Label>(String::formatted("To: {}", m_destination_path));
|
||||
destination_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
destination_label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
destination_label.set_preferred_size(0, 16);
|
||||
|
@ -138,7 +138,7 @@ void DownloadWidget::did_progress(Optional<u32> total_size, u32 downloaded_size)
|
|||
StringBuilder builder;
|
||||
builder.append("Downloaded ");
|
||||
builder.append(human_readable_size(downloaded_size));
|
||||
builder.appendf(" in %d sec", m_elapsed_timer.elapsed() / 1000);
|
||||
builder.appendff(" in {} sec", m_elapsed_timer.elapsed() / 1000);
|
||||
m_progress_label->set_text(builder.to_string());
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ void DownloadWidget::did_progress(Optional<u32> total_size, u32 downloaded_size)
|
|||
StringBuilder builder;
|
||||
if (total_size.has_value()) {
|
||||
int percent = roundf(((float)downloaded_size / (float)total_size.value()) * 100);
|
||||
builder.appendf("%d%%", percent);
|
||||
builder.appendff("{}%", percent);
|
||||
} else {
|
||||
builder.append(human_readable_size(downloaded_size));
|
||||
}
|
||||
|
@ -172,14 +172,14 @@ void DownloadWidget::did_finish(bool success, const ByteBuffer& payload, RefPtr<
|
|||
m_cancel_button->update();
|
||||
|
||||
if (!success) {
|
||||
GUI::MessageBox::show(window(), String::format("Download failed for some reason"), "Download failed", GUI::MessageBox::Type::Error);
|
||||
GUI::MessageBox::show(window(), String::formatted("Download failed for some reason"), "Download failed", GUI::MessageBox::Type::Error);
|
||||
window()->close();
|
||||
return;
|
||||
}
|
||||
|
||||
auto file_or_error = Core::File::open(m_destination_path, Core::IODevice::WriteOnly);
|
||||
if (file_or_error.is_error()) {
|
||||
GUI::MessageBox::show(window(), String::format("Cannot open %s for writing", m_destination_path.characters()), "Download failed", GUI::MessageBox::Type::Error);
|
||||
GUI::MessageBox::show(window(), String::formatted("Cannot open {} for writing", m_destination_path), "Download failed", GUI::MessageBox::Type::Error);
|
||||
window()->close();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -30,10 +30,10 @@ namespace Browser {
|
|||
|
||||
void History::dump() const
|
||||
{
|
||||
dbg() << "Dump " << m_items.size() << " item(s)";
|
||||
dbgf("Dump {} items(s)", m_items.size());
|
||||
int i = 0;
|
||||
for (auto& item : m_items) {
|
||||
dbg() << "[" << i << "] " << item << " " << (m_current == i ? '*' : ' ');
|
||||
dbgf("[{}] {} {}", i, item, m_current == i ? '*' : ' ');
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ static void start_download(const URL& url)
|
|||
{
|
||||
auto window = GUI::Window::construct();
|
||||
window->resize(300, 150);
|
||||
window->set_title(String::format("0%% of %s", url.basename().characters()));
|
||||
window->set_title(String::formatted("0% of {}", url.basename()));
|
||||
window->set_resizable(false);
|
||||
window->set_main_widget<DownloadWidget>(url);
|
||||
window->show();
|
||||
|
@ -504,7 +504,7 @@ void Tab::did_become_active()
|
|||
m_statusbar->set_text("");
|
||||
return;
|
||||
}
|
||||
m_statusbar->set_text(String::format("Loading (%d pending resources...)", Web::ResourceLoader::the().pending_loads()));
|
||||
m_statusbar->set_text(String::formatted("Loading ({} pending resources...)", Web::ResourceLoader::the().pending_loads()));
|
||||
};
|
||||
|
||||
BookmarksBarWidget::the().on_bookmark_click = [this](auto& url, unsigned modifiers) {
|
||||
|
@ -546,4 +546,5 @@ Web::WebViewHooks& Tab::hooks()
|
|||
return *m_page_view;
|
||||
return *m_web_content_view;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ int main(int argc, char** argv)
|
|||
|
||||
tab_widget.on_change = [&](auto& active_widget) {
|
||||
auto& tab = static_cast<Browser::Tab&>(active_widget);
|
||||
window->set_title(String::format("%s - Browser", tab.title().characters()));
|
||||
window->set_title(String::formatted("{} - Browser", tab.title()));
|
||||
tab.did_become_active();
|
||||
};
|
||||
|
||||
|
@ -171,7 +171,7 @@ int main(int argc, char** argv)
|
|||
new_tab.on_title_change = [&](auto title) {
|
||||
tab_widget.set_tab_title(new_tab, title);
|
||||
if (tab_widget.active_widget() == &new_tab)
|
||||
window->set_title(String::format("%s - Browser", title.characters()));
|
||||
window->set_title(String::formatted("{} - Browser", title));
|
||||
};
|
||||
|
||||
new_tab.on_favicon_change = [&](auto& bitmap) {
|
||||
|
@ -193,7 +193,7 @@ int main(int argc, char** argv)
|
|||
|
||||
new_tab.load(url);
|
||||
|
||||
dbg() << "Added new tab " << &new_tab << ", loading " << url;
|
||||
dbgf("Added new tab {:p}, loading {}", &new_tab, url);
|
||||
|
||||
if (activate)
|
||||
tab_widget.set_active_widget(&new_tab);
|
||||
|
|
Loading…
Reference in a new issue