diff --git a/components/bsa/ba2dx10file.cpp b/components/bsa/ba2dx10file.cpp index b0d999d77e..c0922d905c 100644 --- a/components/bsa/ba2dx10file.cpp +++ b/components/bsa/ba2dx10file.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -146,13 +147,13 @@ namespace Bsa mIsLoaded = true; } - std::optional BA2DX10File::getFileRecord(const std::string& str) const + std::optional BA2DX10File::getFileRecord(std::string_view str) const { for (const auto c : str) { if (((static_cast(c) >> 7U) & 1U) != 0U) { - fail("File record " + str + " contains unicode characters, refusing to load."); + fail(std::format("File record {} contains unicode characters, refusing to load.", str)); } } @@ -162,7 +163,7 @@ namespace Bsa // Force-convert the path into something UNIX can handle first // to make sure std::filesystem::path doesn't think the entire path is the filename on Linux // and subsequently purge it to determine the file folder. - std::string path = str; + std::string path(str); std::replace(path.begin(), path.end(), '\\', '/'); #endif diff --git a/components/bsa/ba2dx10file.hpp b/components/bsa/ba2dx10file.hpp index c902a4ccb0..a10a0c4740 100644 --- a/components/bsa/ba2dx10file.hpp +++ b/components/bsa/ba2dx10file.hpp @@ -41,7 +41,7 @@ namespace Bsa std::list> mFileNames; - std::optional getFileRecord(const std::string& str) const; + std::optional getFileRecord(std::string_view str) const; Files::IStreamPtr getFile(const FileRecord& fileRecord); diff --git a/components/bsa/ba2gnrlfile.cpp b/components/bsa/ba2gnrlfile.cpp index 4f77fba5f7..fec7b9a255 100644 --- a/components/bsa/ba2gnrlfile.cpp +++ b/components/bsa/ba2gnrlfile.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -137,13 +138,13 @@ namespace Bsa mIsLoaded = true; } - BA2GNRLFile::FileRecord BA2GNRLFile::getFileRecord(const std::string& str) const + BA2GNRLFile::FileRecord BA2GNRLFile::getFileRecord(std::string_view str) const { for (const auto c : str) { if (((static_cast(c) >> 7U) & 1U) != 0U) { - fail("File record " + str + " contains unicode characters, refusing to load."); + fail(std::format("File record {} contains unicode characters, refusing to load.", str)); } } @@ -153,7 +154,7 @@ namespace Bsa // Force-convert the path into something UNIX can handle first // to make sure std::filesystem::path doesn't think the entire path is the filename on Linux // and subsequently purge it to determine the file folder. - std::string path = str; + std::string path(str); std::replace(path.begin(), path.end(), '\\', '/'); #endif diff --git a/components/bsa/ba2gnrlfile.hpp b/components/bsa/ba2gnrlfile.hpp index 080ba3a8df..bc1de65d98 100644 --- a/components/bsa/ba2gnrlfile.hpp +++ b/components/bsa/ba2gnrlfile.hpp @@ -29,7 +29,7 @@ namespace Bsa std::list> mFileNames; - FileRecord getFileRecord(const std::string& str) const; + FileRecord getFileRecord(std::string_view str) const; Files::IStreamPtr getFile(const FileRecord& fileRecord); diff --git a/components/bsa/bsafile.hpp b/components/bsa/bsafile.hpp index af7d101eb0..c091e38548 100644 --- a/components/bsa/bsafile.hpp +++ b/components/bsa/bsafile.hpp @@ -68,18 +68,11 @@ namespace Bsa uint32_t mFileSize = 0; uint32_t mOffset = 0; Hash mHash{}; - - // Zero-terminated file name - const char* name() const - { - if (mNameSize == 0) - return ""; - return mNamesBuffer->data() + mNameOffset; - } - uint32_t mNameOffset = 0; uint32_t mNameSize = 0; std::vector* mNamesBuffer = nullptr; + + std::string_view name() const { return std::string_view(mNamesBuffer->data() + mNameOffset, mNameSize); } }; typedef std::vector FileList; @@ -153,7 +146,6 @@ namespace Bsa // checks version of BSA from file header static BsaVersion detectVersion(const std::filesystem::path& filePath); }; - } #endif diff --git a/components/bsa/compressedbsafile.cpp b/components/bsa/compressedbsafile.cpp index cbcb6aeeab..6cf8c366a3 100644 --- a/components/bsa/compressedbsafile.cpp +++ b/components/bsa/compressedbsafile.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -193,13 +194,13 @@ namespace Bsa mIsLoaded = true; } - CompressedBSAFile::FileRecord CompressedBSAFile::getFileRecord(const std::string& str) const + CompressedBSAFile::FileRecord CompressedBSAFile::getFileRecord(std::string_view str) const { for (const auto c : str) { if (((static_cast(c) >> 7U) & 1U) != 0U) { - fail("File record " + str + " contains unicode characters, refusing to load."); + fail(std::format("File record {} contains unicode characters, refusing to load.", str)); } } @@ -209,7 +210,7 @@ namespace Bsa // Force-convert the path into something UNIX can handle first // to make sure std::filesystem::path doesn't think the entire path is the filename on Linux // and subsequently purge it to determine the file folder. - std::string path = str; + std::string path(str); std::replace(path.begin(), path.end(), '\\', '/'); #endif diff --git a/components/bsa/compressedbsafile.hpp b/components/bsa/compressedbsafile.hpp index 1e359ea3fe..9610e88f73 100644 --- a/components/bsa/compressedbsafile.hpp +++ b/components/bsa/compressedbsafile.hpp @@ -108,7 +108,7 @@ namespace Bsa std::map mFolders; - FileRecord getFileRecord(const std::string& str) const; + FileRecord getFileRecord(std::string_view str) const; /// \brief Normalizes given filename or folder and generates format-compatible hash. static std::uint64_t generateHash(const std::filesystem::path& stem, std::string extension);