Mercurial > minori
changeset 59:327e9a5c72f1
filesystem: add basename and stem functions
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 28 Sep 2023 13:45:45 -0400 |
parents | b7a1c0010ffd |
children | d417e9381ca5 |
files | include/core/filesystem.h src/core/filesystem.cpp |
diffstat | 2 files changed, 18 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/include/core/filesystem.h Thu Sep 28 13:32:21 2023 -0400 +++ b/include/core/filesystem.h Thu Sep 28 13:45:45 2023 -0400 @@ -4,9 +4,11 @@ namespace Filesystem { -bool CreateDirectories(std::string path); -bool Exists(std::string path); -std::string GetParentDirectory(std::string path); +bool CreateDirectories(const std::string& path); +bool Exists(const std::string& path); +std::string Basename(const std::string& path); +std::string Stem(const std::string& path); +std::string GetParentDirectory(const std::string& path); std::string GetDotPath(); // %APPDATA%/minori, ~/Library/Application Support/minori, ~/.config/minori... std::string GetConfigPath(); // (dotpath)/config.json std::string GetAnimeDBPath(); // (dotpath)/anime/db.json
--- a/src/core/filesystem.cpp Thu Sep 28 13:32:21 2023 -0400 +++ b/src/core/filesystem.cpp Thu Sep 28 13:45:45 2023 -0400 @@ -22,7 +22,7 @@ namespace Filesystem { -bool CreateDirectories(std::string path) { +bool CreateDirectories(const std::string& path) { std::string temp = ""; size_t start; size_t end = 0; @@ -45,7 +45,7 @@ return true; } -bool Exists(std::string path) { +bool Exists(const std::string& path) { #if WIN32 return GetFileAttributes(path.c_str()) != INVALID_FILE_ATTRIBUTES; #else @@ -54,10 +54,17 @@ #endif } -std::string GetParentDirectory(std::string path) { - size_t pos = 0; - pos = path.find_last_of(DELIM); - return path.substr(0, pos); +std::string Basename(const std::string& path) { + return path.substr(0, path.find_last_of(DELIM)); +} + +std::string Stem(const std::string& path) { + std::string basename = Basename(path); + return basename.substr(0, path.find_last_of(".")); +} + +std::string GetParentDirectory(const std::string& path) { + return path.substr(0, path.find_last_of(DELIM)); } std::string GetDotPath(void) {