From bae8bb0c00ce0f3d77e9d17a2862b875a19655f1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 2 Jul 2021 19:50:27 -0400 Subject: [PATCH] Gives the FAT parser responsibility for right trims. --- Analyser/Static/Enterprise/StaticAnalyser.cpp | 2 +- Storage/Disk/Parsers/FAT.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Analyser/Static/Enterprise/StaticAnalyser.cpp b/Analyser/Static/Enterprise/StaticAnalyser.cpp index 75a19b74d..08cf076b1 100644 --- a/Analyser/Static/Enterprise/StaticAnalyser.cpp +++ b/Analyser/Static/Enterprise/StaticAnalyser.cpp @@ -54,7 +54,7 @@ Analyser::Static::TargetList Analyser::Static::Enterprise::GetTargets(const Medi bool has_exdos_ini = false; bool did_pick_file = false; for(const auto &file: (*volume).root_directory) { - if(insensitive_equal(file.name, "EXDOS ") && insensitive_equal(file.extension, "INI")) { + if(insensitive_equal(file.name, "exdos") && insensitive_equal(file.extension, "ini")) { has_exdos_ini = true; break; } diff --git a/Storage/Disk/Parsers/FAT.cpp b/Storage/Disk/Parsers/FAT.cpp index 2cdd71756..528c73248 100644 --- a/Storage/Disk/Parsers/FAT.cpp +++ b/Storage/Disk/Parsers/FAT.cpp @@ -32,6 +32,14 @@ int FAT::Volume::sector_for_cluster(uint16_t cluster) const { namespace { +template std::string trim(CharT start, CharT end) { + std::string result(start, end); + result.erase(std::find_if(result.rbegin(), result.rend(), [](unsigned char ch) { + return !std::isspace(ch); + }).base(), result.end()); + return result; +} + FAT::Directory directory_from(const std::vector &contents) { FAT::Directory result; @@ -49,8 +57,8 @@ FAT::Directory directory_from(const std::vector &contents) { // Otherwise create and populate a new entry. result.emplace_back(); - result.back().name = std::string(&contents[base], &contents[base+8]); - result.back().extension = std::string(&contents[base+8], &contents[base+11]); + result.back().name = trim(&contents[base], &contents[base+8]); + result.back().extension = trim(&contents[base+8], &contents[base+11]); result.back().attributes = contents[base + 11]; result.back().time = uint16_t(contents[base+22] | (contents[base+23] << 8)); result.back().date = uint16_t(contents[base+24] | (contents[base+25] << 8));