summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/strgen/strgen.cpp3
-rw-r--r--src/strings.cpp23
2 files changed, 10 insertions, 16 deletions
diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp
index 236597cdd..167af24f0 100644
--- a/src/strgen/strgen.cpp
+++ b/src/strgen/strgen.cpp
@@ -327,9 +327,10 @@ static int TranslateArgumentIdx(int arg);
static void EmitWordList(const char * const *words, uint nw)
{
PutByte(nw);
- for (uint i = 0; i < nw; i++) PutByte(strlen(words[i]));
+ for (uint i = 0; i < nw; i++) PutByte(strlen(words[i]) + 1);
for (uint i = 0; i < nw; i++) {
for (uint j = 0; words[i][j] != '\0'; j++) PutByte(words[i][j]);
+ PutByte(0);
}
}
diff --git a/src/strings.cpp b/src/strings.cpp
index 25c992e44..e05229f1b 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -190,7 +190,7 @@ static char *FormatNumber(char *buff, int64 number, const char *last, const char
uint64 num;
if (number < 0) {
- *buff++ = '-';
+ buff += seprintf(buff, last, "-");
number = -number;
}
@@ -460,22 +460,19 @@ static int DeterminePluralForm(int64 count)
}
}
-static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen)
+static const char *ParseStringChoice(const char *b, uint form, char **dst, const char *last)
{
/* <NUM> {Length of each string} {each string} */
uint n = (byte)*b++;
- uint pos, i, mylen = 0, mypos = 0;
+ uint pos, i, mypos = 0;
for (i = pos = 0; i != n; i++) {
uint len = (byte)*b++;
- if (i == form) {
- mypos = pos;
- mylen = len;
- }
+ if (i == form) mypos = pos;
pos += len;
}
- *dstlen = mylen;
- memcpy(dst, b + mypos, mylen);
+
+ *dst += seprintf(*dst, last, "%s", b + mypos);
return b + pos;
}
@@ -717,7 +714,6 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
case SCC_GENDER_LIST: { // {G 0 Der Die Das}
const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
- int len;
int gender = 0;
if (s != NULL) {
wchar_t c = Utf8Consume(&s);
@@ -731,8 +727,7 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
/* Does this string have a gender, if so, set it */
if (c == SCC_GENDER_INDEX) gender = (byte)s[0];
}
- str = ParseStringChoice(str, gender, buff, &len);
- buff += len;
+ str = ParseStringChoice(str, gender, &buff, last);
break;
}
@@ -831,9 +826,7 @@ static char *FormatString(char *buff, const char *str, int64 *argv, uint casei,
case SCC_PLURAL_LIST: { // {P}
int64 v = argv_orig[(byte)*str++]; // contains the number that determines plural
- int len;
- str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len);
- buff += len;
+ str = ParseStringChoice(str, DeterminePluralForm(v), &buff, last);
break;
}