Skip to content

Commit

Permalink
Add llvm::getOrdinalSuffix to get the appropriate -st, -nd, -rd, -th …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jrose-apple committed Sep 22, 2012
1 parent f5091b4 commit a2df2ba
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/llvm/ADT/StringExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a2df2ba

Please sign in to comment.