diff src/core/filesystem.cpp @ 59:327e9a5c72f1

filesystem: add basename and stem functions
author Paper <mrpapersonic@gmail.com>
date Thu, 28 Sep 2023 13:45:45 -0400
parents 4b05bc7668eb
children d417e9381ca5
line wrap: on
line diff
--- 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) {