From a1b2319ff2ddc8a6f139ee364cabe236ca62e23e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 8 Aug 2016 14:55:26 +0300 Subject: Add ignore case support for find_option() --- build2/cxx/compile.cxx | 5 +---- build2/cxx/link.cxx | 9 ++------- build2/cxx/msvc.cxx | 6 ++++-- build2/install/rule.cxx | 4 +--- build2/parser.cxx | 3 +-- build2/utility | 7 ++++++- build2/utility.cxx | 54 ++++++++++++++++++++----------------------------- 7 files changed, 37 insertions(+), 51 deletions(-) diff --git a/build2/cxx/compile.cxx b/build2/cxx/compile.cxx index 2f1eb8d..56c518b 100644 --- a/build2/cxx/compile.cxx +++ b/build2/cxx/compile.cxx @@ -586,12 +586,9 @@ namespace build2 { // See if this one is part of the Windows drive letter. // - auto isalpha = [](char c) { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');}; - if (p > 1 && p + 1 < n && // 2 chars before, 1 after. l[p - 2] == ' ' && - isalpha (l[p - 1]) && + alpha (l[p - 1]) && path::traits::is_separator (l[p + 1])) p = l.rfind (':', p - 2); } diff --git a/build2/cxx/link.cxx b/build2/cxx/link.cxx index 4ac5c43..d19d6b1 100644 --- a/build2/cxx/link.cxx +++ b/build2/cxx/link.cxx @@ -466,15 +466,10 @@ namespace build2 auto upcase_sanitize = [] (char c) -> char { - if (c >= 'a' && c <='z') - { - const unsigned char shift ('a' - 'A'); - return c - shift; - } - else if (c == '-' || c == '+' || c == '.') + if (c == '-' || c == '+' || c == '.') return '_'; else - return c; + return ucase (c); }; transform (t.name.begin (), diff --git a/build2/cxx/msvc.cxx b/build2/cxx/msvc.cxx index dcf7fee..9798046 100644 --- a/build2/cxx/msvc.cxx +++ b/build2/cxx/msvc.cxx @@ -174,10 +174,12 @@ namespace build2 if (p != string::npos && s[p + 1] == ' ') { - if (s.compare (n + 1, 3, "obj") == 0) // @@ CASE + const char* e (s.c_str () + n + 1); + + if (casecmp (e, "obj", 3) == 0) obj = true; - if (s.compare (n + 1, 3, "dll") == 0) // @@ CASE + if (casecmp (e, "dll", 3) == 0) dll = true; } } diff --git a/build2/install/rule.cxx b/build2/install/rule.cxx index 165b43d..39741bd 100644 --- a/build2/install/rule.cxx +++ b/build2/install/rule.cxx @@ -4,8 +4,6 @@ #include -#include // tolower() - #include #include #include @@ -254,7 +252,7 @@ namespace build2 assert (d.absolute ()); string s (d.representation ()); - s[1] = tolower(s[0]); // Replace ':' with the drive letter. + s[1] = lcase (s[0]); // Replace ':' with the drive letter. s[0] = '/'; return dir_path (dir_path (move (s)).posix_representation ()); diff --git a/build2/parser.cxx b/build2/parser.cxx index 82be698..9fd584a 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -4,7 +4,6 @@ #include -#include // is{alpha alnum}() #include #include @@ -2754,7 +2753,7 @@ namespace build2 for (size_t i (0); i != n.value.size (); ++i) { char c (n.value[i]); - if (c != '_' && !(i != 0 ? isalnum (c) : isalpha (c))) + if (c != '_' && !(i != 0 ? alnum (c) : alpha (c))) return false; } diff --git a/build2/utility b/build2/utility index 4da422b..4c49be5 100644 --- a/build2/utility +++ b/build2/utility @@ -12,7 +12,8 @@ #include // assert() #include // make_move_iterator() -#include // combine_hash(), reverse_iterate() +#include // combine_hash(), reverse_iterate(), casecmp(), + // lcase() #include // uncaught_exception() #include @@ -35,6 +36,10 @@ namespace build2 // using butl::combine_hash; using butl::reverse_iterate; + using butl::casecmp; + using butl::lcase; + using butl::alpha; + using butl::alnum; // Basic string utilities. // diff --git a/build2/utility.cxx b/build2/utility.cxx index 46741a3..971c1fb 100644 --- a/build2/utility.cxx +++ b/build2/utility.cxx @@ -168,24 +168,20 @@ namespace build2 } bool - find_option (const char* o, const strings& strs, bool) + find_option (const char* o, const strings& strs, bool ic) { - //@@ CASE ignore case - for (const string& s: strs) - if (s == o) + if (ic ? casecmp (s, o) == 0 : s == o) return true; return false; } bool - find_option (const char* o, const cstrings& cstrs, bool) + find_option (const char* o, const cstrings& cstrs, bool ic) { - //@@ CASE ignore case - for (const char* s: cstrs) - if (s != nullptr && strcmp (s, o) == 0) + if (s != nullptr && (ic ? casecmp (s, o) : strcmp (s, o)) == 0) return true; return false; @@ -198,27 +194,25 @@ namespace build2 } bool - find_options (initializer_list os, const strings& strs, bool) + find_options (initializer_list os, const strings& strs, bool ic) { - //@@ CASE ignore case - for (const string& s: strs) for (const char* o: os) - if (s == o) + if (ic ? casecmp (s, o) == 0 : s == o) return true; return false; } bool - find_options (initializer_list os, const cstrings& cstrs, bool) + find_options (initializer_list os, + const cstrings& cstrs, + bool ic) { - //@@ CASE ignore case - for (const char* s: cstrs) if (s != nullptr) for (const char* o: os) - if (strcmp (s, o) == 0) + if ((ic ? casecmp (s, o) : strcmp (s, o)) == 0) return true; return false; @@ -231,28 +225,24 @@ namespace build2 } bool - find_option_prefix (const char* p, const strings& strs, bool) + find_option_prefix (const char* p, const strings& strs, bool ic) { - //@@ CASE ignore case - size_t n (strlen (p)); for (const string& s: strs) - if (s.compare (0, n, p) == 0) + if ((ic ? casecmp (s, p, n) : s.compare (0, n, p)) == 0) return true; return false; } bool - find_option_prefix (const char* p, const cstrings& cstrs, bool) + find_option_prefix (const char* p, const cstrings& cstrs, bool ic) { - //@@ CASE ignore case - size_t n (strlen (p)); for (const char* s: cstrs) - if (s != nullptr && strncmp (s, p, n) == 0) + if (s != nullptr && (ic ? casecmp (s, p, n) : strncmp (s, p, n)) == 0) return true; return false; @@ -269,13 +259,13 @@ namespace build2 bool find_option_prefixes (initializer_list ps, const strings& strs, - bool) + bool ic) { - //@@ CASE ignore case - for (const string& s: strs) for (const char* p: ps) - if (s.compare (0, strlen (p), p) == 0) + if ((ic + ? casecmp (s, p, strlen (p)) + : s.compare (0, strlen (p), p)) == 0) return true; return false; @@ -284,14 +274,14 @@ namespace build2 bool find_option_prefixes (initializer_list ps, const cstrings& cstrs, - bool) + bool ic) { - //@@ CASE ignore case - for (const char* s: cstrs) if (s != nullptr) for (const char* p: ps) - if (strncmp (s, p, strlen (p)) == 0) + if ((ic + ? casecmp (s, p, strlen (p)) + : strncmp (s, p, strlen (p))) == 0) return true; return false; -- cgit v1.1