From 086f8b6e68228c9081c15bee03975db4024114ad Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 23 May 2019 15:33:26 +0200 Subject: Improve path_traits convenience overloads --- libbutl/path.mxx | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'libbutl/path.mxx') diff --git a/libbutl/path.mxx b/libbutl/path.mxx index 3f3a844..1b1513a 100644 --- a/libbutl/path.mxx +++ b/libbutl/path.mxx @@ -81,6 +81,7 @@ LIBBUTL_MODEXPORT namespace butl struct path_traits { using string_type = std::basic_string; + using char_traits_type = typename string_type::traits_type; using size_type = typename string_type::size_type; // Canonical directory and path seperators. @@ -135,6 +136,12 @@ LIBBUTL_MODEXPORT namespace butl } static bool + absolute (const C* s) + { + return absolute (s, char_traits_type::length (s)); + } + + static bool absolute (const C* s, size_type n) { #ifdef _WIN32 @@ -151,6 +158,12 @@ LIBBUTL_MODEXPORT namespace butl } static bool + current (const C* s) + { + return current (s, char_traits_type::length (s)); + } + + static bool current (const C* s, size_type n) { return n == 1 && s[0] == '.'; @@ -163,6 +176,12 @@ LIBBUTL_MODEXPORT namespace butl } static bool + parent (const C* s) + { + return parent (s, char_traits_type::length (s)); + } + + static bool parent (const C* s, size_type n) { return n == 2 && s[0] == '.' && s[1] == '.'; @@ -175,6 +194,12 @@ LIBBUTL_MODEXPORT namespace butl } static bool + normalized (const C* s, bool sep) + { + return normalized (s, char_traits_type::length (s), sep); + } + + static bool normalized (const C* s, size_type n, bool sep) { size_t j (0); // Beginning of path component. @@ -215,6 +240,12 @@ LIBBUTL_MODEXPORT namespace butl } static bool + root (const C* s) + { + return root (s, char_traits_type::length (s)); + } + + static bool root (const C* s, size_type n) { #ifdef _WIN32 @@ -237,6 +268,12 @@ LIBBUTL_MODEXPORT namespace butl } static const C* + find_separator (const C* s) + { + return find_separator (s, char_traits_type::length (s)); + } + + static const C* find_separator (const C* s, size_type n) { for (const C* e (s + n); s != e; ++s) @@ -261,6 +298,12 @@ LIBBUTL_MODEXPORT namespace butl } static const C* + rfind_separator (const C* s) + { + return rfind_separator (s, char_traits_type::length (s)); + } + + static const C* rfind_separator (const C* s, size_type n) { for (; n != 0; --n) @@ -282,6 +325,12 @@ LIBBUTL_MODEXPORT namespace butl } static const C* + find_extension (const C* s) + { + return find_extension (s, char_traits_type::length (s)); + } + + static const C* find_extension (const C* s, size_type n) { size_type i (n); @@ -320,6 +369,12 @@ LIBBUTL_MODEXPORT namespace butl } static const C* + find_leaf (const C* s) + { + return find_leaf (s, char_traits_type::length (s)); + } + + static const C* find_leaf (const C* s, size_type n) { const C* p; @@ -600,7 +655,7 @@ LIBBUTL_MODEXPORT namespace butl using string_type = std::basic_string; using size_type = typename string_type::size_type; using difference_type = typename string_type::difference_type; - using traits = path_traits; + using traits = path_traits; //@@ TODO: rename to traits_type. struct iterator; using reverse_iterator = std::reverse_iterator; -- cgit v1.1