Option parsing: support case-insensitive option matching.

Re-submitting r189416 with fix for Windows build on where strcasecmp is not defined.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189501 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rui Ueyama
2013-08-28 20:04:31 +00:00
parent 435798e96a
commit 2957273b88
4 changed files with 77 additions and 30 deletions

View File

@@ -13,18 +13,23 @@
#include "llvm/ADT/Twine.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <cstring>
#include <cctype>
#include <map>
using namespace llvm;
// Ordering on Info. The logic should match with the consumer-side function in
// llvm/Option/OptTable.h.
static int StrCmpOptionName(const char *A, const char *B) {
char a = *A, b = *B;
const char *X = A, *Y = B;
char a = tolower(*A), b = tolower(*B);
while (a == b) {
if (a == '\0')
return 0;
return strcmp(A, B);
a = *++A;
b = *++B;
a = tolower(*++X);
b = tolower(*++Y);
}
if (a == '\0') // A is a prefix of B.
@@ -50,7 +55,7 @@ static int CompareOptionRecords(const void *Av, const void *Bv) {
if (!ASent)
if (int Cmp = StrCmpOptionName(A->getValueAsString("Name").c_str(),
B->getValueAsString("Name").c_str()))
return Cmp;
return Cmp;
if (!ASent) {
std::vector<std::string> APrefixes = A->getValueAsListOfStrings("Prefixes");