summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/file.cpp23
-rw-r--r--src/lib/file.h13
2 files changed, 36 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 );
+}
diff --git a/src/lib/file.h b/src/lib/file.h
new file mode 100644
index 0000000..85c8852
--- /dev/null
+++ b/src/lib/file.h
@@ -0,0 +1,13 @@
+using namespace std;
+
+#include <string>
+#include <vector>
+#include <iostream>
+
+class file {
+ public:
+ string name;
+ vector<string> dirs;
+
+ file( string );
+};

Generated by cgit