mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-31 07:53:36 +00:00
COMMON: fix String::rfind for default value of pos (max value of size_t)
This commit is contained in:
parent
f7b2bb0e66
commit
d136a5f54c
@ -325,9 +325,15 @@ size_t String::rfind(const char *s) const {
|
||||
}
|
||||
|
||||
size_t String::rfind(char c, size_t pos) const {
|
||||
for (int idx = MIN((int)_size - 1, (int)pos); idx >= 0; --idx) {
|
||||
if ((*this)[idx] == c)
|
||||
return idx;
|
||||
if (pos == npos || pos > _size)
|
||||
pos = _size;
|
||||
else
|
||||
++pos;
|
||||
|
||||
while (pos > 0) {
|
||||
--pos;
|
||||
if ((*this)[pos] == c)
|
||||
return pos;
|
||||
}
|
||||
|
||||
return npos;
|
||||
|
@ -570,6 +570,22 @@ class StringTestSuite : public CxxTest::TestSuite
|
||||
TS_ASSERT_EQUALS(s4, "TestTestTestTestTestTestTestTestTestTestTest");
|
||||
}
|
||||
|
||||
void test_find() {
|
||||
Common::String a("0123012"), b;
|
||||
|
||||
TS_ASSERT_EQUALS(a.find('1'), 1u);
|
||||
TS_ASSERT_EQUALS(a.find('3'), 3u);
|
||||
TS_ASSERT_EQUALS(a.find('1', 3), 5u);
|
||||
TS_ASSERT_EQUALS(b.find('*'), Common::String::npos);
|
||||
TS_ASSERT_EQUALS(b.find('*', 1), Common::String::npos);
|
||||
|
||||
TS_ASSERT_EQUALS(a.rfind('1'), 5u);
|
||||
TS_ASSERT_EQUALS(a.rfind('3'), 3u);
|
||||
TS_ASSERT_EQUALS(a.rfind('1', 3), 1u);
|
||||
TS_ASSERT_EQUALS(b.rfind('*'), Common::String::npos);
|
||||
TS_ASSERT_EQUALS(b.rfind('*', 1), Common::String::npos);
|
||||
}
|
||||
|
||||
void test_setChar() {
|
||||
Common::String testString("123456");
|
||||
testString.setChar('2', 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user