summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-02-05 19:22:46 +0100
committerBardur Arantsson <bardur@scientician.net>2016-02-05 19:22:46 +0100
commit5cecddb28bf224e06fc062ed430dd8322b2d3cff (patch)
tree346e26505e6db366d4d99a7dc3575b494244390a /src
parent0626333610e343551f88778320a04836f2d2b406 (diff)
Make get_day() return std::string
Diffstat (limited to 'src')
-rw-r--r--src/cmd4.cc5
-rw-r--r--src/util.cc38
-rw-r--r--src/util.hpp2
3 files changed, 30 insertions, 15 deletions
diff --git a/src/cmd4.cc b/src/cmd4.cc
index 4b6c040c..56728a86 100644
--- a/src/cmd4.cc
+++ b/src/cmd4.cc
@@ -4267,9 +4267,10 @@ void do_cmd_time()
strcpy(desc, "It is a strange time.");
/* Display day */
- u32b days = bst(DAY, turn) + 1;
+ auto days = bst(DAY, turn) + 1;
+ auto days_str = get_day(days);
msg_format("This is the %s day of your adventure.",
- get_day(days));
+ days_str.c_str());
/* Message */
msg_format("The time is %d:%02d %s.",
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)
diff --git a/src/util.hpp b/src/util.hpp
index bb8a64f4..6e7d74fa 100644
--- a/src/util.hpp
+++ b/src/util.hpp
@@ -10,7 +10,7 @@ extern bool_ input_box(cptr text, int y, int x, char *buf, int max);
extern void draw_box(int y, int x, int h, int w);
extern void display_list(int y, int x, int h, int w, cptr title, cptr *list, int max, int begin, int sel, byte sel_color);
extern cptr get_player_race_name(int pr, int ps);
-extern cptr get_day(int day);
+extern std::string get_day(s32b day);
extern s32b bst(s32b what, s32b t);
extern errr path_temp(char *buf, int max);
extern FILE *my_fopen(cptr file, cptr mode);