[llvm-commits] [llvm] r164440 - /llvm/trunk/include/llvm/ADT/StringExtras.h
Jordan Rose
jordan_rose at apple.com
Fri Sep 21 18:24:21 PDT 2012
Author: jrose
Date: Fri Sep 21 20:24:21 2012
New Revision: 164440
URL: http://llvm.org/viewvc/llvm-project?rev=164440&view=rev
Log:
Add llvm::getOrdinalSuffix to get the appropriate -st, -nd, -rd, -th suffix.
Used by clang to print parameter indexes.
Modified:
llvm/trunk/include/llvm/ADT/StringExtras.h
Modified: llvm/trunk/include/llvm/ADT/StringExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringExtras.h?rev=164440&r1=164439&r2=164440&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/StringExtras.h Fri Sep 21 20:24:21 2012
@@ -129,6 +129,25 @@
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
More information about the llvm-commits
mailing list