aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-08-08 14:55:26 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-08-10 15:02:45 +0300
commita1b2319ff2ddc8a6f139ee364cabe236ca62e23e (patch)
tree401acff7ca7f009455aa355f5e1e008f0b50810c
parent5352f2fb6b911c804e70ea98c1bb335c54fea6b5 (diff)
Add ignore case support for find_option()
-rw-r--r--build2/cxx/compile.cxx5
-rw-r--r--build2/cxx/link.cxx9
-rw-r--r--build2/cxx/msvc.cxx6
-rw-r--r--build2/install/rule.cxx4
-rw-r--r--build2/parser.cxx3
-rw-r--r--build2/utility7
-rw-r--r--build2/utility.cxx54
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 <build2/install/rule>
-#include <cctype> // tolower()
-
#include <build2/scope>
#include <build2/target>
#include <build2/algorithm>
@@ -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 <build2/parser>
-#include <cctype> // is{alpha alnum}()
#include <iostream>
#include <build2/version>
@@ -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 <cassert> // assert()
#include <iterator> // make_move_iterator()
-#include <butl/utility> // combine_hash(), reverse_iterate()
+#include <butl/utility> // combine_hash(), reverse_iterate(), casecmp(),
+ // lcase()
#include <exception> // uncaught_exception()
#include <unordered_set>
@@ -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<const char*> os, const strings& strs, bool)
+ find_options (initializer_list<const char*> 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<const char*> os, const cstrings& cstrs, bool)
+ find_options (initializer_list<const char*> 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<const char*> 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<const char*> 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;