summaryrefslogtreecommitdiff
path: root/src/lib/file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/file.cpp')
-rw-r--r--src/lib/file.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/file.cpp b/src/lib/file.cpp
new file mode 100644
index 0000000..6b18277
--- /dev/null
+++ b/src/lib/file.cpp
@@ -0,0 +1,23 @@
+#include "file.h"
+
+file::file( string p ) {
+ // Parse path into parent dir array and filename
+ long cur_dir_begin = 0;
+ for( int i = 0; i < p.length(); i++ ) {
+ int cur_char = p[i];
+ int delim = '/';
+ // Parse the directories out of the path
+ // Skip the first if it's an absolute path
+ if( i == 0 && cur_char == delim ) {
+ // Do nothing
+ } else if( cur_char == delim ) {
+ // Check if we've hit a path delimiter (/ or \)
+ dirs.push_back( p.substr( cur_dir_begin, i - cur_dir_begin ) );
+ // Skip the slash since we don't need it
+ i++;
+ cur_dir_begin = i;
+ }
+ }
+ // Annnnnd output the filename...for now
+ name = p.substr( cur_dir_begin, p.length() - cur_dir_begin );
+}

Generated by cgit