ICU-8691 fix UnicodeString::startsWith(const UChar *, -1 for NUL-terminated)
X-SVN-Rev: 30292
This commit is contained in:
parent
47a0559a84
commit
f0f91649ce
@ -3973,15 +3973,20 @@ UnicodeString::startsWith(const UnicodeString& srcText,
|
||||
{ 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
|
||||
|
@ -62,6 +62,7 @@ void UnicodeStringTest::runIndexedTest( int32_t index, UBool exec, const char* &
|
||||
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
|
||||
}
|
||||
@ -966,6 +967,17 @@ UnicodeStringTest::TestPrefixAndSuffix()
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
@ -54,6 +54,7 @@ public:
|
||||
* Test methods startsWith and endsWith
|
||||
**/
|
||||
void TestPrefixAndSuffix(void);
|
||||
void TestStartsWithAndEndsWithNulTerminated();
|
||||
/**
|
||||
* Test method findAndReplace
|
||||
**/
|
||||
|
Loading…
Reference in New Issue
Block a user