[Scummvm-git-logs] scummvm master -> 3441c7230d44d856a74d3699efd0d7ae78398c31
sev-
noreply at scummvm.org
Sun Nov 20 13:23:33 UTC 2022
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
29024cded7 COMMON: Fix handling negative numbers in Common::U32String::format
3441c7230d COMMON: Fix handling escaped percents in Common::U32String::format
Commit: 29024cded72cbce3d138bc4d697a6a4e02a3a4bc
https://github.com/scummvm/scummvm/commit/29024cded72cbce3d138bc4d697a6a4e02a3a4bc
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2022-11-20T14:23:30+01:00
Commit Message:
COMMON: Fix handling negative numbers in Common::U32String::format
Changed paths:
common/ustr.cpp
common/ustr.h
test/common/str.h
diff --git a/common/ustr.cpp b/common/ustr.cpp
index 531eddfc185..6cfda39cf10 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -176,6 +176,7 @@ U32String U32String::format(const char *fmt, ...) {
int U32String::vformat(const value_type *fmt, const value_type *fmtEnd, U32String &output, va_list args) {
int int_temp;
+ uint uint_temp;
char *string_temp;
value_type ch;
@@ -221,8 +222,8 @@ int U32String::vformat(const value_type *fmt, const value_type *fmtEnd, U32Strin
pos += len - 1;
break;
case 'u':
- int_temp = va_arg(args, uint);
- itoa(int_temp, buffer, 10);
+ uint_temp = va_arg(args, uint);
+ uitoa(uint_temp, buffer, 10);
len = strlen(buffer);
length += len;
@@ -247,7 +248,18 @@ int U32String::vformat(const value_type *fmt, const value_type *fmtEnd, U32Strin
return length;
}
-char* U32String::itoa(int num, char* str, int base) {
+char* U32String::itoa(int num, char* str, uint base) {
+ if (num < 0) {
+ str[0] = '-';
+ uitoa(-num, str + 1, base);
+ } else {
+ uitoa(num, str, base);
+ }
+
+ return str;
+}
+
+char* U32String::uitoa(uint num, char* str, uint base) {
int i = 0;
if (num) {
diff --git a/common/ustr.h b/common/ustr.h
index b6cf316ef4e..5687fce60ec 100644
--- a/common/ustr.h
+++ b/common/ustr.h
@@ -156,12 +156,6 @@ public:
*/
static int vformat(const value_type *fmt, const value_type *fmtEnd, U32String &output, va_list args);
- /**
- * Helper function for vformat. Convert an int to string.
- * Minimal implementation, only for base 10.
- */
- static char* itoa(int num, char* str, int base);
-
using BaseString<value_type>::insertString;
void insertString(const char *s, uint32 p, CodePage page = kUtf8); /*!< Insert string @p s into this string at position @p p. */
void insertString(const String &s, uint32 p, CodePage page = kUtf8); /*!< @overload */
@@ -194,6 +188,18 @@ public:
private:
static U32String formatInternal(const U32String *fmt, ...);
+ /**
+ * Helper function for vformat. Convert an int to a string.
+ * Minimal implementation, only for base 10.
+ */
+ static char* itoa(int num, char* str, uint base);
+
+ /**
+ * Helper function for vformat. Convert an unsigned int to a string.
+ * Minimal implementation, only for base 10.
+ */
+ static char* uitoa(uint num, char* str, uint base);
+
void decodeInternal(const char *str, uint32 len, CodePage page);
void decodeOneByte(const char *str, uint32 len, CodePage page);
void decodeWindows932(const char *src, uint32 len);
diff --git a/test/common/str.h b/test/common/str.h
index 598051aea89..fc28d506e4a 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -370,6 +370,13 @@ class StringTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS( Common::U32String::format("%s", "test").encode(), "test" );
TS_ASSERT_EQUALS( Common::U32String::format("%s%c%s", "Press ", 'X', " to win").encode(), "Press X to win" );
TS_ASSERT_EQUALS( Common::U32String::format("Some %s to make this string longer than the default built-in %s %d", "text", "capacity", 123456).encode(), "Some text to make this string longer than the default built-in capacity 123456" );
+
+ TS_ASSERT_EQUALS( Common::U32String::format("%u", 0).encode(), "0" );
+ TS_ASSERT_EQUALS( Common::U32String::format("%u", 1234).encode(), "1234" );
+
+ TS_ASSERT_EQUALS( Common::U32String::format("%d", 0).encode(), "0" );
+ TS_ASSERT_EQUALS( Common::U32String::format("%d", 1234).encode(), "1234" );
+ TS_ASSERT_EQUALS( Common::U32String::format("%d", -1234).encode(), "-1234" );
}
void test_strlcpy() {
Commit: 3441c7230d44d856a74d3699efd0d7ae78398c31
https://github.com/scummvm/scummvm/commit/3441c7230d44d856a74d3699efd0d7ae78398c31
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2022-11-20T14:23:30+01:00
Commit Message:
COMMON: Fix handling escaped percents in Common::U32String::format
Changed paths:
common/ustr.cpp
test/common/str.h
diff --git a/common/ustr.cpp b/common/ustr.cpp
index 6cfda39cf10..6e70b0598d7 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -236,6 +236,10 @@ int U32String::vformat(const value_type *fmt, const value_type *fmtEnd, U32Strin
output.insertChar(int_temp, pos);
++length;
break;
+ case '%':
+ output.insertChar('%', pos);
+ ++length;
+ break;
default:
warning("Unexpected formatting type for U32String::Format.");
break;
diff --git a/test/common/str.h b/test/common/str.h
index fc28d506e4a..9321f38bd72 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -377,6 +377,8 @@ class StringTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS( Common::U32String::format("%d", 0).encode(), "0" );
TS_ASSERT_EQUALS( Common::U32String::format("%d", 1234).encode(), "1234" );
TS_ASSERT_EQUALS( Common::U32String::format("%d", -1234).encode(), "-1234" );
+
+ TS_ASSERT_EQUALS( Common::U32String::format("%u %%", 100).encode(), "100 %" );
}
void test_strlcpy() {
More information about the Scummvm-git-logs
mailing list