From f005548d560c1e628ae5d6dffb58adabba709f85 Mon Sep 17 00:00:00 2001 From: asynts Date: Tue, 6 Oct 2020 15:02:05 +0200 Subject: [PATCH] Spreadsheet: Use new format functions. In a few places I also simplified a few format strings: -outln("{} item{}", items, items.size() == 1 ? ' ' : 's'); +outln("{} item(s)", items); In my opinion this is more readable and in some places it incorrectly wrote '0 item' which is "fixed" now. In other places the placeholder space looked weird. --- Applications/Spreadsheet/CellTypeDialog.cpp | 4 ++-- Applications/Spreadsheet/HelpWindow.cpp | 10 +++++----- Applications/Spreadsheet/Spreadsheet.cpp | 15 +++++++-------- Applications/Spreadsheet/SpreadsheetWidget.cpp | 6 +++--- Applications/Spreadsheet/main.cpp | 2 +- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Applications/Spreadsheet/CellTypeDialog.cpp b/Applications/Spreadsheet/CellTypeDialog.cpp index 77e3d038e1..1a3d681c83 100644 --- a/Applications/Spreadsheet/CellTypeDialog.cpp +++ b/Applications/Spreadsheet/CellTypeDialog.cpp @@ -56,9 +56,9 @@ CellTypeDialog::CellTypeDialog(const Vector& positions, Sheet& sheet, StringBuilder builder; if (positions.size() == 1) - builder.appendf("Format Cell %s%zu", positions.first().column.characters(), positions.first().row); + builder.appendff("Format Cell {}{}", positions.first().column, positions.first().row); else - builder.appendf("Format %zu Cells", positions.size()); + builder.appendff("Format {} Cells", positions.size()); set_title(builder.string_view()); resize(285, 360); diff --git a/Applications/Spreadsheet/HelpWindow.cpp b/Applications/Spreadsheet/HelpWindow.cpp index b59c745b5e..7d5ba0e58d 100644 --- a/Applications/Spreadsheet/HelpWindow.cpp +++ b/Applications/Spreadsheet/HelpWindow.cpp @@ -132,21 +132,21 @@ String HelpWindow::render(const GUI::ModelIndex& index) markdown_builder.append("# ARGUMENTS\n"); if (argc > 0) - markdown_builder.appendf("%d required argument%s: \n", argc, argc > 1 ? "s" : ""); + markdown_builder.appendff("{} required argument(s):\n", argc); else markdown_builder.appendf("No required arguments.\n"); for (size_t i = 0; i < argc; ++i) - markdown_builder.appendf("- `%s`\n", argnames.at(i).to_string().characters()); + markdown_builder.appendff("- `{}`\n", argnames.at(i).to_string()); if (argc > 0) markdown_builder.append("\n"); if ((size_t)argnames.size() > argc) { auto opt_count = argnames.size() - argc; - markdown_builder.appendf("%d optional argument%s: \n", opt_count, opt_count > 1 ? "s" : ""); + markdown_builder.appendff("{} optional argument(s):\n", opt_count); for (size_t i = argc; i < (size_t)argnames.size(); ++i) - markdown_builder.appendf("- `%s`\n", argnames.at(i).to_string().characters()); + markdown_builder.appendff("- `{}`\n", argnames.at(i).to_string()); markdown_builder.append("\n"); } @@ -157,7 +157,7 @@ String HelpWindow::render(const GUI::ModelIndex& index) if (!examples.is_empty()) { markdown_builder.append("# EXAMPLES\n"); examples.for_each_member([&](auto& text, auto& description_value) { - markdown_builder.appendf("- %s\n\n```js\n%s\n```\n", description_value.to_string().characters(), text.characters()); + markdown_builder.appendf("- {}\n\n```js\n{}\n```\n", description_value.to_string(), text); }); } diff --git a/Applications/Spreadsheet/Spreadsheet.cpp b/Applications/Spreadsheet/Spreadsheet.cpp index 2e871d4624..1bfb2299ec 100644 --- a/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Applications/Spreadsheet/Spreadsheet.cpp @@ -64,16 +64,15 @@ Sheet::Sheet(Workbook& workbook) auto buffer = file_or_error.value()->read_all(); JS::Parser parser { JS::Lexer(buffer) }; if (parser.has_errors()) { - dbg() << "Spreadsheet: Failed to parse runtime code"; + dbgln("Spreadsheet: Failed to parse runtime code"); for (auto& error : parser.errors()) - dbg() << "Error: " << error.to_string() << "\n" - << error.source_location_hint(buffer); + dbgln("Error: {}\n{}", error.to_string(), error.source_location_hint(buffer)); } else { interpreter().run(global_object(), parser.parse_program()); if (auto exc = interpreter().exception()) { - dbg() << "Spreadsheet: Failed to run runtime code: "; + dbgln("Spreadsheet: Failed to run runtime code: "); for (auto& t : exc->trace()) - dbg() << t; + dbgln("{}", t); interpreter().vm().clear_exception(); } } @@ -331,7 +330,7 @@ JsonObject Sheet::to_json() const for (auto& it : m_cells) { StringBuilder builder; builder.append(it.key.column); - builder.appendf("%zu", it.key.row); + builder.appendff("{}", it.key.row); auto key = builder.to_string(); JsonObject data; @@ -399,7 +398,7 @@ JsonObject Sheet::gather_documentation() const if (!value_object.has_own_property(doc_name)) return; - dbg() << "Found '" << it.key.to_display_string() << "'"; + dbgln("Found '{}'", it.key.to_display_string()); auto doc = value_object.get(doc_name); if (!doc.is_string()) return; @@ -410,7 +409,7 @@ JsonObject Sheet::gather_documentation() const if (doc_object.has_value()) object.set(it.key.to_display_string(), doc_object.value()); else - dbg() << "Sheet::gather_documentation(): Failed to parse the documentation for '" << it.key.to_display_string() << "'!"; + dbgln("Sheet::gather_documentation(): Failed to parse the documentation for '{}'!", it.key.to_display_string()); }; for (auto& it : interpreter().global_object().shape().property_table()) diff --git a/Applications/Spreadsheet/SpreadsheetWidget.cpp b/Applications/Spreadsheet/SpreadsheetWidget.cpp index 1b5fec57fa..548be961d7 100644 --- a/Applications/Spreadsheet/SpreadsheetWidget.cpp +++ b/Applications/Spreadsheet/SpreadsheetWidget.cpp @@ -104,7 +104,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector new_sheets) auto& position = selection.first(); StringBuilder builder; builder.append(position.column); - builder.appendf("%zu", position.row); + builder.appendff("{}", position.row); m_current_cell_label->set_enabled(true); m_current_cell_label->set_text(builder.string_view()); @@ -121,7 +121,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector new_sheets) // There are many cells selected, change all of them. StringBuilder builder; - builder.appendf("<%zu>", selection.size()); + builder.appendff("<{}>", selection.size()); m_current_cell_label->set_enabled(true); m_current_cell_label->set_text(builder.string_view()); @@ -184,7 +184,7 @@ void SpreadsheetWidget::add_sheet() { StringBuilder name; name.append("Sheet"); - name.appendf(" %d", m_workbook->sheets().size() + 1); + name.appendff(" {}", m_workbook->sheets().size() + 1); auto& sheet = m_workbook->add_sheet(name.string_view()); diff --git a/Applications/Spreadsheet/main.cpp b/Applications/Spreadsheet/main.cpp index e38a7d40dd..79612bd87a 100644 --- a/Applications/Spreadsheet/main.cpp +++ b/Applications/Spreadsheet/main.cpp @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) if (filename) { if (!Core::File::exists(filename) || Core::File::is_directory(filename)) { - fprintf(stderr, "File does not exist or is a directory: %s\n", filename); + warnln("File does not exist or is a directory: {}", filename); return 1; } }