mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 18:37:35 +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:
parent
e5f09ea170
commit
3f3f45580a
762 changed files with 8315 additions and 8316 deletions
|
@ -20,7 +20,7 @@
|
|||
|
||||
ChessWidget::ChessWidget()
|
||||
{
|
||||
set_piece_set("stelar7");
|
||||
set_piece_set("stelar7"sv);
|
||||
}
|
||||
|
||||
void ChessWidget::paint_event(GUI::PaintEvent& event)
|
||||
|
@ -248,46 +248,46 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event)
|
|||
|
||||
if (board().game_result() != Chess::Board::Result::NotFinished) {
|
||||
bool over = true;
|
||||
String msg;
|
||||
StringView msg;
|
||||
switch (board().game_result()) {
|
||||
case Chess::Board::Result::CheckMate:
|
||||
if (board().turn() == Chess::Color::White) {
|
||||
msg = "Black wins by Checkmate.";
|
||||
msg = "Black wins by Checkmate."sv;
|
||||
} else {
|
||||
msg = "White wins by Checkmate.";
|
||||
msg = "White wins by Checkmate."sv;
|
||||
}
|
||||
break;
|
||||
case Chess::Board::Result::StaleMate:
|
||||
msg = "Draw by Stalemate.";
|
||||
msg = "Draw by Stalemate."sv;
|
||||
break;
|
||||
case Chess::Board::Result::FiftyMoveRule:
|
||||
update();
|
||||
if (GUI::MessageBox::show(window(), "50 moves have elapsed without a capture. Claim Draw?", "Claim Draw?",
|
||||
if (GUI::MessageBox::show(window(), "50 moves have elapsed without a capture. Claim Draw?"sv, "Claim Draw?"sv,
|
||||
GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::YesNo)
|
||||
== GUI::Dialog::ExecResult::Yes) {
|
||||
msg = "Draw by 50 move rule.";
|
||||
msg = "Draw by 50 move rule."sv;
|
||||
} else {
|
||||
over = false;
|
||||
}
|
||||
break;
|
||||
case Chess::Board::Result::SeventyFiveMoveRule:
|
||||
msg = "Draw by 75 move rule.";
|
||||
msg = "Draw by 75 move rule."sv;
|
||||
break;
|
||||
case Chess::Board::Result::ThreeFoldRepetition:
|
||||
update();
|
||||
if (GUI::MessageBox::show(window(), "The same board state has repeated three times. Claim Draw?", "Claim Draw?",
|
||||
if (GUI::MessageBox::show(window(), "The same board state has repeated three times. Claim Draw?"sv, "Claim Draw?"sv,
|
||||
GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::YesNo)
|
||||
== GUI::Dialog::ExecResult::Yes) {
|
||||
msg = "Draw by threefold repetition.";
|
||||
msg = "Draw by threefold repetition."sv;
|
||||
} else {
|
||||
over = false;
|
||||
}
|
||||
break;
|
||||
case Chess::Board::Result::FiveFoldRepetition:
|
||||
msg = "Draw by fivefold repetition.";
|
||||
msg = "Draw by fivefold repetition."sv;
|
||||
break;
|
||||
case Chess::Board::Result::InsufficientMaterial:
|
||||
msg = "Draw by insufficient material.";
|
||||
msg = "Draw by insufficient material."sv;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
|
@ -296,7 +296,7 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event)
|
|||
set_override_cursor(Gfx::StandardCursor::None);
|
||||
set_drag_enabled(false);
|
||||
update();
|
||||
GUI::MessageBox::show(window(), msg, "Game Over", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window(), msg, "Game Over"sv, GUI::MessageBox::Type::Information);
|
||||
}
|
||||
} else {
|
||||
input_engine_move();
|
||||
|
@ -377,18 +377,18 @@ static RefPtr<Gfx::Bitmap> get_piece(StringView set, StringView image)
|
|||
void ChessWidget::set_piece_set(StringView set)
|
||||
{
|
||||
m_piece_set = set;
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Pawn }, get_piece(set, "white-pawn.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Pawn }, get_piece(set, "black-pawn.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Knight }, get_piece(set, "white-knight.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Knight }, get_piece(set, "black-knight.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Bishop }, get_piece(set, "white-bishop.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Bishop }, get_piece(set, "black-bishop.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Rook }, get_piece(set, "white-rook.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Rook }, get_piece(set, "black-rook.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Queen }, get_piece(set, "white-queen.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Queen }, get_piece(set, "black-queen.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::King }, get_piece(set, "white-king.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::King }, get_piece(set, "black-king.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Pawn }, get_piece(set, "white-pawn.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Pawn }, get_piece(set, "black-pawn.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Knight }, get_piece(set, "white-knight.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Knight }, get_piece(set, "black-knight.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Bishop }, get_piece(set, "white-bishop.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Bishop }, get_piece(set, "black-bishop.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Rook }, get_piece(set, "white-rook.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Rook }, get_piece(set, "black-rook.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Queen }, get_piece(set, "white-queen.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Queen }, get_piece(set, "black-queen.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::King }, get_piece(set, "white-king.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::King }, get_piece(set, "black-king.png"sv));
|
||||
}
|
||||
|
||||
Chess::Square ChessWidget::mouse_to_square(GUI::MouseEvent& event) const
|
||||
|
@ -436,7 +436,7 @@ void ChessWidget::set_board_theme(StringView name)
|
|||
} else if (name == "Blue") {
|
||||
m_board_theme = { "Blue", Color::from_rgb(0x8ca2ad), Color::from_rgb(0xdee3e6) };
|
||||
} else {
|
||||
set_board_theme("Beige");
|
||||
set_board_theme("Beige"sv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -596,15 +596,15 @@ bool ChessWidget::import_pgn(StringView import_path)
|
|||
if (token.contains("*"))
|
||||
break;
|
||||
// FIXME: When we become able to set more of the game state, fix these end results
|
||||
if (token.contains("1-0")) {
|
||||
if (token.contains("1-0"sv)) {
|
||||
m_board.set_resigned(Chess::Color::Black);
|
||||
break;
|
||||
}
|
||||
if (token.contains("0-1")) {
|
||||
if (token.contains("0-1"sv)) {
|
||||
m_board.set_resigned(Chess::Color::White);
|
||||
break;
|
||||
}
|
||||
if (token.contains("1/2-1/2")) {
|
||||
if (token.contains("1/2-1/2"sv)) {
|
||||
break;
|
||||
}
|
||||
if (!token.ends_with(".")) {
|
||||
|
@ -633,24 +633,24 @@ bool ChessWidget::export_pgn(StringView export_path) const
|
|||
auto& file = *file_or_error.value();
|
||||
|
||||
// Tag Pair Section
|
||||
file.write("[Event \"Casual Game\"]\n");
|
||||
file.write("[Site \"SerenityOS Chess\"]\n");
|
||||
file.write(String::formatted("[Date \"{}\"]\n", Core::DateTime::now().to_string("%Y.%m.%d")));
|
||||
file.write("[Round \"1\"]\n");
|
||||
file.write("[Event \"Casual Game\"]\n"sv);
|
||||
file.write("[Site \"SerenityOS Chess\"]\n"sv);
|
||||
file.write(String::formatted("[Date \"{}\"]\n", Core::DateTime::now().to_string("%Y.%m.%d"sv)));
|
||||
file.write("[Round \"1\"]\n"sv);
|
||||
|
||||
String username(getlogin());
|
||||
const String player1 = (!username.is_empty() ? username : "?");
|
||||
const String player2 = (!m_engine.is_null() ? "SerenityOS ChessEngine" : "?");
|
||||
const String player1 = (!username.is_empty() ? username.view() : "?"sv);
|
||||
const String player2 = (!m_engine.is_null() ? "SerenityOS ChessEngine"sv : "?"sv);
|
||||
file.write(String::formatted("[White \"{}\"]\n", m_side == Chess::Color::White ? player1 : player2));
|
||||
file.write(String::formatted("[Black \"{}\"]\n", m_side == Chess::Color::Black ? player1 : player2));
|
||||
|
||||
file.write(String::formatted("[Result \"{}\"]\n", Chess::Board::result_to_points(m_board.game_result(), m_board.turn())));
|
||||
file.write("[WhiteElo \"?\"]\n");
|
||||
file.write("[BlackElo \"?\"]\n");
|
||||
file.write("[Variant \"Standard\"]\n");
|
||||
file.write("[TimeControl \"-\"]\n");
|
||||
file.write("[Annotator \"SerenityOS Chess\"]\n");
|
||||
file.write("\n");
|
||||
file.write("[WhiteElo \"?\"]\n"sv);
|
||||
file.write("[BlackElo \"?\"]\n"sv);
|
||||
file.write("[Variant \"Standard\"]\n"sv);
|
||||
file.write("[TimeControl \"-\"]\n"sv);
|
||||
file.write("[Annotator \"SerenityOS Chess\"]\n"sv);
|
||||
file.write("\n"sv);
|
||||
|
||||
// Movetext Section
|
||||
for (size_t i = 0, move_no = 1; i < m_board.moves().size(); i += 2, move_no++) {
|
||||
|
@ -664,11 +664,11 @@ bool ChessWidget::export_pgn(StringView export_path) const
|
|||
}
|
||||
}
|
||||
|
||||
file.write("{ ");
|
||||
file.write("{ "sv);
|
||||
file.write(Chess::Board::result_to_string(m_board.game_result(), m_board.turn()));
|
||||
file.write(" } ");
|
||||
file.write(" } "sv);
|
||||
file.write(Chess::Board::result_to_points(m_board.game_result(), m_board.turn()));
|
||||
file.write("\n");
|
||||
file.write("\n"sv);
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
|
@ -677,7 +677,7 @@ bool ChessWidget::export_pgn(StringView export_path) const
|
|||
void ChessWidget::flip_board()
|
||||
{
|
||||
if (want_engine_move()) {
|
||||
GUI::MessageBox::show(window(), "You can only flip the board on your turn.", "Flip Board", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window(), "You can only flip the board on your turn."sv, "Flip Board"sv, GUI::MessageBox::Type::Information);
|
||||
return;
|
||||
}
|
||||
m_side = Chess::opposing_color(m_side);
|
||||
|
@ -688,11 +688,11 @@ void ChessWidget::flip_board()
|
|||
int ChessWidget::resign()
|
||||
{
|
||||
if (want_engine_move()) {
|
||||
GUI::MessageBox::show(window(), "You can only resign on your turn.", "Resign", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window(), "You can only resign on your turn."sv, "Resign"sv, GUI::MessageBox::Type::Information);
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto result = GUI::MessageBox::show(window(), "Are you sure you wish to resign?", "Resign", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNo);
|
||||
auto result = GUI::MessageBox::show(window(), "Are you sure you wish to resign?"sv, "Resign"sv, GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNo);
|
||||
if (result != GUI::MessageBox::ExecResult::Yes)
|
||||
return -1;
|
||||
|
||||
|
@ -701,7 +701,7 @@ int ChessWidget::resign()
|
|||
set_drag_enabled(false);
|
||||
update();
|
||||
const String msg = Chess::Board::result_to_string(m_board.game_result(), m_board.turn());
|
||||
GUI::MessageBox::show(window(), msg, "Game Over", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window(), msg, "Game Over"sv, GUI::MessageBox::Type::Information);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
TRY(Core::System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec"));
|
||||
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-chess"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-chess"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
auto widget = TRY(window->try_set_main_widget<ChessWidget>());
|
||||
|
@ -42,10 +42,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/bin/ChessEngine", "x"));
|
||||
TRY(Core::System::unveil("/etc/passwd", "r"));
|
||||
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
|
||||
TRY(Core::System::unveil(Core::StandardPaths::home_directory().characters(), "wcbr"));
|
||||
TRY(Core::System::unveil(Core::StandardPaths::home_directory(), "wcbr"sv));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto size = Config::read_i32("Chess", "Display", "size", 512);
|
||||
auto size = Config::read_i32("Chess"sv, "Display"sv, "size"sv, 512);
|
||||
window->set_title("Chess");
|
||||
window->set_base_size({ 4, 4 });
|
||||
window->set_size_increment({ 8, 8 });
|
||||
|
@ -53,10 +53,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
||||
widget->set_piece_set(Config::read_string("Chess", "Style", "PieceSet", "stelar7"));
|
||||
widget->set_board_theme(Config::read_string("Chess", "Style", "BoardTheme", "Beige"));
|
||||
widget->set_coordinates(Config::read_bool("Chess", "Style", "Coordinates", true));
|
||||
widget->set_show_available_moves(Config::read_bool("Chess", "Style", "ShowAvailableMoves", true));
|
||||
widget->set_piece_set(Config::read_string("Chess"sv, "Style"sv, "PieceSet"sv, "stelar7"sv));
|
||||
widget->set_board_theme(Config::read_string("Chess"sv, "Style"sv, "BoardTheme"sv, "Beige"sv));
|
||||
widget->set_coordinates(Config::read_bool("Chess"sv, "Style"sv, "Coordinates"sv, true));
|
||||
widget->set_show_available_moves(Config::read_bool("Chess"sv, "Style"sv, "ShowAvailableMoves"sv, true));
|
||||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
|
@ -75,7 +75,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return;
|
||||
|
||||
if (!widget->import_pgn(import_path.value())) {
|
||||
GUI::MessageBox::show(window, "Unable to import game.\n", "Error", GUI::MessageBox::Type::Error);
|
||||
GUI::MessageBox::show(window, "Unable to import game.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return;
|
||||
|
||||
if (!widget->export_pgn(export_path.value())) {
|
||||
GUI::MessageBox::show(window, "Unable to export game.\n", "Error", GUI::MessageBox::Type::Error);
|
||||
GUI::MessageBox::show(window, "Unable to export game.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -96,11 +96,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
})));
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&Copy FEN", { Mod_Ctrl, Key_C }, [&](auto&) {
|
||||
GUI::Clipboard::the().set_data(widget->get_fen().bytes());
|
||||
GUI::MessageBox::show(window, "Board state copied to clipboard as FEN.", "Copy FEN", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window, "Board state copied to clipboard as FEN."sv, "Copy FEN"sv, GUI::MessageBox::Type::Information);
|
||||
})));
|
||||
TRY(game_menu->try_add_separator());
|
||||
|
||||
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&) {
|
||||
if (widget->board().game_result() == Chess::Board::Result::NotFinished) {
|
||||
if (widget->resign() < 0)
|
||||
return;
|
||||
|
@ -124,7 +124,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto action = GUI::Action::create_checkable(set, [&](auto& action) {
|
||||
widget->set_piece_set(action.text());
|
||||
widget->update();
|
||||
Config::write_string("Chess", "Style", "PieceSet", action.text());
|
||||
Config::write_string("Chess"sv, "Style"sv, "PieceSet"sv, action.text());
|
||||
});
|
||||
|
||||
piece_set_action_group.add_action(*action);
|
||||
|
@ -136,13 +136,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
GUI::ActionGroup board_theme_action_group;
|
||||
board_theme_action_group.set_exclusive(true);
|
||||
auto board_theme_menu = TRY(style_menu->try_add_submenu("Board Theme"));
|
||||
board_theme_menu->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/chess/mini-board.png").release_value_but_fixme_should_propagate_errors());
|
||||
board_theme_menu->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/chess/mini-board.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
for (auto const& theme : { "Beige", "Green", "Blue" }) {
|
||||
auto action = GUI::Action::create_checkable(theme, [&](auto& action) {
|
||||
widget->set_board_theme(action.text());
|
||||
widget->update();
|
||||
Config::write_string("Chess", "Style", "BoardTheme", action.text());
|
||||
Config::write_string("Chess"sv, "Style"sv, "BoardTheme"sv, action.text());
|
||||
});
|
||||
board_theme_action_group.add_action(*action);
|
||||
if (widget->board_theme().name == theme)
|
||||
|
@ -153,7 +153,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto coordinates_action = GUI::Action::create_checkable("Coordinates", [&](auto& action) {
|
||||
widget->set_coordinates(action.is_checked());
|
||||
widget->update();
|
||||
Config::write_bool("Chess", "Style", "Coordinates", action.is_checked());
|
||||
Config::write_bool("Chess"sv, "Style"sv, "Coordinates"sv, action.is_checked());
|
||||
});
|
||||
coordinates_action->set_checked(widget->coordinates());
|
||||
TRY(style_menu->try_add_action(coordinates_action));
|
||||
|
@ -161,7 +161,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto show_available_moves_action = GUI::Action::create_checkable("Show Available Moves", [&](auto& action) {
|
||||
widget->set_show_available_moves(action.is_checked());
|
||||
widget->update();
|
||||
Config::write_bool("Chess", "Style", "ShowAvailableMoves", action.is_checked());
|
||||
Config::write_bool("Chess"sv, "Style"sv, "ShowAvailableMoves"sv, action.is_checked());
|
||||
});
|
||||
show_available_moves_action->set_checked(widget->show_available_moves());
|
||||
TRY(style_menu->try_add_action(show_available_moves_action));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue