[Scummvm-git-logs] scummvm master -> 8ddcbf8120b8e56bbc29c828edc216a55c23e98d
whoozle
vladimir.menshakov at gmail.com
Wed Sep 2 19:36:32 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
8ddcbf8120 COMMON: Fix warnings about different signedness (uint32/char comparison), remove unused var
Commit: 8ddcbf8120b8e56bbc29c828edc216a55c23e98d
https://github.com/scummvm/scummvm/commit/8ddcbf8120b8e56bbc29c828edc216a55c23e98d
Author: Vladimir Menshakov (vladimir.menshakov at gmail.com)
Date: 2020-09-02T20:35:43+01:00
Commit Message:
COMMON: Fix warnings about different signedness (uint32/char comparison), remove unused var
Add tests for both str/ustr comparison operators.
Changed paths:
common/ustr.cpp
test/common/str.h
diff --git a/common/ustr.cpp b/common/ustr.cpp
index 18e3957520..5e247c2c87 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -199,10 +199,12 @@ bool U32String::operator!=(const char *x) const {
}
bool U32String::operator<(const String &x) const {
- for (int i = 0 ; i < _size && i < x.size() ; ++i) {
- if (_str[i] < x[i])
+ for (uint32 i = 0, n = x.size(); i < _size && i < n; ++i) {
+ uint32 sc = _str[i];
+ uint8 xc = x[i];
+ if (sc < xc)
return true;
- else if (_str[i] > x[i])
+ else if (sc > xc)
return false;
}
return (_size < x.size());
@@ -213,10 +215,12 @@ bool U32String::operator<=(const String &x) const {
}
bool U32String::operator>(const String &x) const {
- for (int i = 0 ; i < _size && i < x.size() ; ++i) {
- if (_str[i] > x[i])
+ for (uint i = 0, n = x.size(); i < _size && i < n; ++i) {
+ uint32 sc = _str[i];
+ uint8 xc = x[i];
+ if (sc > xc)
return true;
- else if (_str[i] < x[i])
+ else if (sc < xc)
return false;
}
return (_size > x.size());
@@ -242,8 +246,8 @@ bool U32String::equals(const String &x) const {
if (x.size() != _size)
return false;
- for (size_t idx = 0; idx < _size; ++idx)
- if (_str[idx] != (value_type)x[idx])
+ for (uint32 idx = 0; idx < _size; ++idx)
+ if (_str[idx] != static_cast<value_type>(x[idx]))
return false;
return true;
@@ -626,11 +630,10 @@ void U32String::trim() {
U32String U32String::format(U32String fmt, ...) {
U32String output;
- int len;
va_list va;
va_start(va, fmt);
- len = U32String::vformat(fmt.begin(), fmt.end(), output, va);
+ U32String::vformat(fmt.begin(), fmt.end(), output, va);
va_end(va);
return output;
diff --git a/test/common/str.h b/test/common/str.h
index c6a6e7bed6..6d5a95aba7 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -1,6 +1,7 @@
#include <cxxtest/TestSuite.h>
#include "common/str.h"
+#include "common/ustr.h"
class StringTestSuite : public CxxTest::TestSuite
{
@@ -567,4 +568,48 @@ class StringTestSuite : public CxxTest::TestSuite
testString.insertChar('0', 5);
TS_ASSERT(testString == "21234056");
}
+
+ void test_comparison() {
+ Common::String a("0123"), ax("01234"), b("0124"), e;
+ TS_ASSERT_EQUALS(a, a);
+ TS_ASSERT_EQUALS(ax, ax);
+ TS_ASSERT_EQUALS(b, b);
+ TS_ASSERT_EQUALS(e, e);
+
+ TS_ASSERT_DIFFERS(a, ax);
+ TS_ASSERT_DIFFERS(a, b);
+ TS_ASSERT_DIFFERS(a, e);
+ TS_ASSERT_DIFFERS(ax, b);
+ TS_ASSERT_DIFFERS(ax, e);
+ TS_ASSERT_DIFFERS(b, ax);
+ TS_ASSERT_DIFFERS(b, e);
+
+ TS_ASSERT_LESS_THAN(e, a);
+ TS_ASSERT_LESS_THAN(e, ax);
+ TS_ASSERT_LESS_THAN(e, b);
+ TS_ASSERT_LESS_THAN(a, ax);
+ TS_ASSERT_LESS_THAN(a, b);
+ TS_ASSERT_LESS_THAN(ax, b);
+ }
+
+ void test_ustr_comparison() {
+ Common::U32String a("abc"), b("abd");
+
+ TS_ASSERT_EQUALS(a, a);
+ TS_ASSERT_EQUALS(b, b);
+
+ TS_ASSERT_DIFFERS(a, b);
+
+ TS_ASSERT_LESS_THAN(a, b);
+
+ TS_ASSERT_LESS_THAN_EQUALS(a, b);
+ TS_ASSERT_LESS_THAN_EQUALS(a, a);
+ TS_ASSERT_LESS_THAN_EQUALS(b, b);
+
+ //U32String does not define compare, so test both sides
+ TS_ASSERT(a >= a);
+ TS_ASSERT(b > a);
+ TS_ASSERT(b >= b);
+ TS_ASSERT(b >= a);
+ }
};
More information about the Scummvm-git-logs
mailing list