diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-09-28 17:58:00 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-09-28 17:58:47 +0300 |
commit | 8f14a22e5bbb71d90577b35a09ba8ffae04bfe9c (patch) | |
tree | 96bce706024b3ec200170d5e090ac41615887606 | |
parent | f488e6473a7d0562c0e2df6d107a36de4d30d9da (diff) |
Rename casecmp() function and case_compare_[c_]string structs to icasecmp() and icase_compare_[c_]string
-rw-r--r-- | libbutl/curl.cxx | 8 | ||||
-rw-r--r-- | libbutl/process.cxx | 16 | ||||
-rw-r--r-- | libbutl/project-name.cxx | 2 | ||||
-rw-r--r-- | libbutl/project-name.mxx | 4 | ||||
-rw-r--r-- | libbutl/utility.ixx | 12 | ||||
-rw-r--r-- | libbutl/utility.mxx | 20 | ||||
-rw-r--r-- | tests/strcase/driver.cxx | 28 |
7 files changed, 44 insertions, 46 deletions
diff --git a/libbutl/curl.cxx b/libbutl/curl.cxx index f88869b..33ca5be 100644 --- a/libbutl/curl.cxx +++ b/libbutl/curl.cxx @@ -33,7 +33,7 @@ import butl.fdstream; import butl.small_vector; #endif -import butl.utility; // casecmp() +import butl.utility; // icasecmp() #else #include <libbutl/utility.mxx> #endif @@ -178,8 +178,7 @@ namespace butl if (n == string::npos) throw invalid_argument ("no protocol in URL"); - if (casecmp (u, "ftp", n) == 0 || - casecmp (u, "tftp", n) == 0) + if (icasecmp (u, "ftp", n) == 0 || icasecmp (u, "tftp", n) == 0) { switch (m) { @@ -189,8 +188,7 @@ namespace butl throw invalid_argument ("POST method with FTP protocol"); } } - else if (casecmp (u, "http", n) == 0 || - casecmp (u, "https", n) == 0) + else if (icasecmp (u, "http", n) == 0 || icasecmp (u, "https", n) == 0) { o.push_back ("--fail"); // Fail on HTTP errors (e.g., 404). o.push_back ("--location"); // Follow redirects. diff --git a/libbutl/process.cxx b/libbutl/process.cxx index 4408610..b82af3c 100644 --- a/libbutl/process.cxx +++ b/libbutl/process.cxx @@ -135,7 +135,7 @@ import butl.small_vector; import std.threading; #endif -import butl.utility; // casecmp() +import butl.utility; // icasecmp() import butl.fdstream; // fdnull() #else #include <libbutl/utility.mxx> @@ -945,9 +945,9 @@ namespace butl { const char* e (traits::find_extension (f, fn)); ext = (e == nullptr || - (casecmp (e, ".exe") != 0 && - casecmp (e, ".bat") != 0 && - casecmp (e, ".cmd") != 0)); + (icasecmp (e, ".exe") != 0 && + icasecmp (e, ".bat") != 0 && + icasecmp (e, ".cmd") != 0)); } process_path r (f, path (), path ()); // Make sure it is not empty. @@ -1413,7 +1413,7 @@ namespace butl for (; *ev != nullptr; ++ev) { const char* v (*ev); - if (casecmp (cv, v, nn) == 0 && (v[nn] == '=' || v[nn] == '\0')) + if (icasecmp (cv, v, nn) == 0 && (v[nn] == '=' || v[nn] == '\0')) break; } @@ -1443,8 +1443,8 @@ namespace butl { const char* p (pp.effect_string ()); const char* e (path::traits_type::find_extension (p)); - if (e != nullptr && (casecmp (e, ".bat") == 0 || - casecmp (e, ".cmd") == 0)) + if (e != nullptr && (icasecmp (e, ".bat") == 0 || + icasecmp (e, ".cmd") == 0)) { batch = getenv ("COMSPEC"); @@ -1749,7 +1749,7 @@ namespace butl { if (auto name = static_cast<const char*> (rva_to_ptr (imp->Name))) { - if (casecmp (name, "msys-2.0.dll") == 0) + if (icasecmp (name, "msys-2.0.dll") == 0) return true; } } diff --git a/libbutl/project-name.cxx b/libbutl/project-name.cxx index a1767e9..4b02949 100644 --- a/libbutl/project-name.cxx +++ b/libbutl/project-name.cxx @@ -88,7 +88,7 @@ namespace butl if (e != nullptr && p != string::npos && - casecmp (value_.c_str () + p + 1, e) != 0) + icasecmp (value_.c_str () + p + 1, e) != 0) p = string::npos; return string (value_, 0, p); diff --git a/libbutl/project-name.mxx b/libbutl/project-name.mxx index 5f5a586..dce1c7a 100644 --- a/libbutl/project-name.mxx +++ b/libbutl/project-name.mxx @@ -22,7 +22,7 @@ export module butl.project_name; import std.core; import std.io; #endif -import butl.utility; // casecmp(), sanitize_identifier() +import butl.utility; // icasecmp(), sanitize_identifier() #else #include <libbutl/utility.mxx> #endif @@ -100,7 +100,7 @@ LIBBUTL_MODEXPORT namespace butl // int compare (const project_name& n) const {return compare (n.value_);} int compare (const std::string& n) const {return compare (n.c_str ());} - int compare (const char* n) const {return butl::casecmp (value_, n);} + int compare (const char* n) const {return icasecmp (value_, n);} private: std::string value_; diff --git a/libbutl/utility.ixx b/libbutl/utility.ixx index 8f37242..d8a5ee8 100644 --- a/libbutl/utility.ixx +++ b/libbutl/utility.ixx @@ -84,7 +84,7 @@ namespace butl } inline int - casecmp (char l, char r) + icasecmp (char l, char r) { l = lcase (l); r = lcase (r); @@ -92,7 +92,7 @@ namespace butl } inline int - casecmp (const char* l, const char* r, std::size_t n) + icasecmp (const char* l, const char* r, std::size_t n) { #ifndef _WIN32 return n == std::string::npos ? strcasecmp (l, r) : strncasecmp (l, r, n); @@ -102,15 +102,15 @@ namespace butl } inline int - casecmp (const std::string& l, const std::string& r, std::size_t n) + icasecmp (const std::string& l, const std::string& r, std::size_t n) { - return casecmp (l.c_str (), r.c_str (), n); + return icasecmp (l.c_str (), r.c_str (), n); } inline int - casecmp (const std::string& l, const char* r, std::size_t n) + icasecmp (const std::string& l, const char* r, std::size_t n) { - return casecmp (l.c_str (), r, n); + return icasecmp (l.c_str (), r, n); } inline bool diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx index 03fb89e..11aa013 100644 --- a/libbutl/utility.mxx +++ b/libbutl/utility.mxx @@ -108,31 +108,31 @@ LIBBUTL_MODEXPORT namespace butl // The optional size argument specifies the maximum number of characters // to compare. // - int casecmp (char, char); + int icasecmp (char, char); - int casecmp (const std::string&, const std::string&, - std::size_t = std::string::npos); + int icasecmp (const std::string&, const std::string&, + std::size_t = std::string::npos); - int casecmp (const std::string&, const char*, - std::size_t = std::string::npos); + int icasecmp (const std::string&, const char*, + std::size_t = std::string::npos); - int casecmp (const char*, const char*, std::size_t = std::string::npos); + int icasecmp (const char*, const char*, std::size_t = std::string::npos); // Case-insensitive key comparators (i.e., to be used in sets, maps, etc). // - struct case_compare_string + struct icase_compare_string { bool operator() (const std::string& x, const std::string& y) const { - return casecmp (x, y) < 0; + return icasecmp (x, y) < 0; } }; - struct case_compare_c_string + struct icase_compare_c_string { bool operator() (const char* x, const char* y) const { - return casecmp (x, y) < 0; + return icasecmp (x, y) < 0; } }; diff --git a/tests/strcase/driver.cxx b/tests/strcase/driver.cxx index e9b779c..4ebe5f4 100644 --- a/tests/strcase/driver.cxx +++ b/tests/strcase/driver.cxx @@ -28,35 +28,35 @@ main () const string upper ("+/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); const string lower ("+/0123456789abcdefghijklmnopqrstuvwxyz"); - assert (casecmp (upper, lower) == 0); - assert (casecmp (upper, lower, upper.size ()) == 0); - assert (casecmp (upper, lower, 100) == 0); - assert (casecmp ("a", "A1") < 0); - assert (casecmp ("A1", "a") > 0); - assert (casecmp ("a", "A1", 1) == 0); - assert (casecmp ("A1", "a", 1) == 0); - assert (casecmp ("a", "b", 0) == 0); + assert (icasecmp (upper, lower) == 0); + assert (icasecmp (upper, lower, upper.size ()) == 0); + assert (icasecmp (upper, lower, 100) == 0); + assert (icasecmp ("a", "A1") < 0); + assert (icasecmp ("A1", "a") > 0); + assert (icasecmp ("a", "A1", 1) == 0); + assert (icasecmp ("A1", "a", 1) == 0); + assert (icasecmp ("a", "b", 0) == 0); for (size_t i (0); i < upper.size (); ++i) { - assert (casecmp (upper[i], lower[i]) == 0); + assert (icasecmp (upper[i], lower[i]) == 0); if (i > 0) { - assert (casecmp (upper[i], lower[i - 1]) > 0); - assert (casecmp (lower[i - 1], upper[i]) < 0); + assert (icasecmp (upper[i], lower[i - 1]) > 0); + assert (icasecmp (lower[i - 1], upper[i]) < 0); } } - // As casecmp() compares strings as if they have been converted to the + // As icasecmp() compares strings as if they have been converted to the // lower case the characters [\]^_` (located between 'Z' and 'a' in the ASCII // table) evaluates as less than any alphabetic character. // string ascii_91_96 ("[\\]^_`"); for (const auto& c: ascii_91_96) { - assert (casecmp (&c, "A", 1) < 0); - assert (casecmp (&c, "a", 1) < 0); + assert (icasecmp (&c, "A", 1) < 0); + assert (icasecmp (&c, "a", 1) < 0); } assert (ucase (lower) == upper); |