diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2012-09-22 01:24:21 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2012-09-22 01:24:21 +0000 |
| commit | d2718b1fedd724d734c01570e45d694964737879 (patch) | |
| tree | 787980c0099a692785c984e2d2e3b2ae139dbc39 /llvm | |
| parent | f8b0a5e9e348c0afe8e1e49d6c5c8c90935ca766 (diff) | |
| download | bcm5719-llvm-d2718b1fedd724d734c01570e45d694964737879.tar.gz bcm5719-llvm-d2718b1fedd724d734c01570e45d694964737879.zip | |
Add llvm::getOrdinalSuffix to get the appropriate -st, -nd, -rd, -th suffix.
Used by clang to print parameter indexes.
llvm-svn: 164440
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/ADT/StringExtras.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index 1ba60ed114f..bf27c4313f8 100644 --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/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 |

