From cadc5c2a4976617227d92fb0f72943e360f2c00b Mon Sep 17 00:00:00 2001 From: Jim Snyder Grant Date: Fri, 16 Feb 2001 22:42:45 +0000 Subject: [PATCH] ICU-853 APIs for ucol_safeClone & ubrk_safeClone X-SVN-Rev: 3660 --- icu4c/source/i18n/unicode/ubrk.h | 27 +++++++++++++++++++++++++++ icu4c/source/i18n/unicode/ucol.h | 24 ++++++++++++++++++++---- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/icu4c/source/i18n/unicode/ubrk.h b/icu4c/source/i18n/unicode/ubrk.h index 51c6a5da446..1e3f78f93b8 100644 --- a/icu4c/source/i18n/unicode/ubrk.h +++ b/icu4c/source/i18n/unicode/ubrk.h @@ -223,6 +223,33 @@ ubrk_openRules(const UChar *rules, int32_t textLength, UErrorCode *status); +/** + * Thread safe cloning operation + * @param bi iterator to be cloned + * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated. + If buffer is not large enough, new memory will be allocated. + Clients can use the U_BRK_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations. + * @param pBufferSize pointer to size of allocated space. + If *pBufferSize == 0, a sufficient size for use in cloning will + be returned ('pre-flighting') + If *pBufferSize is not enough for a stack-based safe clone, + new memory will be allocated. + * @param status to indicate whether the operation went on smoothly or there were errors + An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were necessary. + * @return pointer to the new clone + * @draft API 1.8 freeze + */ + + +U_CAPI UBreakIterator * +ubrk_safeClone( + const UBreakIterator *bi, + void *stackBuffer, + int32_t *pBufferSize, + UErrorCode *status); + +#define U_BRK_SAFECLONE_BUFFERSIZE 512 + /** * Close a UBreakIterator. * Once closed, a UBreakIterator may no longer be used. diff --git a/icu4c/source/i18n/unicode/ucol.h b/icu4c/source/i18n/unicode/ucol.h index b87e081187f..21d3110479c 100644 --- a/icu4c/source/i18n/unicode/ucol.h +++ b/icu4c/source/i18n/unicode/ucol.h @@ -527,13 +527,29 @@ U_CAPI UColAttributeValue ucol_getAttribute(const UCollator *coll, UColAttribute /** * Thread safe cloning operation * @param coll collator to be cloned - * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated - * @param bufferSize size of allocated space. If not enough new memory will be allocated. + * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated. + If buffer is not lareg enough, new memory will be allocated. + Clients can use the U_COL_SAFECLONE_BUFFERSIZE. + This will probably be enough to avoid memory allocations. + * @param pBufferSize pointer to size of allocated space. + If *pBufferSize == 0, a sufficient size for use in cloning will + be returned ('pre-flighting') + If *pBufferSize is not enough for a stack-based safe clone, + new memory will be allocated. * @param status to indicate whether the operation went on smoothly or there were errors + An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were necessary. * @return pointer to the new clone - * @draft API 1.7 freeze + * @draft API 1.8 freeze */ -U_CAPI UCollator *ucol_safeClone(const UCollator *coll, void *stackBuffer, uint32_t bufferSize, UErrorCode *status); + + +U_CAPI UCollator * ucol_safeClone( + const UCollator *coll, + void *stackBuffer, + int32_t *pBufferSize, + UErrorCode *status); + +#define U_COL_SAFECLONE_BUFFERSIZE 256 /* declaration for forward iterating function */ typedef UChar UCharForwardIterator(void *context);