diff options
author | Bardur Arantsson <bardur@scientician.net> | 2016-02-05 19:22:46 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2016-02-05 19:22:46 +0100 |
commit | 5cecddb28bf224e06fc062ed430dd8322b2d3cff (patch) | |
tree | 346e26505e6db366d4d99a7dc3575b494244390a /src/util.cc | |
parent | 0626333610e343551f88778320a04836f2d2b406 (diff) |
Make get_day() return std::string
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/util.cc b/src/util.cc index 08af0658..8f3374d5 100644 --- a/src/util.cc +++ b/src/util.cc @@ -27,6 +27,7 @@ #include <boost/algorithm/string/predicate.hpp> #include <chrono> +#include <sstream> #include <thread> using boost::algorithm::iequals; @@ -3196,7 +3197,7 @@ void repeat_check(void) * * Allow numbers of any size and save the last keypress. */ -u32b get_number(u32b def, u32b max, int y, int x, char *cmd) +static u32b get_number(u32b def, u32b max, int y, int x, char *cmd) { u32b res = def; @@ -3402,18 +3403,31 @@ s32b bst(s32b what, s32b t) } } -cptr get_day(int day) +std::string get_day(s32b day_no) { - static char buf[20]; - cptr p = "th"; - - if ((day / 10) == 1) ; - else if ((day % 10) == 1) p = "st"; - else if ((day % 10) == 2) p = "nd"; - else if ((day % 10) == 3) p = "rd"; - - sprintf(buf, "%d%s", day, p); - return (buf); + // Convert the number + std::string day(std::to_string(day_no)); + // Suffix + if ((day_no / 10) == 1) + { + return day + "th"; + } + else if ((day_no % 10) == 1) + { + return day + "st"; + } + else if ((day_no % 10) == 2) + { + return day + "nd"; + } + else if ((day_no % 10) == 3) + { + return day + "rd"; + } + else + { + return day + "th"; + } } cptr get_player_race_name(int pr, int ps) |