#if !UCONFIG_NO_BREAK_ITERATION // Read-only alias to the original string contents for the titlecasing BreakIterator. // We cannot set the iterator simply to *this because *this is being modified.
UnicodeString oldString; #endif
// Try to avoid heap-allocating a new character array for this string. if (writable ? oldLength <= UPRV_LENGTHOF(oldBuffer) : oldLength < US_STACKBUF_SIZE) { // Short string: Copy the contents into a temporary buffer and // case-map back into the current array, or into the stack buffer.
char16_t *buffer = getArrayStart();
int32_t capacity;
oldArray = oldBuffer;
u_memcpy(oldBuffer, buffer, oldLength); if (writable) {
capacity = getCapacity();
} else { // Switch from the read-only alias or shared heap buffer to the stack buffer. if (!cloneArrayIfNeeded(US_STACKBUF_SIZE, US_STACKBUF_SIZE, /* doCopyArray= */ false)) { return *this;
}
U_ASSERT(fUnion.fFields.fLengthAndFlags & kUsingStackBuffer);
buffer = fUnion.fStackFields.fBuffer;
capacity = US_STACKBUF_SIZE;
} #if !UCONFIG_NO_BREAK_ITERATION if (iter != nullptr) {
oldString.setTo(false, oldArray, oldLength);
iter->setText(oldString);
} #endif
newLength = stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
buffer, capacity,
oldArray, oldLength, nullptr, errorCode); if (U_SUCCESS(errorCode)) {
setLength(newLength); return *this;
} elseif (errorCode == U_BUFFER_OVERFLOW_ERROR) { // common overflow handling below
} else {
setToBogus(); return *this;
}
} else { // Longer string or read-only buffer: // Collect only changes and then apply them to this string. // Case mapping often changes only small parts of a string, // and often does not change its length.
oldArray = getArrayStart();
Edits edits;
char16_t replacementChars[200]; #if !UCONFIG_NO_BREAK_ITERATION if (iter != nullptr) {
oldString.setTo(false, oldArray, oldLength);
iter->setText(oldString);
} #endif
stringCaseMapper(caseLocale, options | U_OMIT_UNCHANGED_TEXT, UCASEMAP_BREAK_ITERATOR
replacementChars, UPRV_LENGTHOF(replacementChars),
oldArray, oldLength, &edits, errorCode); if (U_SUCCESS(errorCode)) { // Grow the buffer at most once, not for multiple doReplace() calls.
newLength = oldLength + edits.lengthDelta(); if (newLength > oldLength && !cloneArrayIfNeeded(newLength, newLength)) { return *this;
} for (Edits::Iterator ei = edits.getCoarseChangesIterator(); ei.next(errorCode);) {
doReplace(ei.destinationIndex(), ei.oldLength(),
replacementChars, ei.replacementIndex(), ei.newLength());
} if (U_FAILURE(errorCode)) {
setToBogus();
} return *this;
} elseif (errorCode == U_BUFFER_OVERFLOW_ERROR) { // common overflow handling below
newLength = oldLength + edits.lengthDelta();
} else {
setToBogus(); return *this;
}
}
// Handle buffer overflow, newLength is known. // We need to allocate a new buffer for the internal string case mapping function. // This is very similar to how doReplace() keeps the old array pointer // and deletes the old array itself after it is done. // In addition, we are forcing cloneArrayIfNeeded() to always allocate a new array.
int32_t *bufferToDelete = nullptr; if (!cloneArrayIfNeeded(newLength, newLength, false, &bufferToDelete, true)) { return *this;
}
errorCode = U_ZERO_ERROR; // No need to iter->setText() again: The case mapper restarts via iter->first().
newLength = stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
getArrayStart(), getCapacity(),
oldArray, oldLength, nullptr, errorCode); if (bufferToDelete) {
uprv_free(bufferToDelete);
} if (U_SUCCESS(errorCode)) {
setLength(newLength);
} else {
setToBogus();
} return *this;
}
// Defined here to reduce dependencies on break iterator
U_CAPI int32_t U_EXPORT2
uhash_hashCaselessUnicodeString(const UElement key) {
U_NAMESPACE_USE const UnicodeString *str = (const UnicodeString*) key.pointer; if (str == nullptr) { return 0;
} // Inefficient; a better way would be to have a hash function in // UnicodeString that does case folding on the fly.
UnicodeString copy(*str); return copy.foldCase().hashCode();
}
// Defined here to reduce dependencies on break iterator
U_CAPI UBool U_EXPORT2
uhash_compareCaselessUnicodeString(const UElement key1, const UElement key2) {
U_NAMESPACE_USE const UnicodeString *str1 = (const UnicodeString*) key1.pointer; const UnicodeString *str2 = (const UnicodeString*) key2.pointer; if (str1 == str2) { returntrue;
} if (str1 == nullptr || str2 == nullptr) { returnfalse;
} return str1->caseCompare(*str2, U_FOLD_CASE_DEFAULT) == 0;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.