From 0d0b406acfa66cc6f70e4e6aefa21932df1e2c19 Mon Sep 17 00:00:00 2001 From: x1nixmzeng Date: Fri, 13 Feb 2015 00:26:02 +0000 Subject: [PATCH] Resolving entry names Some more string manipulation fluff --- src/poly/string.cc | 24 ++++++++++++++++++++++++ src/poly/string.h | 3 +++ src/xenia/kernel/fs/entry.cc | 3 +-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/poly/string.cc b/src/poly/string.cc index 322f12dfb..de2b0b254 100644 --- a/src/poly/string.cc +++ b/src/poly/string.cc @@ -126,4 +126,28 @@ std::string fix_path_separators(const std::string& source, char new_sep) { return dest; } +std::string find_name_from_path(const std::string& path) +{ + std::string name(path); + + if (!path.empty()) { + std::string::size_type from(std::string::npos); + if (path.back() == '\\') { + from = path.size() - 2; + } + + auto pos(path.find_last_of('\\', from)); + if (pos != std::string::npos) { + if (from == std::string::npos) { + name = path.substr(pos + 1); + } else { + auto len(from - pos); + name = path.substr(pos + 1, len); + } + } + } + + return name; +} + } // namespace poly diff --git a/src/poly/string.h b/src/poly/string.h index 789710bd0..7609d2f8e 100644 --- a/src/poly/string.h +++ b/src/poly/string.h @@ -48,6 +48,9 @@ std::wstring fix_path_separators(const std::wstring& source, std::string fix_path_separators(const std::string& source, char new_sep = poly::path_separator); +// Find the top directory name or filename from a path +std::string find_name_from_path(const std::string& path); + } // namespace poly #endif // POLY_STRING_H_ diff --git a/src/xenia/kernel/fs/entry.cc b/src/xenia/kernel/fs/entry.cc index 3989e0992..490487bda 100644 --- a/src/xenia/kernel/fs/entry.cc +++ b/src/xenia/kernel/fs/entry.cc @@ -23,8 +23,7 @@ Entry::Entry(Device* device, const std::string& path) : device_(device), path_(path) { assert_not_null(device); absolute_path_ = device->path() + path; - // TODO(benvanik): last index of \, unless \ at end, then before that - name_ = ""; + name_ = poly::find_name_from_path(path); } Entry::~Entry() = default;