From 75205dd307c57df24d282b94f1bca3b668579c1e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 6 Sep 2014 14:26:41 +0200 Subject: Do not low-case paths in normalize() for Win32 Instead, do case-insensitive comparison. Also handle separators while at it. --- cutl/fs/path.hxx | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'cutl/fs/path.hxx') diff --git a/cutl/fs/path.hxx b/cutl/fs/path.hxx index cbe71a6..45a7891 100644 --- a/cutl/fs/path.hxx +++ b/cutl/fs/path.hxx @@ -39,7 +39,6 @@ namespace cutl // could be multiple seperators. For example, on Windows // we check for both '/' and '\'. // - static bool is_separator (C c) { @@ -78,6 +77,33 @@ namespace cutl return string_type::npos; } + + static int + compare (string_type const& l, string_type const& r) + { + size_type ln (l.size ()), rn (r.size ()), n (ln < rn ? ln : rn); + for (size_type i (0); i != n; ++i) + { +#ifdef _WIN32 + C lc (tolower (l[i])), rc (tolower (r[i])); +#else + C lc (l[i]), rc (r[i]); +#endif + if (is_separator (lc) && is_separator (rc)) + continue; + + if (lc < rc) return -1; + if (lc > rc) return 1; + } + + return ln < rn ? -1 : (ln > rn ? 1 : 0); + } + + private: +#ifdef _WIN32 + static C + tolower (C); +#endif }; template @@ -210,10 +236,8 @@ namespace cutl public: // Normalize the path. This includes collapsing the '.' and '..' // directories if possible, collapsing multiple directory - // separators, converting all directory separators to the - // canonical form, and making the path lower-case if the - // filesystem is not case-sensitive (e.g., Windows). Returns - // *this. + // separators, and converting all directory separators to the + // canonical form. Returns *this. // basic_path& normalize (); @@ -249,10 +273,13 @@ namespace cutl return *this; } + // Note that comparison is case-insensitive if the filesystem is + // not case-sensitive (e.g., Windows). + // bool operator== (basic_path const& x) const { - return path_ == x.path_; + return traits::compare (path_, x.path_) == 0; } bool @@ -264,7 +291,7 @@ namespace cutl bool operator< (basic_path const& x) const { - return path_ < x.path_; + return traits::compare (path_, x.path_) < 0; } public: @@ -287,11 +314,6 @@ namespace cutl void init (); -#ifdef _WIN32 - static C - tolower (C); -#endif - private: string_type path_; }; -- cgit v1.1