diff options
Diffstat (limited to 'src/utils.cc')
-rw-r--r-- | src/utils.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/utils.cc b/src/utils.cc index d071fe6..a44eced 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -82,3 +82,21 @@ std::string utils::getCostString(int coppers) { } return utils::join(parts, ", "); } + +std::string utils::toOrdinal(std::size_t number) { + std::string suffix = "th"; + if (number % 100 < 11 || number % 100 > 13) { + switch (number % 10) { + case 1: + suffix = "st"; + break; + case 2: + suffix = "nd"; + break; + case 3: + suffix = "rd"; + break; + } + } + return std::to_string(number) + suffix; +} |