[PATCH] Option parsing: support case-insensitive option matching.
Rui Ueyama
ruiu at google.com
Tue Aug 27 14:48:38 PDT 2013
================
Comment at: include/llvm/Option/OptTable.h:29-42
@@ +28,16 @@
+inline int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
+ const char *X = A, *Y = B;
+ char a = tolower(*A), b = tolower(*B);
+ while (a == b) {
+ if (a == '\0')
+ return 0;
+
+ a = tolower(*++X);
+ b = tolower(*++Y);
+ }
+
+ if (a == '\0') // A is a prefix of B.
+ return 1;
+ if (b == '\0') // B is a prefix of A.
+ return -1;
+
----------------
Shankar Kalpathi Easwaran wrote:
> Reid Kleckner wrote:
> > Shankar Kalpathi Easwaran wrote:
> > > Cant we just use strncasecmp here ?
> > No, prefixes come later in the sort, ie
> > abc
> > ab
> > a
> >
> > vs.
> >
> > a
> > ab
> > abc
> What I was trying to recommend here was
>
> if (strncasecmp(A, B, strlen(A)) == 0)
> return 1;
> if (strncasecmp(A, B, strlen(B)) == 0)
> return 1;
>
>
That strncasecmp() seems to simplify the code too much, but I tried to simplify the logic using strncasecmp(). PTAL.
http://llvm-reviews.chandlerc.com/D1485
BRANCH
ignore-case
ARCANIST PROJECT
llvm
More information about the llvm-commits
mailing list