X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FStringSwitch.h;h=7fd6e27960321a3e680fecf87d3f0467486ca01b;hb=5d37976090df34f003e5128e39593b763be0ca71;hp=7dd5647df6051b59c264009ede855b4c8aa504a3;hpb=d01518630ad165e0bc7d7194abb183abfa93e0d5;p=oota-llvm.git diff --git a/include/llvm/ADT/StringSwitch.h b/include/llvm/ADT/StringSwitch.h index 7dd5647df60..7fd6e279603 100644 --- a/include/llvm/ADT/StringSwitch.h +++ b/include/llvm/ADT/StringSwitch.h @@ -48,8 +48,8 @@ class StringSwitch { const T *Result; public: - explicit StringSwitch(StringRef Str) - : Str(Str), Result(0) { } + explicit StringSwitch(StringRef S) + : Str(S), Result(0) { } template StringSwitch& Case(const char (&S)[N], const T& Value) { @@ -61,6 +61,26 @@ public: return *this; } + template + StringSwitch& EndsWith(const char (&S)[N], const T &Value) { + if (!Result && Str.size() >= N-1 && + std::memcmp(S, Str.data() + Str.size() + 1 - N, N-1) == 0) { + Result = &Value; + } + + return *this; + } + + template + StringSwitch& StartsWith(const char (&S)[N], const T &Value) { + if (!Result && Str.size() >= N-1 && + std::memcmp(S, Str.data(), N-1) == 0) { + Result = &Value; + } + + return *this; + } + template StringSwitch& Cases(const char (&S0)[N0], const char (&S1)[N1], const T& Value) {