aboutsummaryrefslogtreecommitdiff
path: root/common/str.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/str.cpp')
-rw-r--r--common/str.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 223188bdd6..32f4b44e79 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -25,8 +25,6 @@
#include "common/str.h"
#include "common/util.h"
-#include <stdarg.h>
-
namespace Common {
MemoryPool *g_refCountPool = 0; // FIXME: This is never freed right now
@@ -407,7 +405,7 @@ void String::trim() {
makeUnique();
// Trim trailing whitespace
- while (_size >= 1 && isspace(_str[_size - 1]))
+ while (_size >= 1 && isspace(static_cast<unsigned char>(_str[_size - 1])))
--_size;
_str[_size] = 0;
@@ -429,10 +427,22 @@ uint String::hash() const {
// static
String String::format(const char *fmt, ...) {
String output;
- assert(output.isStorageIntern());
va_list va;
va_start(va, fmt);
+ output = String::vformat(fmt, va);
+ va_end(va);
+
+ return output;
+}
+
+// static
+String String::vformat(const char *fmt, va_list args) {
+ String output;
+ assert(output.isStorageIntern());
+
+ va_list va;
+ scumm_va_copy(va, args);
int len = vsnprintf(output._str, _builtinCapacity, fmt, va);
va_end(va);
@@ -457,7 +467,7 @@ String String::format(const char *fmt, ...) {
assert(!output.isStorageIntern());
size = output._extern._capacity;
- va_start(va, fmt);
+ scumm_va_copy(va, args);
len = vsnprintf(output._str, size, fmt, va);
va_end(va);
} while (len == -1 || len >= size - 1);
@@ -468,7 +478,7 @@ String String::format(const char *fmt, ...) {
} else {
// vsnprintf didn't have enough space, so grow buffer
output.ensureCapacity(len, false);
- va_start(va, fmt);
+ scumm_va_copy(va, args);
int len2 = vsnprintf(output._str, len+1, fmt, va);
va_end(va);
assert(len == len2);
@@ -596,14 +606,14 @@ String operator+(const String &x, char y) {
}
char *ltrim(char *t) {
- while (isspace(*t))
+ while (isspace(static_cast<unsigned char>(*t)))
t++;
return t;
}
char *rtrim(char *t) {
int l = strlen(t) - 1;
- while (l >= 0 && isspace(t[l]))
+ while (l >= 0 && isspace(static_cast<unsigned char>(t[l])))
t[l--] = 0;
return t;
}