X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FStringExtras.h;h=9503e0f805a76d5195e9fffcc63fa3943bc2807e;hb=105fdbb1312bac8c46ba2e28e9d6a70c0af151c8;hp=1ba60ed114f4f1a38d2c9f10a8b61e1cf99244e4;hpb=2d9eb72178af8e79dc6432cd1b7d29bde16da1b9;p=oota-llvm.git diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h index 1ba60ed114f..9503e0f805a 100644 --- a/include/llvm/ADT/StringExtras.h +++ b/include/llvm/ADT/StringExtras.h @@ -14,8 +14,8 @@ #ifndef LLVM_ADT_STRINGEXTRAS_H #define LLVM_ADT_STRINGEXTRAS_H -#include "llvm/Support/DataTypes.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/DataTypes.h" namespace llvm { template class SmallVectorImpl; @@ -129,6 +129,25 @@ static inline unsigned HashString(StringRef Str, unsigned Result = 0) { return Result; } +/// Returns the English suffix for an ordinal integer (-st, -nd, -rd, -th). +static inline StringRef getOrdinalSuffix(unsigned Val) { + // It is critically important that we do this perfectly for + // user-written sequences with over 100 elements. + switch (Val % 100) { + case 11: + case 12: + case 13: + return "th"; + default: + switch (Val % 10) { + case 1: return "st"; + case 2: return "nd"; + case 3: return "rd"; + default: return "th"; + } + } +} + } // End llvm namespace #endif