[PATCH] Option parsing: support case-insensitive option matching.

Rui Ueyama ruiu at google.com
Fri Aug 23 14:32:33 PDT 2013



================
Comment at: lib/Option/OptTable.cpp:213
@@ -211,3 +212,3 @@
   // Search for the first next option which could be a prefix.
   Start = std::lower_bound(Start, End, Name.data());
 
----------------
Hans Wennborg wrote:
> I'm worried about how the sort order of the table interacts with case-insensitive options.
> 
> The option parser will do a binary search into the option table to find a matching option. If the option in the table is spelled in uppercase (e.g. Foo), but the user supplies a lower-case argument (e.g. foo), the binary search will go too far into the table, since f comes after F, and the option will not be found.
> 
> Maybe this can be fixed by making the sort order of the table based on case-insensitive comparison, and use a case-insensitive comparator for the binary search.
> 
> Or, if all options in a table are to be matched case-insensitively, maybe it would be easier to add that as a flag to the whole option table, assert that all options in the table are spelled in lower-case if that flag is true, and just transform arguments to lowercase when trying to match them?
Thinking about it, adding case sensitive/insensitive flag to the whole option table seems like a good idea. It's simple while it covers all the use cases I can think of. I'll try to do that in that way. Case insensitive command line parsing is used only on Windows, and on that platform all options are case insensitive. Mix of case sensitive and insensitive options is pretty weird and should be rare if any.


http://llvm-reviews.chandlerc.com/D1485



More information about the llvm-commits mailing list