A bit more tolerant check to return itself in String::substr().

This commit is contained in:
Tsuda Kageyu 2016-11-26 13:05:14 +09:00
parent 7871afec37
commit d3062f3af4
2 changed files with 3 additions and 1 deletions

View File

@ -447,7 +447,7 @@ bool String::startsWith(const String &s) const
String String::substr(unsigned int position, unsigned int n) const
{
if(position == 0 && n == size())
if(position == 0 && n >= size())
return *this;
else
return String(d->data.substr(position, n));

View File

@ -257,6 +257,8 @@ public:
CPPUNIT_ASSERT_EQUAL(String("01"), String("0123456").substr(0, 2));
CPPUNIT_ASSERT_EQUAL(String("12"), String("0123456").substr(1, 2));
CPPUNIT_ASSERT_EQUAL(String("123456"), String("0123456").substr(1, 200));
CPPUNIT_ASSERT_EQUAL(String("0123456"), String("0123456").substr(0, 7));
CPPUNIT_ASSERT_EQUAL(String("0123456"), String("0123456").substr(0, 200));
}
void testNewline()