/*
********************************************************************************
-* Copyright (C) 1996-2012, 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;
}
- // 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;
+ if (pBufferSize != NULL) {
+ int32_t inputSize = *pBufferSize;
+ *pBufferSize = 1;
+ if (inputSize == 0) {
+ return NULL; // preflighting for deprecated functionality
+ }
+ }
+ 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)
{
- 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
+ ((BreakIterator*)bi)->setText(&ut, *status);
+ // A stack allocated UText wrapping a UChar * string
// can be dumped without explicitly closing it.
}
UText *text,
UErrorCode *status)
{
- RuleBasedBreakIterator *brit = (RuleBasedBreakIterator *)bi;
- brit->RuleBasedBreakIterator::setText(text, *status);
+ ((BreakIterator*)bi)->setText(text, *status);
}
ubrk_current(const UBreakIterator *bi)
{
- return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::current();
+ return ((BreakIterator*)bi)->current();
}
U_CAPI int32_t U_EXPORT2
ubrk_next(UBreakIterator *bi)
{
- return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::next();
+ return ((BreakIterator*)bi)->next();
}
U_CAPI int32_t U_EXPORT2
ubrk_previous(UBreakIterator *bi)
{
- return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::previous();
+ return ((BreakIterator*)bi)->previous();
}
U_CAPI int32_t U_EXPORT2
ubrk_first(UBreakIterator *bi)
{
- return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::first();
+ return ((BreakIterator*)bi)->first();
}
U_CAPI int32_t U_EXPORT2
ubrk_last(UBreakIterator *bi)
{
- return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::last();
+ return ((BreakIterator*)bi)->last();
}
U_CAPI int32_t U_EXPORT2
int32_t offset)
{
- return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::preceding(offset);
+ return ((BreakIterator*)bi)->preceding(offset);
}
U_CAPI int32_t U_EXPORT2
int32_t offset)
{
- return ((RuleBasedBreakIterator*)bi)->RuleBasedBreakIterator::following(offset);
+ return ((BreakIterator*)bi)->following(offset);
}
U_CAPI const char* U_EXPORT2
U_CAPI UBool U_EXPORT2
ubrk_isBoundary(UBreakIterator *bi, int32_t offset)
{
- return ((RuleBasedBreakIterator *)bi)->RuleBasedBreakIterator::isBoundary(offset);
+ return ((BreakIterator*)bi)->isBoundary(offset);
}
U_CAPI int32_t U_EXPORT2
ubrk_getRuleStatus(UBreakIterator *bi)
{
- return ((RuleBasedBreakIterator *)bi)->RuleBasedBreakIterator::getRuleStatus();
+ return ((BreakIterator*)bi)->getRuleStatus();
}
U_CAPI int32_t U_EXPORT2
ubrk_getRuleStatusVec(UBreakIterator *bi, int32_t *fillInVec, int32_t capacity, UErrorCode *status)
{
- return ((RuleBasedBreakIterator *)bi)->RuleBasedBreakIterator::getRuleStatusVec(fillInVec, capacity, *status);
+ return ((BreakIterator*)bi)->getRuleStatusVec(fillInVec, capacity, *status);
}