diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2022-07-11 17:32:29 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-12 23:11:35 +0200 |
commit | 3f3f45580ab7266258e97cb3cecf1e24716d61c5 (patch) | |
tree | 152c7a187c98184d58bf91a326357e0af435edcf /Userland/Games/Minesweeper | |
parent | e5f09ea1703bacfbb79a4ad3c587a7d5d3d7bb13 (diff) | |
download | serenity-3f3f45580ab7266258e97cb3cecf1e24716d61c5.zip |
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.
Diffstat (limited to 'Userland/Games/Minesweeper')
-rw-r--r-- | Userland/Games/Minesweeper/Field.cpp | 34 | ||||
-rw-r--r-- | Userland/Games/Minesweeper/Field.h | 10 | ||||
-rw-r--r-- | Userland/Games/Minesweeper/main.cpp | 8 |
3 files changed, 26 insertions, 26 deletions
diff --git a/Userland/Games/Minesweeper/Field.cpp b/Userland/Games/Minesweeper/Field.cpp index df88e1e0a3..ba2b94e193 100644 --- a/Userland/Games/Minesweeper/Field.cpp +++ b/Userland/Games/Minesweeper/Field.cpp @@ -118,13 +118,13 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b m_time_label.set_text(String::formatted("{}.{}", m_time_elapsed / 10, m_time_elapsed % 10)); }; m_timer->set_interval(100); - m_mine_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/mine.png").release_value_but_fixme_should_propagate_errors(); - m_flag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png").release_value_but_fixme_should_propagate_errors(); - m_badflag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/badflag.png").release_value_but_fixme_should_propagate_errors(); - m_consider_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/consider.png").release_value_but_fixme_should_propagate_errors(); - m_default_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-default.png").release_value_but_fixme_should_propagate_errors(); - m_good_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-good.png").release_value_but_fixme_should_propagate_errors(); - m_bad_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-bad.png").release_value_but_fixme_should_propagate_errors(); + m_mine_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/mine.png"sv).release_value_but_fixme_should_propagate_errors(); + m_flag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png"sv).release_value_but_fixme_should_propagate_errors(); + m_badflag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/badflag.png"sv).release_value_but_fixme_should_propagate_errors(); + m_consider_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/consider.png"sv).release_value_but_fixme_should_propagate_errors(); + m_default_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-default.png"sv).release_value_but_fixme_should_propagate_errors(); + m_good_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-good.png"sv).release_value_but_fixme_should_propagate_errors(); + m_bad_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-bad.png"sv).release_value_but_fixme_should_propagate_errors(); for (int i = 0; i < 8; ++i) m_number_bitmap[i] = Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/minesweeper/{}.png", i + 1)).release_value_but_fixme_should_propagate_errors(); // Square with mine will be filled with background color later, i.e. red @@ -137,11 +137,11 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b set_face(Face::Default); { - bool single_chording = Config::read_bool("Minesweeper", "Game", "SingleChording", false); - int mine_count = Config::read_i32("Minesweeper", "Game", "MineCount", 10); - int rows = Config::read_i32("Minesweeper", "Game", "Rows", 9); - int columns = Config::read_i32("Minesweeper", "Game", "Columns", 9); - auto difficulty_string = Config::read_string("Minesweeper", "Game", "Difficulty", "beginner"); + bool single_chording = Config::read_bool("Minesweeper"sv, "Game"sv, "SingleChording"sv, false); + int mine_count = Config::read_i32("Minesweeper"sv, "Game"sv, "MineCount"sv, 10); + int rows = Config::read_i32("Minesweeper"sv, "Game"sv, "Rows"sv, 9); + int columns = Config::read_i32("Minesweeper"sv, "Game"sv, "Columns"sv, 9); + auto difficulty_string = Config::read_string("Minesweeper"sv, "Game"sv, "Difficulty"sv, "beginner"sv); auto difficulty = difficulty_from_string(difficulty_string); // Do a quick sanity check to make sure the user hasn't tried anything crazy @@ -507,10 +507,10 @@ void Field::set_field_size(Difficulty difficulty, size_t rows, size_t columns, s if (m_rows == rows && m_columns == columns && m_mine_count == mine_count) return; { - Config::write_i32("Minesweeper", "Game", "MineCount", mine_count); - Config::write_i32("Minesweeper", "Game", "Rows", rows); - Config::write_i32("Minesweeper", "Game", "Columns", columns); - Config::write_string("Minesweeper", "Game", "Difficulty", difficulty_to_string(difficulty)); + Config::write_i32("Minesweeper"sv, "Game"sv, "MineCount"sv, mine_count); + Config::write_i32("Minesweeper"sv, "Game"sv, "Rows"sv, rows); + Config::write_i32("Minesweeper"sv, "Game"sv, "Columns"sv, columns); + Config::write_string("Minesweeper"sv, "Game"sv, "Difficulty"sv, difficulty_to_string(difficulty)); } m_difficulty = difficulty; m_rows = rows; @@ -524,7 +524,7 @@ void Field::set_field_size(Difficulty difficulty, size_t rows, size_t columns, s void Field::set_single_chording(bool enabled) { m_single_chording = enabled; - Config::write_bool("Minesweeper", "Game", "SingleChording", m_single_chording); + Config::write_bool("Minesweeper"sv, "Game"sv, "SingleChording"sv, m_single_chording); } template<typename Callback> diff --git a/Userland/Games/Minesweeper/Field.h b/Userland/Games/Minesweeper/Field.h index b4d986d42f..13efd998a5 100644 --- a/Userland/Games/Minesweeper/Field.h +++ b/Userland/Games/Minesweeper/Field.h @@ -74,19 +74,19 @@ public: Optional<Difficulty> difficulty_from_string(StringView difficulty_string) const { - if (difficulty_string.matches("beginner")) + if (difficulty_string.matches("beginner"sv)) return Difficulty::Beginner; - if (difficulty_string.equals_ignoring_case("intermediate")) + if (difficulty_string.equals_ignoring_case("intermediate"sv)) return Difficulty::Intermediate; - if (difficulty_string.equals_ignoring_case("expert")) + if (difficulty_string.equals_ignoring_case("expert"sv)) return Difficulty::Expert; - if (difficulty_string.equals_ignoring_case("madwoman")) + if (difficulty_string.equals_ignoring_case("madwoman"sv)) return Difficulty::Madwoman; - if (difficulty_string.equals_ignoring_case("custom")) + if (difficulty_string.equals_ignoring_case("custom"sv)) return Difficulty::Custom; return {}; diff --git a/Userland/Games/Minesweeper/main.cpp b/Userland/Games/Minesweeper/main.cpp index 78e786eddf..2423070239 100644 --- a/Userland/Games/Minesweeper/main.cpp +++ b/Userland/Games/Minesweeper/main.cpp @@ -41,7 +41,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) TRY(Core::System::unveil("/tmp/portal/launch", "rw")); TRY(Core::System::unveil(nullptr, nullptr)); - auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-minesweeper")); + auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-minesweeper"sv)); auto window = TRY(GUI::Window::try_create()); window->set_resizable(false); @@ -63,7 +63,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) container->layout()->add_spacer(); auto flag_image = TRY(container->try_add<GUI::Label>()); - flag_image->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png").release_value_but_fixme_should_propagate_errors()); + flag_image->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png"sv).release_value_but_fixme_should_propagate_errors()); flag_image->set_fixed_width(16); auto flag_label = TRY(container->try_add<GUI::Label>()); @@ -81,7 +81,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto time_image = TRY(container->try_add<GUI::Label>()); time_image->set_fixed_width(16); - time_image->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/timer.png").release_value_but_fixme_should_propagate_errors()); + time_image->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/timer.png"sv).release_value_but_fixme_should_propagate_errors()); auto time_label = TRY(container->try_add<GUI::Label>()); time_label->set_fixed_width(50); @@ -96,7 +96,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto game_menu = TRY(window->try_add_menu("&Game")); - TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) { + TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) { field->reset(); }))); |