From 36ce1f890a9ff63d8faf002298b0f3099780a393 Mon Sep 17 00:00:00 2001 From: frosch Date: Wed, 30 Apr 2025 12:38:02 +0200 Subject: [PATCH] Codechange: Remove c_str, if std::string_view is already accepted. --- src/game/game_text.cpp | 2 +- src/genworld_gui.cpp | 2 +- src/landscape.cpp | 2 +- src/network/network.cpp | 2 +- src/newgrf_gui.cpp | 4 ++-- src/openttd.cpp | 2 +- src/settings.cpp | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp index 5e29fa6c86..1ba23ba89f 100644 --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -96,7 +96,7 @@ struct StringListReader : StringReader { * @param translation Are we reading a translation? */ StringListReader(StringData &data, const LanguageStrings &strings, bool master, bool translation) : - StringReader(data, strings.language.c_str(), master, translation), p(strings.lines.begin()), end(strings.lines.end()) + StringReader(data, strings.language, master, translation), p(strings.lines.begin()), end(strings.lines.end()) { } diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 7b911ff6d7..31e23303b4 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -1000,7 +1000,7 @@ static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode) if (mode == GLWM_HEIGHTMAP) { /* If the function returns negative, it means there was a problem loading the heightmap */ - if (!GetHeightmapDimensions(_file_to_saveload.ftype.detailed, _file_to_saveload.name.c_str(), &x, &y)) return; + if (!GetHeightmapDimensions(_file_to_saveload.ftype.detailed, _file_to_saveload.name, &x, &y)) return; } WindowDesc &desc = (mode == GLWM_HEIGHTMAP) ? _heightmap_load_desc : _generate_landscape_desc; diff --git a/src/landscape.cpp b/src/landscape.cpp index 7865895cab..2d0abb44db 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1540,7 +1540,7 @@ bool GenerateLandscape(uint8_t mode) if (mode == GWM_HEIGHTMAP) { SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP); - if (!LoadHeightmap(_file_to_saveload.ftype.detailed, _file_to_saveload.name.c_str())) { + if (!LoadHeightmap(_file_to_saveload.ftype.detailed, _file_to_saveload.name)) { return false; } IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); diff --git a/src/network/network.cpp b/src/network/network.cpp index df0eaa5302..0054cd5a6e 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -718,7 +718,7 @@ NetworkGame *NetworkAddServer(std::string_view connection_string, bool manually, void GetBindAddresses(NetworkAddressList *addresses, uint16_t port) { for (const auto &iter : _network_bind_list) { - addresses->emplace_back(iter.c_str(), port); + addresses->emplace_back(iter, port); } /* No address, so bind to everything. */ diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index de39414872..2296518438 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1155,7 +1155,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { this->preset = index; if (index != -1) { - this->actives = LoadGRFPresetFromConfig(this->grf_presets[index].c_str()); + this->actives = LoadGRFPresetFromConfig(this->grf_presets[index]); } this->avails.ForceRebuild(); @@ -1170,7 +1170,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { { if (!str.has_value()) return; - SaveGRFPresetToConfig(str->c_str(), this->actives); + SaveGRFPresetToConfig(*str, this->actives); this->grf_presets = GetGRFPresetList(); /* Switch to this preset */ diff --git a/src/openttd.cpp b/src/openttd.cpp index d7022468d6..b2f2064bfb 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1186,7 +1186,7 @@ void SwitchToMode(SwitchMode new_mode) break; case SM_SAVE_HEIGHTMAP: // Save heightmap. - MakeHeightmapScreenshot(_file_to_saveload.name.c_str()); + MakeHeightmapScreenshot(_file_to_saveload.name); CloseWindowById(WC_SAVELOAD, 0); break; diff --git a/src/settings.cpp b/src/settings.cpp index 7a86bfa46a..b050667d42 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1125,7 +1125,7 @@ static GRFConfigList GRFLoadConfig(const IniFile &ini, std::string_view grpname, } ShowErrorMessage(GetEncodedString(STR_CONFIG_ERROR), - GetEncodedString(STR_CONFIG_ERROR_INVALID_GRF, filename.empty() ? item.name.c_str() : filename, reason), + GetEncodedString(STR_CONFIG_ERROR_INVALID_GRF, filename.empty() ? item.name : filename, reason), WL_CRITICAL); continue; } @@ -1559,7 +1559,7 @@ GRFConfigList LoadGRFPresetFromConfig(std::string_view config_name) section += config_name; ConfigIniFile ini(_config_file); - GRFConfigList config = GRFLoadConfig(ini, section.c_str(), false); + GRFConfigList config = GRFLoadConfig(ini, section, false); return config; } @@ -1576,7 +1576,7 @@ void SaveGRFPresetToConfig(std::string_view config_name, GRFConfigList &config) section += config_name; ConfigIniFile ini(_config_file); - GRFSaveConfig(ini, section.c_str(), config); + GRFSaveConfig(ini, section, config); ini.SaveToDisk(_config_file); }