summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/StringExtras.h
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-09-22 01:24:21 +0000
committerJordan Rose <jordan_rose@apple.com>2012-09-22 01:24:21 +0000
commita2df2ba16a94bf20b9202594d01cfbf370c2091a (patch)
tree4f54987873c818c325f4e1cc3b00510535cde3e8 /include/llvm/ADT/StringExtras.h
parentf5091b476c46333ecfcf095cd2e422e9748e9546 (diff)
downloadllvm-a2df2ba16a94bf20b9202594d01cfbf370c2091a.tar.gz
llvm-a2df2ba16a94bf20b9202594d01cfbf370c2091a.tar.bz2
llvm-a2df2ba16a94bf20b9202594d01cfbf370c2091a.tar.xz
Add llvm::getOrdinalSuffix to get the appropriate -st, -nd, -rd, -th suffix.
Used by clang to print parameter indexes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164440 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/StringExtras.h')
-rw-r--r--include/llvm/ADT/StringExtras.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index 1ba60ed114..bf27c4313f 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -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