From aaed751bf4430bf4b9b30cef532b8753b9f639ce Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Sep 2025 13:48:31 +0500 Subject: Replace most of C strings with string_view --- core/resource/binfile.cc | 8 ++++---- core/resource/image.cc | 8 ++++---- core/resource/resource.hh | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'core/resource') diff --git a/core/resource/binfile.cc b/core/resource/binfile.cc index b8e3db8..726ef9b 100644 --- a/core/resource/binfile.cc +++ b/core/resource/binfile.cc @@ -7,16 +7,16 @@ static emhash8::HashMap> resource_map; template<> -resource_ptr resource::load(const char* name, unsigned int flags) +resource_ptr resource::load(std::string_view name, unsigned int flags) { - auto it = resource_map.find(name); + auto it = resource_map.find(std::string(name)); if(it != resource_map.cend()) { // Return an existing resource return it->second; } - auto file = PHYSFS_openRead(name); + auto file = PHYSFS_openRead(std::string(name).c_str()); if(file == nullptr) { spdlog::warn("resource: {}: {}", name, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); @@ -30,7 +30,7 @@ resource_ptr resource::load(const char* name, unsigned int fla PHYSFS_readBytes(file, new_resource->buffer, new_resource->size); PHYSFS_close(file); - return resource_map.insert_or_assign(name, new_resource).first->second; + return resource_map.insert_or_assign(std::string(name), new_resource).first->second; } template<> diff --git a/core/resource/image.cc b/core/resource/image.cc index 9ff0206..8b570e4 100644 --- a/core/resource/image.cc +++ b/core/resource/image.cc @@ -23,16 +23,16 @@ static int stbi_physfs_eof(void* context) } template<> -resource_ptr resource::load(const char* name, unsigned int flags) +resource_ptr resource::load(std::string_view name, unsigned int flags) { - auto it = resource_map.find(name); + auto it = resource_map.find(std::string(name)); if(it != resource_map.cend()) { // Return an existing resource return it->second; } - auto file = PHYSFS_openRead(name); + auto file = PHYSFS_openRead(std::string(name).c_str()); if(file == nullptr) { spdlog::warn("resource: {}: {}", name, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); @@ -74,7 +74,7 @@ resource_ptr resource::load(const char* name, unsigned int flags) return nullptr; } - return resource_map.insert_or_assign(name, new_resource).first->second; + return resource_map.insert_or_assign(std::string(name), new_resource).first->second; } template<> diff --git a/core/resource/resource.hh b/core/resource/resource.hh index 4946ffa..5b6b2ac 100644 --- a/core/resource/resource.hh +++ b/core/resource/resource.hh @@ -8,7 +8,7 @@ using resource_ptr = std::shared_ptr; namespace resource { template -resource_ptr load(const char* name, unsigned int flags = 0U); +resource_ptr load(std::string_view name, unsigned int flags = 0U); template void hard_cleanup(void); template -- cgit