toUTF8(int32_t start, int32_t len,
char *target, int32_t capacity) const;
+ /**
+ * Internal string contents comparison, called by operator==.
+ * Requires: this & text not bogus and have same lengths.
+ */
+ UBool doEquals(const UnicodeString &text, int32_t len) const;
inline int8_t
doCompare(int32_t start,
return text.isBogus();
} else {
int32_t len = length(), textLength = text.length();
- return
- !text.isBogus() &&
- len == textLength &&
- doCompare(0, len, text, 0, textLength) == 0;
+ return !text.isBogus() && len == textLength && doEquals(text, len);
}
}
//========================================
// Read-only implementation
//========================================
+UBool
+UnicodeString::doEquals(const UnicodeString &text, int32_t len) const {
+ // Requires: this & text not bogus and have same lengths.
+ // Byte-wise comparison works for equality regardless of endianness.
+ return uprv_memcmp(getArrayStart(), text.getArrayStart(), len * U_SIZEOF_UCHAR) == 0;
+}
+
int8_t
UnicodeString::doCompare( int32_t start,
int32_t length,