From 6efb1b1ce3901c7d90402e8e828b07977fe425d0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 9 Jul 2016 11:24:11 +0200 Subject: Add path::operator=/(string), path::size() --- butl/path | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 8 deletions(-) (limited to 'butl/path') 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 friend P butl::path_cast (const basic_path&); @@ -648,6 +682,24 @@ namespace butl return r; } + template + inline basic_path + operator/ (basic_path const& x, std::basic_string const& y) + { + basic_path r (x); + r /= y; + return r; + } + + template + inline basic_path + operator/ (basic_path const& x, const C* y) + { + basic_path r (x); + r /= y; + return r; + } + template inline bool operator== (const basic_path& x, const basic_path& y) -- cgit v1.1