diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-21 12:35:57 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-21 12:35:57 +0200 |
commit | b6616430560102415bb82062b845a23c830bac0d (patch) | |
tree | 11b3601b2493a05c11e79af74e696e73155786cd /butl/path | |
parent | ea3b7793fa039aa166212d57ea816b83f678a147 (diff) |
Add C-string version of path_traits::find_extension()
Diffstat (limited to 'butl/path')
-rw-r--r-- | butl/path | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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 |