Codechange: Redundant use of char * and c_str(). (#11454)

wip-string
Peter Nelson 7 months ago committed by GitHub
parent 938c8339d2
commit 1071acb483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -106,19 +106,19 @@ struct BaseSet {
* @param isocode the isocode to search for * @param isocode the isocode to search for
* @return the description * @return the description
*/ */
const char *GetDescription(const std::string &isocode) const const std::string &GetDescription(const std::string &isocode) const
{ {
if (!isocode.empty()) { if (!isocode.empty()) {
/* First the full ISO code */ /* First the full ISO code */
auto desc = this->description.find(isocode); 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 */ /* Then the first two characters */
desc = this->description.find(isocode.substr(0, 2)); 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 */ /* Then fall back */
return this->description.at(std::string{}).c_str(); return this->description.at(std::string{});
} }
/** /**

@ -125,11 +125,11 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
*/ */
virtual void UpdateVirtCoord() = 0; 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(); if (this->cached_name.empty()) this->FillCachedName();
return this->cached_name.c_str(); return this->cached_name;
} }
virtual void MoveSign(TileIndex new_xy) virtual void MoveSign(TileIndex new_xy)

@ -326,7 +326,7 @@ void LoadCoreTextFont(FontSize fs)
path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8)); path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8));
} else { } else {
/* Scan the search-paths to see if it can be found. */ /* 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()) { if (!full_font.empty()) {
path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8)); path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8));
} }

@ -46,7 +46,7 @@ ScriptStorage::~ScriptStorage()
static void PrintFunc(bool error_msg, const std::string &message) static void PrintFunc(bool error_msg, const std::string &message)
{ {
/* Convert to OpenTTD internal capable string */ /* Convert to OpenTTD internal capable string */
ScriptController::Print(error_msg, message.c_str()); ScriptController::Print(error_msg, message);
} }
ScriptInstance::ScriptInstance(const char *APIName) : ScriptInstance::ScriptInstance(const char *APIName) :

@ -1552,7 +1552,7 @@ void DeleteGRFPresetFromConfig(const char *config_name)
section += config_name; section += config_name;
ConfigIniFile ini(_config_file); ConfigIniFile ini(_config_file);
ini.RemoveGroup(section.c_str()); ini.RemoveGroup(section);
ini.SaveToDisk(_config_file); ini.SaveToDisk(_config_file);
} }

@ -79,7 +79,7 @@ struct FileStringReader : StringReader {
* @param translation Are we reading a translation? * @param translation Are we reading a translation?
*/ */
FileStringReader(StringData &data, const std::filesystem::path &file, bool master, bool 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); this->input_stream.open(file, std::ifstream::binary);
} }

Loading…
Cancel
Save