Codechange: add std::string_view variant of FileHandle::Open

This commit is contained in:
Rubidium
2025-04-28 18:35:16 +02:00
committed by rubidium42
parent 2c4897c2cd
commit 9107c3f6c6
4 changed files with 8 additions and 6 deletions

View File

@@ -1166,13 +1166,13 @@ uint FileScanner::Scan(const std::string_view extension, const std::string &dire
* @param mode Mode to open file.
* @return FileHandle, or std::nullopt on failure.
*/
std::optional<FileHandle> FileHandle::Open(const std::string &filename, const std::string &mode)
std::optional<FileHandle> FileHandle::Open(const std::string &filename, std::string_view mode)
{
#if defined(_WIN32)
/* Windows also requires mode to be wchar_t. */
auto f = _wfopen(OTTD2FS(filename).c_str(), OTTD2FS(mode).c_str());
#else
auto f = fopen(filename.c_str(), mode.c_str());
auto f = fopen(filename.c_str(), std::string{mode}.c_str());
#endif /* _WIN32 */
if (f == nullptr) return std::nullopt;