summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2016-03-10 18:41:54 +0100
committerBardur Arantsson <bardur@scientician.net>2016-03-10 19:02:23 +0100
commitf6812b19be995ddd26a318391a0f5311e4de11a6 (patch)
tree50660aad7586c7e2b6142c96995a4cd0675d2aea /src
parent66cb5538460d08241d384a5fc04d8628726abd43 (diff)
Rework scroll title generator to use std::string
Diffstat (limited to 'src')
-rw-r--r--src/object1.cc39
1 files changed, 14 insertions, 25 deletions
diff --git a/src/object1.cc b/src/object1.cc
index 096cadc5..cb935973 100644
--- a/src/object1.cc
+++ b/src/object1.cc
@@ -596,48 +596,37 @@ void flavor_init(void)
/* Get a new title */
while (TRUE)
{
- char buf[80];
-
- bool_ okay;
-
- /* Start a new title */
- buf[0] = '\0';
+ std::string buf;
/* Collect words until done */
while (1)
{
- int q, s;
-
- char tmp[80];
-
- /* Start a new word */
- tmp[0] = '\0';
-
/* Choose one or two syllables */
- s = ((rand_int(100) < 30) ? 1 : 2);
+ int s = ((rand_int(100) < 30) ? 1 : 2);
/* Add a one or two syllable word */
- for (q = 0; q < s; q++)
+ std::string tmp;
+ for (int q = 0; q < s; q++)
{
- /* Add the syllable */
- strcat(tmp, syllables[rand_int(MAX_SYLLABLES)]);
+ tmp += syllables[rand_int(MAX_SYLLABLES)];
}
/* Stop before getting too long */
- if (strlen(buf) + 1 + strlen(tmp) > 15) break;
-
- /* Add a space */
- strcat(buf, " ");
+ if (buf.size() + tmp.size() + 1 > 15)
+ {
+ break;
+ }
- /* Add the word */
- strcat(buf, tmp);
+ /* Add the word with separator */
+ buf += " ";
+ buf += tmp;
}
/* Save the title */
- strcpy(scroll_adj[i], buf + 1);
+ strcpy(scroll_adj[i], buf.c_str());
/* Assume okay */
- okay = TRUE;
+ bool_ okay = TRUE;
/* Check for "duplicate" scroll titles */
for (j = 0; j < i; j++)