X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/51004dcb01e06fef634b61be77ed73dd61cb6db9..b331163bffd790ced0e88b73f44f86d49ccc48a5:/icuSources/common/utext.cpp diff --git a/icuSources/common/utext.cpp b/icuSources/common/utext.cpp index 396ee077..6dc31a04 100644 --- a/icuSources/common/utext.cpp +++ b/icuSources/common/utext.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2005-2012, International Business Machines +* Copyright (C) 2005-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -516,8 +516,17 @@ utext_copy(UText *ut, U_CAPI UText * U_EXPORT2 utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCode *status) { - UText *result; - result = src->pFuncs->clone(dest, src, deep, status); + if (U_FAILURE(*status)) { + return dest; + } + UText *result = src->pFuncs->clone(dest, src, deep, status); + if (U_FAILURE(*status)) { + return result; + } + if (result == NULL) { + *status = U_MEMORY_ALLOCATION_ERROR; + return result; + } if (readOnly) { utext_freeze(result); } @@ -806,6 +815,11 @@ shallowTextClone(UText * dest, const UText * src, UErrorCode * status) { adjustPointer(dest, &dest->r, src); adjustPointer(dest, (const void **)&dest->chunkContents, src); + // The newly shallow-cloned UText does _not_ own the underlying storage for the text. + // (The source for the clone may or may not have owned the text.) + + dest->providerProperties &= ~I32_FLAG(UTEXT_PROVIDER_OWNS_TEXT); + return dest; } @@ -1575,7 +1589,7 @@ utf8TextClose(UText *ut) { U_CDECL_END -static const struct UTextFuncs utf8Funcs = +static const struct UTextFuncs utf8Funcs = { sizeof(UTextFuncs), 0, 0, 0, // Reserved alignment padding @@ -1862,7 +1876,7 @@ repTextExtract(UText *ut, UnicodeString buffer(dest, 0, destCapacity); // writable alias rep->extractBetween(start32, limit32, buffer); repTextAccess(ut, limit32, TRUE); - + return u_terminateUChars(dest, destCapacity, length, status); } @@ -1984,7 +1998,7 @@ repTextCopy(UText *ut, repTextAccess(ut, nativeIterIndex, TRUE); } -static const struct UTextFuncs repFuncs = +static const struct UTextFuncs repFuncs = { sizeof(UTextFuncs), 0, 0, 0, // Reserved alignment padding @@ -1992,8 +2006,8 @@ static const struct UTextFuncs repFuncs = repTextLength, repTextAccess, repTextExtract, - repTextReplace, - repTextCopy, + repTextReplace, + repTextCopy, NULL, // MapOffsetToNative, NULL, // MapIndexToUTF16, repTextClose, @@ -2235,7 +2249,7 @@ unistrTextCopy(UText *ut, } -static const struct UTextFuncs unistrFuncs = +static const struct UTextFuncs unistrFuncs = { sizeof(UTextFuncs), 0, 0, 0, // Reserved alignment padding @@ -2243,8 +2257,8 @@ static const struct UTextFuncs unistrFuncs = unistrTextLength, unistrTextAccess, unistrTextExtract, - unistrTextReplace, - unistrTextCopy, + unistrTextReplace, + unistrTextCopy, NULL, // MapOffsetToNative, NULL, // MapIndexToUTF16, unistrTextClose, @@ -2548,7 +2562,7 @@ ucstrTextExtract(UText *ut, return di; } -static const struct UTextFuncs ucstrFuncs = +static const struct UTextFuncs ucstrFuncs = { sizeof(UTextFuncs), 0, 0, 0, // Reserved alignment padding @@ -2765,14 +2779,14 @@ charIterTextExtract(UText *ut, } srci += len; } - + charIterTextAccess(ut, copyLimit, TRUE); u_terminateUChars(dest, destCapacity, desti, status); return desti; } -static const struct UTextFuncs charIterFuncs = +static const struct UTextFuncs charIterFuncs = { sizeof(UTextFuncs), 0, 0, 0, // Reserved alignment padding @@ -2832,6 +2846,3 @@ utext_openCharacterIterator(UText *ut, CharacterIterator *ci, UErrorCode *status } return ut; } - - -