fsmgr.cpp: Restore trim_end_spaces as a std::string_view function and use it in place of strtrimrightspace in FS code due to feedback on f5066881db

This commit is contained in:
AJR 2023-09-17 14:08:30 -04:00
parent 01040b1e0c
commit 0c8dbef887
5 changed files with 17 additions and 12 deletions

View File

@ -10,7 +10,6 @@
#include "fs_coco_rsdos.h"
#include "coco_rawdsk.h"
#include "util/corestr.h"
#include "util/strformat.h"
#include <bitset>
@ -415,8 +414,8 @@ meta_data coco_rsdos_impl::get_metadata_from_dirent(const rsdos_dirent &dirent)
std::string coco_rsdos_impl::get_filename_from_dirent(const rsdos_dirent &dirent)
{
std::string_view stem = strtrimrightspace(std::string_view(&dirent.m_filename[0], 8));
std::string_view ext = strtrimrightspace(std::string_view(&dirent.m_filename[8], 3));
std::string_view stem = trim_end_spaces(std::string_view(&dirent.m_filename[0], 8));
std::string_view ext = trim_end_spaces(std::string_view(&dirent.m_filename[8], 3));
return util::string_format("%s.%s", stem, ext);
}

View File

@ -142,9 +142,8 @@
#include "fs_fat.h"
#include "pc_dsk.h"
#include "strformat.h"
#include "util/corestr.h"
#include "util/strformat.h"
using namespace fs;
@ -449,8 +448,8 @@ std::unique_ptr<filesystem_t> fs::fat_image::mount_partition(fsblk_t &blockdev,
std::string directory_entry::name() const
{
std::string_view stem = strtrimrightspace(raw_stem());
std::string_view ext = strtrimrightspace(raw_ext());
std::string_view stem = filesystem_t::trim_end_spaces(raw_stem());
std::string_view ext = filesystem_t::trim_end_spaces(raw_ext());
return !ext.empty()
? util::string_format("%s.%s", stem, ext)
: std::string(stem);
@ -711,8 +710,8 @@ void impl::iterate_directory_entries(const directory_span &dir, const std::funct
if (dirent.raw_stem()[0] != 0x00)
{
// get the filename
std::string_view stem = strtrimrightspace(dirent.raw_stem());
std::string_view ext = strtrimrightspace(dirent.raw_ext());
std::string_view stem = trim_end_spaces(dirent.raw_stem());
std::string_view ext = trim_end_spaces(dirent.raw_ext());
if (ext.empty() && (stem == "." || stem == ".."))
continue;

View File

@ -6,7 +6,6 @@
#include "fs_vtech.h"
#include "vt_dsk.h"
#include "corestr.h"
#include "multibyte.h"
#include <stdexcept>
@ -142,7 +141,7 @@ meta_data vtech_impl::file_metadata(const u8 *entry)
{
meta_data res;
res.set(meta_name::name, strtrimrightspace(rstr(entry+2, 8)));
res.set(meta_name::name, trim_end_spaces(rstr(entry+2, 8)));
res.set(meta_name::basic, entry[0] == 'T');
res.set(meta_name::loading_address, get_u16le(entry + 0xc));
res.set(meta_name::length, ((get_u16le(entry + 0xe) - get_u16le(entry + 0xc) + 1) & 0xffff));
@ -161,7 +160,7 @@ std::tuple<fsblk_t::block_t, u32> vtech_impl::file_find(std::string_view name)
continue;
if(bdir.r8(off+1) != ':')
continue;
if(strtrimrightspace(bdir.rstr(off+2, 8)) == name) {
if(trim_end_spaces(bdir.rstr(off+2, 8)) == name) {
return std::make_tuple(bdir, i);
}
}

View File

@ -231,6 +231,12 @@ std::string_view filesystem_t::rstr(const u8 *p, u32 size)
return std::string_view(reinterpret_cast<const char *>(p), size);
}
std::string_view filesystem_t::trim_end_spaces(std::string_view str)
{
const auto i = str.find_last_not_of(' ');
return str.substr(0, (std::string::npos != i) ? (i + 1) : 0);
}
meta_data filesystem_t::volume_metadata()
{
return meta_data();

View File

@ -257,6 +257,8 @@ public:
static std::string_view rstr(const u8 *p, u32 size);
static std::string_view trim_end_spaces(std::string_view str);
protected:
filesystem_t(fsblk_t &blockdev, u32 size) : m_blockdev(blockdev) {
m_blockdev.set_block_size(size);