]> granicus.if.org Git - taglib/commitdiff
A bit more tolerant check to return itself in String::substr().
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 26 Nov 2016 04:05:14 +0000 (13:05 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 26 Nov 2016 04:05:14 +0000 (13:05 +0900)
taglib/toolkit/tstring.cpp
tests/test_string.cpp

index ee8d04d1a9eda27339d0bb8af4781ae4c404b277..1639d7c5057ae01783afadce55749597577aad51 100644 (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));
index b99c3f304b678b0c84018cd40d17309e696cd728..4e3a1ac5381a944b548d047563217143fbf59625 100644 (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()