{ return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
inline UBool
-UnicodeString::startsWith(const UChar *srcChars,
- int32_t srcLength) const
-{ return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
+UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const {
+ if(srcLength < 0) {
+ srcLength = u_strlen(srcChars);
+ }
+ return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
+}
inline UBool
-UnicodeString::startsWith(const UChar *srcChars,
- int32_t srcStart,
- int32_t srcLength) const
-{ return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
+UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const {
+ if(srcLength < 0) {
+ srcLength = u_strlen(srcChars);
+ }
+ return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
+}
inline UBool
UnicodeString::endsWith(const UnicodeString& text) const
case 20: name = "TestAppendable"; if (exec) TestAppendable(); break;
case 21: name = "TestUnicodeStringImplementsAppendable"; if (exec) TestUnicodeStringImplementsAppendable(); break;
case 22: name = "TestSizeofUnicodeString"; if (exec) TestSizeofUnicodeString(); break;
+ case 23: name = "TestStartsWithAndEndsWithNulTerminated"; if (exec) TestStartsWithAndEndsWithNulTerminated(); break;
default: name = ""; break; //needed to end loop
}
}
}
+void
+UnicodeStringTest::TestStartsWithAndEndsWithNulTerminated() {
+ UnicodeString test("abcde");
+ const UChar ab[] = { 0x61, 0x62, 0 };
+ const UChar de[] = { 0x64, 0x65, 0 };
+ assertTrue("abcde.startsWith(ab, -1)", test.startsWith(ab, -1));
+ assertTrue("abcde.startsWith(ab, 0, -1)", test.startsWith(ab, 0, -1));
+ assertTrue("abcde.endsWith(de, -1)", test.endsWith(de, -1));
+ assertTrue("abcde.endsWith(de, 0, -1)", test.endsWith(de, 0, -1));
+}
+
void
UnicodeStringTest::TestFindAndReplace()
{
* Test methods startsWith and endsWith
**/
void TestPrefixAndSuffix(void);
+ void TestStartsWithAndEndsWithNulTerminated();
/**
* Test method findAndReplace
**/