return -1;
}
+int String::rfind(const String &s, int offset) const
+{
+ wstring::size_type position =
+ d->data.rfind(s.d->data, offset == -1 ? wstring::npos : offset);
+
+ if(position != wstring::npos)
+ return position;
+ else
+ return -1;
+}
+
bool String::startsWith(const String &s) const
{
if(s.length() > length())
*/
int find(const String &s, int offset = 0) const;
+ /*!
+ * Finds the last occurrence of pattern \a s in this string, searched backwards,
+ * either from the end of the string or starting from \a offset. If the pattern
+ * is not found, -1 is returned.
+ */
+ int rfind(const String &s, int offset = -1) const;
+
/*!
* Returns true if the strings starts with the substring \a s.
*/
{
CPPUNIT_TEST_SUITE(TestString);
CPPUNIT_TEST(testString);
+ CPPUNIT_TEST(testRfind);
CPPUNIT_TEST(testUTF16Encode);
CPPUNIT_TEST(testUTF16Decode);
CPPUNIT_TEST(testUTF16DecodeInvalidBOM);
CPPUNIT_ASSERT_EQUAL(String("a"), b);
}
+ void testRfind()
+ {
+ CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 0));
+ CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 1));
+ CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 2));
+ CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 3));
+ CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 4));
+ CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 5));
+ CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 6));
+ CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 7));
+ CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind("."));
+ }
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestString);