summaryrefslogtreecommitdiff
path: root/libs/pbd3/basename.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/pbd3/basename.cc')
-rw-r--r--libs/pbd3/basename.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/libs/pbd3/basename.cc b/libs/pbd3/basename.cc
new file mode 100644
index 0000000000..b8c5c64d91
--- /dev/null
+++ b/libs/pbd3/basename.cc
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <string.h>
+#include <pbd/basename.h>
+
+char *
+PBD::basename (const char *path)
+
+{
+ char *slash;
+
+ if ((slash = strrchr (path, '/')) == 0) {
+ return strdup (path);
+ }
+
+ if (*(slash+1) == '\0') {
+ return strdup ("");
+ }
+
+ return strdup (slash+1);
+}
+
+std::string
+PBD::basename (const std::string str)
+{
+ std::string::size_type slash = str.find_last_of ('/');
+
+ if (slash == std::string::npos) {
+ return str;
+ }
+
+ return str.substr (slash+1);
+}
+
+std::string
+PBD::basename_nosuffix (const std::string str)
+{
+ std::string::size_type slash = str.find_last_of ('/');
+ std::string noslash;
+
+ if (slash == std::string::npos) {
+ noslash = str;
+ } else {
+ noslash = str.substr (slash+1);
+ }
+
+ return noslash.substr (0, noslash.find_last_of ('.'));
+}