summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNullspoon <nullspoon@iohq.net>2014-08-26 20:45:16 -0600
committerNullspoon <nullspoon@iohq.net>2014-08-26 20:45:36 -0600
commit9dcea6a23e5d598e6fbe558dc216d3becb617619 (patch)
tree3cb8a08bf66fc65223510b1d2dcf3a76d1439c9c /src
parenta66cb7eb80005da7c78abb9d785b7455cc31f800 (diff)
downloadnoteless-9dcea6a23e5d598e6fbe558dc216d3becb617619.tar.gz
noteless-9dcea6a23e5d598e6fbe558dc216d3becb617619.tar.xz
Implemented path type variable
Now we can check if the path is of type 'r' (relative) or 'a' (absolute). This should be handy when reconstructing paths (does it start with a delimiter?...eg: absolute).
Diffstat (limited to 'src')
-rw-r--r--src/lib/path.cpp21
-rw-r--r--src/lib/path.h1
2 files changed, 17 insertions, 5 deletions
diff --git a/src/lib/path.cpp b/src/lib/path.cpp
index c51fc9f..490dde3 100644
--- a/src/lib/path.cpp
+++ b/src/lib/path.cpp
@@ -22,12 +22,23 @@ path::path( string p ) {
value = p;
// Parse path into parent dir array and filename
long cur_dir_begin = 0;
- for( int i = 0; i < p.length(); i++ ) {
- // Setting this to a variable so we can handle Windows in the future
- char delim = '/';
+
+ // Setting this to a variable so we can handle Windows in the future
+ char delim = '/';
+
+ // Set the path type ( [r]elative or [a]bsolute ) based on the first char in
+ // the path.
+ // Also set the starting integer (we can skip 0 if it's a delimiter)
+ int i = 0;
+ if( p[0] == delim ) {
+ type = 'a';
+ i = 1;
+ } else {
+ type = 'r';
+ }
+ // Parse the path into a vector
+ for( i; i < p.length(); i++ ) {
// Parse the directories out of the path
- // Skip the first if it's an absolute path
- if( i == 0 && p[i] == delim ) { continue; }
if( p[i] == delim ) {
// Handle multiple consecutive delimiters.
if( p[i + 1] == delim ) {
diff --git a/src/lib/path.h b/src/lib/path.h
index 045a93f..d72848b 100644
--- a/src/lib/path.h
+++ b/src/lib/path.h
@@ -27,6 +27,7 @@ class path {
public:
string value;
string filename;
+ char type;
vector<string> dirs;
path();

Generated by cgit