diff options
| author | AltoXorg <56553686+Alto1772@users.noreply.github.com> | 2023-11-14 09:07:32 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-13 20:07:32 -0500 |
| commit | 04b85b95fab07a394b62dcd28a502a3040f08e0c (patch) | |
| tree | 875c0f5bb1caa5bff2878846c00b5dac0f2bbee5 | |
| parent | 0d8f5570a8e57f302ec6633d65615ee21ab39454 (diff) | |
Use substr method to determine file extension (#12)
Alternatively use the "find_last_of" & "substr" methods on this
conveniently and performance wise.
This fixes the "." problem where we are working currently on a
directory that contains ".", which prior to this will get rid of any
occurences of this character from the original path (when using
std::accumulate without a binary operation).
| -rw-r--r-- | OTRExporter/Main.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/OTRExporter/Main.cpp b/OTRExporter/Main.cpp index b6a09cb..4fc3c48 100644 --- a/OTRExporter/Main.cpp +++ b/OTRExporter/Main.cpp @@ -174,15 +174,18 @@ static void ExporterProgramEnd() for (const auto& item : lst) { - std::vector<std::string> splitPath = StringHelper::Split(item, "."); + size_t filenameSepAt = item.find_last_of("/\\"); + const std::string filename = item.substr(filenameSepAt + 1); - if (splitPath.size() >= 3) + if (std::count(filename.begin(), filename.end(), '.') >= 2) { - const std::string extension = splitPath.at(splitPath.size() - 1); - const std::string format = splitPath.at(splitPath.size() - 2); - splitPath.pop_back(); - splitPath.pop_back(); - std::string afterPath = std::accumulate(splitPath.begin(), splitPath.end(), std::string("")); + size_t extensionSepAt = filename.find_last_of("."); + size_t formatSepAt = filename.find_last_of(".", extensionSepAt - 1); + + const std::string extension = filename.substr(extensionSepAt + 1); + const std::string format = filename.substr(formatSepAt + 1, extensionSepAt - formatSepAt - 1); + std::string afterPath = item.substr(0, filenameSepAt + formatSepAt + 1); + if (extension == "png" && (format == "rgba32" || format == "rgb5a1" || format == "i4" || format == "i8" || format == "ia4" || format == "ia8" || format == "ia16" || format == "ci4" || format == "ci8")) { ZTexture tex(nullptr); @@ -208,8 +211,7 @@ static void ExporterProgramEnd() if (item.find("accessibility") != std::string::npos) { - std::string extension = splitPath.at(splitPath.size() - 1); - splitPath.pop_back(); + std::string extension = filename.substr(filename.find_last_of(".") + 1); if (extension == "json") { const auto &fileData = DiskFile::ReadAllBytes(item); |
