[llvm-branch-commits] [llvm-branch] r164516 - /llvm/branches/R600/include/llvm/ADT/StringExtras.h

Tom Stellard thomas.stellard at amd.com
Mon Sep 24 08:53:49 PDT 2012


Author: tstellar
Date: Mon Sep 24 10:52:08 2012
New Revision: 164516

URL: http://llvm.org/viewvc/llvm-project?rev=164516&view=rev
Log:
Add llvm::getOrdinalSuffix to get the appropriate -st, -nd, -rd, -th suffix.

Used by clang to print parameter indexes.

Modified:
    llvm/branches/R600/include/llvm/ADT/StringExtras.h

Modified: llvm/branches/R600/include/llvm/ADT/StringExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/R600/include/llvm/ADT/StringExtras.h?rev=164516&r1=164515&r2=164516&view=diff
==============================================================================
--- llvm/branches/R600/include/llvm/ADT/StringExtras.h (original)
+++ llvm/branches/R600/include/llvm/ADT/StringExtras.h Mon Sep 24 10:52:08 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-branch-commits mailing list