aboutsummaryrefslogtreecommitdiff
path: root/butl/path
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-07-09 11:24:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-07-09 11:24:11 +0200
commit6efb1b1ce3901c7d90402e8e828b07977fe425d0 (patch)
tree66f79216ceaf346ffbca7f5926f40cfbbeb9b755 /butl/path
parent5b1c20f2315cd7fc624ffd31abdcc03b409bfcb2 (diff)
Add path::operator=/(string), path::size()
Diffstat (limited to 'butl/path')
-rw-r--r--butl/path68
1 files changed, 60 insertions, 8 deletions
diff --git a/butl/path b/butl/path
index 193eae4..33c3d11 100644
--- a/butl/path
+++ b/butl/path
@@ -74,13 +74,20 @@ namespace butl
static size_type
find_separator (string_type const& s, size_type pos = 0)
{
- for (size_type n (s.size ()); pos < n; ++pos)
+ const C* r (find_separator (s.c_str () + pos, s.size () - pos));
+ return r != nullptr ? r - s.c_str () : string_type::npos;
+ }
+
+ static const C*
+ find_separator (const C* s, size_type n)
+ {
+ for (const C* e (s + n); s != e; ++s)
{
- if (is_separator (s[pos]))
- return pos;
+ if (is_separator (*s))
+ return s;
}
- return string_type::npos;
+ return nullptr;
}
static size_type
@@ -360,10 +367,10 @@ namespace butl
public:
bool
- empty () const
- {
- return this->path_.empty ();
- }
+ empty () const {return this->path_.empty ();}
+
+ size_type
+ size () const {return this->path_.size ();}
// Return true if this path doesn't have any directories. Note
// that "/foo" is not a simple path (it is "foo" in root directory)
@@ -562,6 +569,15 @@ namespace butl
basic_path&
operator/= (basic_path const&);
+ // Append a single path component (must not contain directory separators)
+ // as a string, without first constructing the path object.
+ //
+ basic_path&
+ operator/= (string_type const&);
+
+ basic_path&
+ operator/= (const C*);
+
basic_path
operator+ (string_type const& s) const
{
@@ -569,6 +585,12 @@ namespace butl
}
basic_path
+ operator+ (const C* s) const
+ {
+ return basic_path (this->path_ + s);
+ }
+
+ basic_path
operator+ (C c) const
{
return basic_path (this->path_ + c);
@@ -582,6 +604,13 @@ namespace butl
}
basic_path&
+ operator+= (const C* s)
+ {
+ this->path_ += s;
+ return *this;
+ }
+
+ basic_path&
operator+= (C c)
{
this->path_ += c;
@@ -622,6 +651,11 @@ namespace butl
init (this->path_);
}
+ // Common implementation for operator=/().
+ //
+ void
+ combine (const C*, size_type);
+
private:
template <class P, class C1, class K1>
friend P butl::path_cast (const basic_path<C1, K1>&);
@@ -648,6 +682,24 @@ namespace butl
return r;
}
+ template <typename C, typename K>
+ inline basic_path<C, K>
+ operator/ (basic_path<C, K> const& x, std::basic_string<C> const& y)
+ {
+ basic_path<C, K> r (x);
+ r /= y;
+ return r;
+ }
+
+ template <typename C, typename K>
+ inline basic_path<C, K>
+ operator/ (basic_path<C, K> const& x, const C* y)
+ {
+ basic_path<C, K> r (x);
+ r /= y;
+ return r;
+ }
+
template <typename C, typename K1, typename K2>
inline bool
operator== (const basic_path<C, K1>& x, const basic_path<C, K2>& y)