1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-20 02:42:42 +01:00

Codechange: use std::string_view over const char *

This commit is contained in:
Rubidium
2025-04-27 17:17:05 +02:00
committed by rubidium42
parent c7056866a3
commit 29ceaf0a84
12 changed files with 27 additions and 27 deletions

View File

@@ -672,20 +672,20 @@ static ScenarioScanner _scanner;
* Find a given scenario based on its unique ID.
* @param ci The content info to compare it to.
* @param md5sum Whether to look at the md5sum or the id.
* @return The filename of the file, else \c nullptr.
* @return The filename of the file, else \c std::nullopt.
*/
const char *FindScenario(const ContentInfo &ci, bool md5sum)
std::optional<std::string_view> FindScenario(const ContentInfo &ci, bool md5sum)
{
_scanner.Scan(false);
for (ScenarioIdentifier &id : _scanner) {
if (md5sum ? (id.md5sum == ci.md5sum)
: (id.scenid == ci.unique_id)) {
return id.filename.c_str();
return id.filename;
}
}
return nullptr;
return std::nullopt;
}
/**
@@ -696,7 +696,7 @@ const char *FindScenario(const ContentInfo &ci, bool md5sum)
*/
bool HasScenario(const ContentInfo &ci, bool md5sum)
{
return (FindScenario(ci, md5sum) != nullptr);
return FindScenario(ci, md5sum).has_value();
}
/**