aboutsummaryrefslogtreecommitdiff
path: root/butl/path
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-21 12:35:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-21 12:35:57 +0200
commitb6616430560102415bb82062b845a23c830bac0d (patch)
tree11b3601b2493a05c11e79af74e696e73155786cd /butl/path
parentea3b7793fa039aa166212d57ea816b83f678a147 (diff)
Add C-string version of path_traits::find_extension()
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 2040f5f..8e1eb1a 100644
--- a/butl/path
+++ b/butl/path
@@ -158,7 +158,14 @@ namespace butl
static size_type
find_extension (string_type const& s)
{
- size_type i (s.size ());
+ const C* r (find_extension (s.c_str (), s.size ()));
+ return r != nullptr ? r - s.c_str () : string_type::npos;
+ }
+
+ static const C*
+ find_extension (const C* s, size_type n)
+ {
+ size_type i (n);
for (; i > 0; --i)
{
@@ -176,10 +183,10 @@ namespace butl
// Weed out paths like ".txt" (and "/.txt") and "txt.".
//
- if (i > 1 && !is_separator (s[i - 2]) && i != s.size ())
- return i - 1;
+ if (i > 1 && !is_separator (s[i - 2]) && i != n)
+ return s + i - 1;
else
- return string_type::npos;
+ return nullptr;
}
static int