From 135a0bcb957dc836c425f51eeeeae4148092fdf8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 29 Aug 2016 18:49:33 +0200 Subject: Add path_traits::find_leaf(), make path::append() public --- butl/path | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'butl') 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 -- cgit v1.1