aboutsummaryrefslogtreecommitdiffstats
path: root/src/fs/Path.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/Path.hxx')
-rw-r--r--src/fs/Path.hxx62
1 files changed, 44 insertions, 18 deletions
diff --git a/src/fs/Path.hxx b/src/fs/Path.hxx
index 9e0fa5aeb..43818b2da 100644
--- a/src/fs/Path.hxx
+++ b/src/fs/Path.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -27,7 +27,8 @@
#include <string>
#include <assert.h>
-#include <string.h>
+
+class AllocatedPath;
/**
* A path name in the native file system character set.
@@ -35,14 +36,10 @@
* This class manages a pointer to an existing path string. While an
* instance lives, the string must not be invalidated.
*/
-class Path {
- typedef PathTraitsFS::value_type value_type;
- typedef PathTraitsFS::pointer pointer;
- typedef PathTraitsFS::const_pointer const_pointer;
-
- const char *value;
+class Path : public PathTraitsFS::Pointer {
+ typedef PathTraitsFS::Pointer Base;
- constexpr Path(const_pointer _value):value(_value) {}
+ constexpr Path(const_pointer _value):Base(_value) {}
public:
/**
@@ -78,7 +75,7 @@ public:
* must not be used.
*/
bool IsNull() const {
- return value == nullptr;
+ return Base::IsNull();
}
/**
@@ -87,7 +84,7 @@ public:
* @see IsNull()
*/
void SetNull() {
- value = nullptr;
+ *this = nullptr;
}
/**
@@ -96,9 +93,9 @@ public:
*/
gcc_pure
size_t length() const {
- assert(value != nullptr);
+ assert(!IsNull());
- return strlen(value);
+ return PathTraitsFS::GetLength(c_str());
}
/**
@@ -108,7 +105,7 @@ public:
*/
gcc_pure
const_pointer c_str() const {
- return value;
+ return Base::c_str();
}
/**
@@ -117,7 +114,17 @@ public:
*/
gcc_pure
const_pointer data() const {
- return value;
+ return c_str();
+ }
+
+ /**
+ * Does the path contain a newline character? (Which is
+ * usually rejected by MPD because its protocol cannot
+ * transfer newline characters).
+ */
+ gcc_pure
+ bool HasNewline() const {
+ return PathTraitsFS::Find(c_str(), '\n') != nullptr;
}
/**
@@ -129,20 +136,39 @@ public:
std::string ToUTF8() const;
/**
+ * Determine the "base" file name.
+ * The return value points inside this object.
+ */
+ gcc_pure
+ Path GetBase() const {
+ return FromFS(PathTraitsFS::GetBase(c_str()));
+ }
+
+ /**
+ * Gets directory name of this path.
+ * Returns a "nulled" instance on error.
+ */
+ gcc_pure
+ AllocatedPath GetDirectoryName() const;
+
+ /**
* Determine the relative part of the given path to this
* object, not including the directory separator. Returns an
* empty string if the given path equals this object or
* nullptr on mismatch.
*/
gcc_pure
- const char *RelativeFS(const char *other_fs) const {
- return PathTraitsFS::Relative(value, other_fs);
+ const_pointer Relative(Path other_fs) const {
+ return PathTraitsFS::Relative(c_str(), other_fs.c_str());
}
gcc_pure
- bool IsAbsolute() {
+ bool IsAbsolute() const {
return PathTraitsFS::IsAbsolute(c_str());
}
+
+ gcc_pure
+ const_pointer GetSuffix() const;
};
#endif