/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2012, International Business Machines Corporation and
+ * Copyright (c) 1997-2014, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
#endif
-#define LENGTHOF(array) (int32_t)((sizeof(array)/sizeof((array)[0])))
-
UnicodeStringTest::~UnicodeStringTest() {}
void UnicodeStringTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char *par)
}
UChar buffer[10]={ 0x61, 0x62, 0x20ac, 0xd900, 0xdc05, 0, 0x62, 0xffff, 0xdbff, 0xdfff };
- UnicodeString s, t(buffer, -1, LENGTHOF(buffer));
+ UnicodeString s, t(buffer, -1, UPRV_LENGTHOF(buffer));
- if(s.setTo(buffer, -1, LENGTHOF(buffer)).length()!=u_strlen(buffer)) {
+ if(s.setTo(buffer, -1, UPRV_LENGTHOF(buffer)).length()!=u_strlen(buffer)) {
errln("UnicodeString.setTo(buffer, length, capacity) does not work with length==-1");
}
if(t.length()!=u_strlen(buffer)) {
}
buffer[u_strlen(buffer)]=0xe4;
- UnicodeString u(buffer, -1, LENGTHOF(buffer));
- if(s.setTo(buffer, -1, LENGTHOF(buffer)).length()!=LENGTHOF(buffer)) {
+ UnicodeString u(buffer, -1, UPRV_LENGTHOF(buffer));
+ if(s.setTo(buffer, -1, UPRV_LENGTHOF(buffer)).length()!=UPRV_LENGTHOF(buffer)) {
errln("UnicodeString.setTo(buffer without NUL, length, capacity) does not work with length==-1");
}
- if(u.length()!=LENGTHOF(buffer)) {
+ if(u.length()!=UPRV_LENGTHOF(buffer)) {
errln("UnicodeString(buffer without NUL, length, capacity) does not work with length==-1");
}
static const UChar utf16[]={ 0x61, 0xE4, 0xDF, 0x4E00 };
UnicodeString from8a = UnicodeString((const char *)utf8);
UnicodeString from8b = UnicodeString((const char *)utf8, (int32_t)sizeof(utf8)-1);
- UnicodeString from16(FALSE, utf16, LENGTHOF(utf16));
+ UnicodeString from16(FALSE, utf16, UPRV_LENGTHOF(utf16));
if(from8a != from16 || from8b != from16) {
errln("UnicodeString(const char * U_CHARSET_IS_UTF8) failed");
}
errln("UnicodeString(shared buffer).remove().getTerminatedBuffer() "
"modified another copy of the string!");
}
+
+ // ticket #9740
+ test1.setTo(TRUE, ucs, 3);
+ assertEquals("length of read-only alias", 3, test1.length());
+ test1.trim();
+ assertEquals("length of read-only alias after trim()", 2, test1.length());
+ assertEquals("length of terminated buffer of read-only alias + trim()",
+ 2, u_strlen(test1.getTerminatedBuffer()));
}
void
0xd804, 0xdc04, 0xd805, 0xdc05,
0x67
};
- UnicodeString string(str, LENGTHOF(str));
+ UnicodeString string(str, UPRV_LENGTHOF(str));
int32_t start, length, number;
/* test hasMoreChar32Than() */
TestEnumeration() : i(0) {}
virtual int32_t count(UErrorCode& /*status*/) const {
- return LENGTHOF(testEnumStrings);
+ return UPRV_LENGTHOF(testEnumStrings);
}
virtual const UnicodeString *snext(UErrorCode &status) {
- if(U_SUCCESS(status) && i<LENGTHOF(testEnumStrings)) {
+ if(U_SUCCESS(status) && i<UPRV_LENGTHOF(testEnumStrings)) {
unistr=UnicodeString(testEnumStrings[i++], "");
return &unistr;
}
private:
static const char fgClassID;
- int32_t i, length;
+ int32_t i;
};
const char TestEnumeration::fgClassID=0;
const char *pc;
// test the next() default implementation and ensureCharsCapacity()
- for(i=0; i<LENGTHOF(testEnumStrings); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(testEnumStrings); ++i) {
status=U_ZERO_ERROR;
pc=ten.next(&length, status);
s=UnicodeString(testEnumStrings[i], "");
// test the unext() default implementation
ten.reset(status);
- for(i=0; i<LENGTHOF(testEnumStrings); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(testEnumStrings); ++i) {
status=U_ZERO_ERROR;
pu=ten.unext(&length, status);
s=UnicodeString(testEnumStrings[i], "");
}
// test uenum_next()
- for(i=0; i<LENGTHOF(testEnumStrings); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(testEnumStrings); ++i) {
status=U_ZERO_ERROR;
pc=uenum_next(uten, &length, &status);
if(U_FAILURE(status) || pc==NULL || strcmp(pc, testEnumStrings[i]) != 0) {
// test the uenum_unext()
uenum_reset(uten, &status);
- for(i=0; i<LENGTHOF(testEnumStrings); ++i) {
+ for(i=0; i<UPRV_LENGTHOF(testEnumStrings); ++i) {
status=U_ZERO_ERROR;
pu=uenum_unext(uten, &length, &status);
s=UnicodeString(testEnumStrings[i], "");
public:
enum EInvariant { kInvariant };
UnicodeString() : i(1) {}
- UnicodeString(UBool /*isTerminated*/, const UChar * /*text*/, int32_t textLength) : i(textLength) {}
+ UnicodeString(UBool /*isTerminated*/, const UChar * /*text*/, int32_t textLength) : i(textLength) {(void)i;}
UnicodeString(const char * /*src*/, int32_t length, enum EInvariant /*inv*/
) : i(length) {}
private:
0x41, 0xfffd, 0x61, 0xfffd, 0xfffd, 0xfffd, 0x5a, 0xd900, 0xdc00, 0x7a,
0xd800, 0xdc00, 0xd840, 0xdc00, 0xdb40, 0xdc00, 0xdbff, 0xdfff
};
- UnicodeString from32 = UnicodeString::fromUTF32(utf32, LENGTHOF(utf32));
- UnicodeString expected(FALSE, expected_utf16, LENGTHOF(expected_utf16));
+ UnicodeString from32 = UnicodeString::fromUTF32(utf32, UPRV_LENGTHOF(utf32));
+ UnicodeString expected(FALSE, expected_utf16, UPRV_LENGTHOF(expected_utf16));
if(from32 != expected) {
errln("UnicodeString::fromUTF32() did not create the expected string.");
}
UChar32 result32[16];
UErrorCode errorCode = U_ZERO_ERROR;
int32_t length32 =
- UnicodeString(FALSE, utf16, LENGTHOF(utf16)).
- toUTF32(result32, LENGTHOF(result32), errorCode);
- if( length32 != LENGTHOF(expected_utf32) ||
+ UnicodeString(FALSE, utf16, UPRV_LENGTHOF(utf16)).
+ toUTF32(result32, UPRV_LENGTHOF(result32), errorCode);
+ if( length32 != UPRV_LENGTHOF(expected_utf32) ||
0 != uprv_memcmp(result32, expected_utf32, length32*4) ||
result32[length32] != 0
) {
0xdb40, 0xdc00, 0xdbff, 0xdfff
};
UnicodeString from8 = UnicodeString::fromUTF8(StringPiece((const char *)utf8, (int32_t)sizeof(utf8)));
- UnicodeString expected(FALSE, expected_utf16, LENGTHOF(expected_utf16));
+ UnicodeString expected(FALSE, expected_utf16, UPRV_LENGTHOF(expected_utf16));
if(from8 != expected) {
errln("UnicodeString::fromUTF8(StringPiece) did not create the expected string.");
0x41, 0xef, 0xbf, 0xbd, 0x61, 0xef, 0xbf, 0xbd, 0x5a, 0xf1, 0x90, 0x80, 0x80, 0x7a,
0xf0, 0x90, 0x80, 0x80, 0xf4, 0x8f, 0xbf, 0xbf
};
- UnicodeString us(FALSE, utf16, LENGTHOF(utf16));
+ UnicodeString us(FALSE, utf16, UPRV_LENGTHOF(utf16));
char buffer[64];
TestCheckedArrayByteSink sink(buffer, (int32_t)sizeof(buffer));