X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FStringRef.cpp;h=51e11004f322151a14f2105a6d0f772f183dcca2;hb=05872ea804cdc9534960b30d28a391928c61481a;hp=6905edf19e12be1dd16a547326a9e9d05dae21a8;hpb=cf62632d835313b720b68669bd1e5682d4d52d0d;p=oota-llvm.git diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp index 6905edf19e1..51e11004f32 100644 --- a/lib/Support/StringRef.cpp +++ b/lib/Support/StringRef.cpp @@ -15,6 +15,26 @@ using namespace llvm; const size_t StringRef::npos; #endif +static char ascii_tolower(char x) { + if (x >= 'A' && x <= 'Z') + return x - 'A' + 'a'; + return x; +} + +/// compare_lower - Compare strings, ignoring case. +int StringRef::compare_lower(StringRef RHS) const { + for (size_t I = 0, E = std::min(Length, RHS.Length); I != E; ++I) { + char LHC = ascii_tolower(Data[I]); + char RHC = ascii_tolower(RHS.Data[I]); + if (LHC != RHC) + return LHC < RHC ? -1 : 1; + } + + if (Length == RHS.Length) + return 0; + return Length < RHS.Length ? -1 : 1; +} + //===----------------------------------------------------------------------===// // String Searching //===----------------------------------------------------------------------===//