aboutsummaryrefslogtreecommitdiff
path: root/butl/path
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-02 11:24:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-02 11:24:35 +0200
commit9125ed697fe61abd1a742686e816b44b887a8d69 (patch)
tree55388511b6ce3361d962a956b66f40a8e96944b8 /butl/path
parent17937d1cc8dc96e0be2ce795442f91eb2dbf81da (diff)
Add C-string overload of path_traits::rfind_separator()
Diffstat (limited to 'butl/path')
-rw-r--r--butl/path15
1 files 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.