From 1071acb4831be15b1e671bec15bee058b5bef6f9 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 10 Nov 2023 00:17:36 +0000 Subject: [PATCH] Codechange: Redundant use of char * and c_str(). (#11454) --- src/base_media_base.h | 8 ++++---- src/base_station_base.h | 6 +++--- src/os/macosx/font_osx.cpp | 2 +- src/script/script_instance.cpp | 2 +- src/settings.cpp | 2 +- src/strgen/strgen.cpp | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/base_media_base.h b/src/base_media_base.h index 0875996103..6321b48339 100644 --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -106,19 +106,19 @@ struct BaseSet { * @param isocode the isocode to search for * @return the description */ - const char *GetDescription(const std::string &isocode) const + const std::string &GetDescription(const std::string &isocode) const { if (!isocode.empty()) { /* First the full ISO code */ auto desc = this->description.find(isocode); - if (desc != this->description.end()) return desc->second.c_str(); + if (desc != this->description.end()) return desc->second; /* Then the first two characters */ desc = this->description.find(isocode.substr(0, 2)); - if (desc != this->description.end()) return desc->second.c_str(); + if (desc != this->description.end()) return desc->second; } /* Then fall back */ - return this->description.at(std::string{}).c_str(); + return this->description.at(std::string{}); } /** diff --git a/src/base_station_base.h b/src/base_station_base.h index 5a76744a17..82b6c967b2 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -125,11 +125,11 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { */ virtual void UpdateVirtCoord() = 0; - inline const char *GetCachedName() const + inline const std::string &GetCachedName() const { - if (!this->name.empty()) return this->name.c_str(); + if (!this->name.empty()) return this->name; if (this->cached_name.empty()) this->FillCachedName(); - return this->cached_name.c_str(); + return this->cached_name; } virtual void MoveSign(TileIndex new_xy) diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index 2eed279c1d..a9fad3764a 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -326,7 +326,7 @@ void LoadCoreTextFont(FontSize fs) path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8)); } else { /* Scan the search-paths to see if it can be found. */ - std::string full_font = FioFindFullPath(BASE_DIR, settings->font.c_str()); + std::string full_font = FioFindFullPath(BASE_DIR, settings->font); if (!full_font.empty()) { path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8)); } diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 84a9ee3a70..42d536b028 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -46,7 +46,7 @@ ScriptStorage::~ScriptStorage() static void PrintFunc(bool error_msg, const std::string &message) { /* Convert to OpenTTD internal capable string */ - ScriptController::Print(error_msg, message.c_str()); + ScriptController::Print(error_msg, message); } ScriptInstance::ScriptInstance(const char *APIName) : diff --git a/src/settings.cpp b/src/settings.cpp index bbf603413a..5e8c0b266f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1552,7 +1552,7 @@ void DeleteGRFPresetFromConfig(const char *config_name) section += config_name; ConfigIniFile ini(_config_file); - ini.RemoveGroup(section.c_str()); + ini.RemoveGroup(section); ini.SaveToDisk(_config_file); } diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index ce8f98517f..49ca24087e 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -79,7 +79,7 @@ struct FileStringReader : StringReader { * @param translation Are we reading a translation? */ FileStringReader(StringData &data, const std::filesystem::path &file, bool master, bool translation) : - StringReader(data, file.generic_string().c_str(), master, translation) + StringReader(data, file.generic_string(), master, translation) { this->input_stream.open(file, std::ifstream::binary); }