From 9125ed697fe61abd1a742686e816b44b887a8d69 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 2 Aug 2016 11:24:35 +0200 Subject: Add C-string overload of path_traits::rfind_separator() --- butl/path | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/butl/path b/butl/path index 3cf3716..7322a15 100644 --- a/butl/path +++ b/butl/path @@ -135,13 +135,20 @@ namespace butl else pos++; - for (; pos > 0; --pos) + const C* r (rfind_separator (s.c_str (), pos)); + return r != nullptr ? r - s.c_str () : string_type::npos; + } + + static const C* + rfind_separator (const C* s, size_type n) + { + for (; n != 0; --n) { - if (is_separator (s[pos - 1])) - return pos - 1; + if (is_separator (s[n - 1])) + return s + n - 1; } - return string_type::npos; + return nullptr; } // Return the position of '.' or npos if there is no extension. -- cgit v1.1