aboutsummaryrefslogtreecommitdiff
path: root/butl/path
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-29 18:49:33 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-29 18:49:33 +0200
commit135a0bcb957dc836c425f51eeeeae4148092fdf8 (patch)
tree010b91011d8d36ca612c1f5aa83626562c4d66a3 /butl/path
parent5e086efce1ae4f8825f6b90c4dc15324d8bea13a (diff)
Add path_traits::find_leaf(), make path::append() public
Diffstat (limited to 'butl/path')
-rw-r--r--butl/path26
1 files changed, 23 insertions, 3 deletions
diff --git a/butl/path b/butl/path
index f679330..e6c9166 100644
--- a/butl/path
+++ b/butl/path
@@ -199,6 +199,26 @@ namespace butl
return nullptr;
}
+ // Return the start of the leaf (last path component) in the path. Note
+ // that the leaf will include the trailing separator, if any (i.e., the
+ // leaf of /tmp/bar/ is bar/).
+ //
+ static size_type
+ find_leaf (string_type const& s)
+ {
+ const C* r (find_leaf (s.c_str (), s.size ()));
+ return r != nullptr ? r - s.c_str () : string_type::npos;
+ }
+
+ static const C*
+ find_leaf (const C* s, size_type n)
+ {
+ const C* p;
+ return n == 0
+ ? nullptr
+ : (p = rfind_separator (s, n - 1)) == nullptr ? s : ++p;
+ }
+
static int
compare (string_type const& l, string_type const& r)
{
@@ -806,6 +826,9 @@ namespace butl
basic_path&
operator+= (C);
+ void
+ append (const C*, size_type);
+
// Note that comparison is case-insensitive if the filesystem is not
// case-sensitive (e.g., Windows). And it ignored trailing slashes
// except for the root case.
@@ -887,9 +910,6 @@ namespace butl
void
combine (const C*, size_type);
- void
- append (const C*, size_type);
-
// Friends.
//
template <class C1, class K1>