From 275a1b714cd9fdfac72e060148f669753569c28c Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Tue, 7 May 2019 22:02:38 +0200 Subject: [PATCH] Clearer non inverted logic for primitive case insensitive compare, updated readme. --- README.md | 3 ++- include/ghc/filesystem.hpp | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a7d251a..9430358 100644 --- a/README.md +++ b/README.md @@ -403,7 +403,8 @@ and part of the justification for the proposed solution is "we did it so for alm But this makes `fs::copy` with `fs::copy_options::create_symlinks` or `fs::copy_options::create_hard_links` just a more complicated syntax for the `fs::create_symlink` or `fs::create_hardlink` operation and I don't want to believe, that this was the intention of the original writing. -As there is another issue related to copy, with a different take on the description, +As there is another issue related to copy, with a different take on the description. + *Note:* With v1.1.2 I decided to integrate a behavior switch for this and make the LWG #2682 the default. diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index b41725e..1f32160 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -1379,20 +1379,20 @@ inline path::path(InputIterator first, InputIterator last, format fmt) namespace detail { -GHC_INLINE bool compare_no_case(const char* str1, const char* str2) +GHC_INLINE bool equals_simple_insensitive(const char* str1, const char* str2) { #ifdef GHC_OS_WINDOWS # ifdef __GNUC__ while (::tolower((unsigned char)*str1) == ::tolower((unsigned char)*str2++)) { if (*str1++ == 0) - return false; + return true; } - return true; + return false; # else - return ::_stricmp(str1, str2); + return 0 == ::_stricmp(str1, str2); # endif #else - return ::strcasecmp(str1, str2); + return 0 == ::strcasecmp(str1, str2); #endif } @@ -1650,7 +1650,7 @@ GHC_INLINE file_status status_from_INFO(const path& p, const INFO* info, std::er prms = prms | perms::owner_write | perms::group_write | perms::others_write; } std::string ext = p.extension().generic_string(); - if (!compare_no_case(ext.c_str(), ".exe") || !compare_no_case(ext.c_str(), ".cmd") || !compare_no_case(ext.c_str(), ".bat") || !compare_no_case(ext.c_str(), ".com")) { + if (equals_simple_insensitive(ext.c_str(), ".exe") || equals_simple_insensitive(ext.c_str(), ".cmd") || equals_simple_insensitive(ext.c_str(), ".bat") || equals_simple_insensitive(ext.c_str(), ".com")) { prms = prms | perms::owner_exec | perms::group_exec | perms::others_exec; } if (sz) { @@ -1810,7 +1810,7 @@ GHC_INLINE u8arguments::u8arguments(int& argc, char**& argv) #if defined(__ANDROID__) && __ANDROID_API__ < 26 _isvalid = true; #else - if (!detail::compare_no_case(::nl_langinfo(CODESET), "UTF-8")) { + if (detail::equals_simple_insensitive(::nl_langinfo(CODESET), "UTF-8")) { _isvalid = true; } #endif