Skip to content

Commit

Permalink
Resolving entry names
Browse files Browse the repository at this point in the history
Some more string manipulation fluff
  • Loading branch information
x1nixmzeng committed Feb 13, 2015
1 parent dc731f6 commit 0d0b406
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/poly/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/poly/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
3 changes: 1 addition & 2 deletions src/xenia/kernel/fs/entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0d0b406

Please sign in to comment.