/*
********************************************************************************
-* Copyright (C) 1996-2008, International Business Machines
+* Copyright (C) 1996-2013, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*/
U_CAPI UBreakIterator * U_EXPORT2
ubrk_safeClone(
const UBreakIterator *bi,
- void *stackBuffer,
+ void * /*stackBuffer*/,
int32_t *pBufferSize,
UErrorCode *status)
{
if (status == NULL || U_FAILURE(*status)){
- return 0;
+ return NULL;
}
- if (!pBufferSize || !bi){
+ if (bi == NULL) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return 0;
+ return NULL;
+ }
+ if (pBufferSize != NULL) {
+ int32_t inputSize = *pBufferSize;
+ *pBufferSize = 1;
+ if (inputSize == 0) {
+ return NULL; // preflighting for deprecated functionality
+ }
}
- // Clear any incoming Safe Clone Allocated warning.
- // Propagating this through to our return would really
- // confuse our caller.
- if (*status==U_SAFECLONE_ALLOCATED_WARNING) {
- *status = U_ZERO_ERROR;
+ BreakIterator *newBI = ((BreakIterator *)bi)->clone();
+ if (newBI == NULL) {
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ *status = U_SAFECLONE_ALLOCATED_WARNING;
}
- return (UBreakIterator *)(((BreakIterator*)bi)->
- createBufferClone(stackBuffer, *pBufferSize, *status));
+ return (UBreakIterator *)newBI;
}
U_CAPI void U_EXPORT2
ubrk_close(UBreakIterator *bi)
{
- BreakIterator *ubi = (BreakIterator*) bi;
- if (ubi) {
- if (ubi->isBufferClone()) {
- ubi->~BreakIterator();
- *(uint32_t *)ubi = 0xdeadbeef;
- } else {
- delete ubi;
- }
- }
+ delete (BreakIterator *)bi;
}
U_CAPI void U_EXPORT2
int32_t textLength,
UErrorCode* status)
{
- if (bi == NULL) {
- if (U_SUCCESS(*status)) {
- *status = U_ILLEGAL_ARGUMENT_ERROR;
- }
- return;
- }
-
BreakIterator *brit = (BreakIterator *)bi;
UText ut = UTEXT_INITIALIZER;
utext_openUChars(&ut, text, textLength, status);
brit->setText(&ut, *status);
- // A stack allocated UText wrapping a UCHar * string
+ // A stack allocated UText wrapping a UChar * string
// can be dumped without explicitly closing it.
}
UText *text,
UErrorCode *status)
{
- if (bi == NULL) {
- if (U_SUCCESS(*status)) {
- *status = U_ILLEGAL_ARGUMENT_ERROR;
- }
- return;
- }
-
RuleBasedBreakIterator *brit = (RuleBasedBreakIterator *)bi;
brit->RuleBasedBreakIterator::setText(text, *status);
}
}
+void ubrk_refreshUText(UBreakIterator *bi,
+ UText *text,
+ UErrorCode *status)
+{
+ BreakIterator *bii = reinterpret_cast<BreakIterator *>(bi);
+ bii->refreshInputText(text, *status);
+}
+
+
+
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */