/*
*******************************************************************************
*
-* Copyright (C) 2005-2006, International Business Machines
+* Copyright (C) 2005-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
#include "cstring.h"
#include "uassert.h"
+U_NAMESPACE_USE
#define I32_FLAG(bitIndex) ((int32_t)1<<(bitIndex))
-U_DRAFT UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
utext_moveIndex32(UText *ut, int32_t delta) {
UChar32 c;
if (delta > 0) {
}
-U_DRAFT int64_t U_EXPORT2
+U_CAPI int64_t U_EXPORT2
utext_nativeLength(UText *ut) {
return ut->pFuncs->nativeLength(ut);
}
-U_DRAFT UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
utext_isLengthExpensive(const UText *ut) {
UBool r = (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_LENGTH_IS_EXPENSIVE)) != 0;
return r;
}
-U_DRAFT int64_t U_EXPORT2
+U_CAPI int64_t U_EXPORT2
utext_getNativeIndex(const UText *ut) {
if(ut->chunkOffset <= ut->nativeIndexingLimit) {
return ut->chunkNativeStart+ut->chunkOffset;
}
-U_DRAFT void U_EXPORT2
+U_CAPI void U_EXPORT2
utext_setNativeIndex(UText *ut, int64_t index) {
if(index<ut->chunkNativeStart || index>=ut->chunkNativeLimit) {
// The desired position is outside of the current chunk.
-U_DRAFT int64_t U_EXPORT2
+U_CAPI int64_t U_EXPORT2
utext_getPreviousNativeIndex(UText *ut) {
//
// Fast-path the common case.
// UText iteration position is always on a code point boundary,
// never on the trail half of a surrogate pair.
//
-U_DRAFT UChar32 U_EXPORT2
+U_CAPI UChar32 U_EXPORT2
utext_current32(UText *ut) {
UChar32 c;
if (ut->chunkOffset==ut->chunkLength) {
}
-U_DRAFT UChar32 U_EXPORT2
+U_CAPI UChar32 U_EXPORT2
utext_char32At(UText *ut, int64_t nativeIndex) {
UChar32 c = U_SENTINEL;
}
-U_DRAFT UChar32 U_EXPORT2
+U_CAPI UChar32 U_EXPORT2
utext_next32(UText *ut) {
UChar32 c;
}
-U_DRAFT UChar32 U_EXPORT2
+U_CAPI UChar32 U_EXPORT2
utext_previous32(UText *ut) {
UChar32 c;
-U_DRAFT UChar32 U_EXPORT2
+U_CAPI UChar32 U_EXPORT2
utext_next32From(UText *ut, int64_t index) {
UChar32 c = U_SENTINEL;
}
-U_DRAFT UChar32 U_EXPORT2
+U_CAPI UChar32 U_EXPORT2
utext_previous32From(UText *ut, int64_t index) {
//
// Return the character preceding the specified index.
}
-U_DRAFT int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
utext_extract(UText *ut,
int64_t start, int64_t limit,
UChar *dest, int32_t destCapacity,
-U_DRAFT UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
utext_equals(const UText *a, const UText *b) {
if (a==NULL || b==NULL ||
a->magic != UTEXT_MAGIC ||
return TRUE;
}
-U_DRAFT UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
utext_isWritable(const UText *ut)
{
UBool b = (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_WRITABLE)) != 0;
}
-U_DRAFT void U_EXPORT2
+U_CAPI void U_EXPORT2
utext_freeze(UText *ut) {
// Zero out the WRITABLE flag.
ut->providerProperties &= ~(I32_FLAG(UTEXT_PROVIDER_WRITABLE));
}
-U_DRAFT UBool U_EXPORT2
+U_CAPI UBool U_EXPORT2
utext_hasMetaData(const UText *ut)
{
UBool b = (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_HAS_META_DATA)) != 0;
-U_DRAFT int32_t U_EXPORT2
+U_CAPI int32_t U_EXPORT2
utext_replace(UText *ut,
int64_t nativeStart, int64_t nativeLimit,
const UChar *replacementText, int32_t replacementLength,
return i;
}
-U_DRAFT void U_EXPORT2
+U_CAPI void U_EXPORT2
utext_copy(UText *ut,
int64_t nativeStart, int64_t nativeLimit,
int64_t destIndex,
-U_DRAFT UText * U_EXPORT2
+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);
static const UText emptyText = UTEXT_INITIALIZER;
-U_DRAFT UText * U_EXPORT2
+U_CAPI UText * U_EXPORT2
utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
if (U_FAILURE(*status)) {
return ut;
ut = (UText *)uprv_malloc(spaceRequired);
if (ut == NULL) {
*status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
} else {
*ut = emptyText;
ut->flags |= UTEXT_HEAP_ALLOCATED;
if (spaceRequired>0) {
ut->extraSize = extraSpace;
ut->pExtra = &((ExtendedUText *)ut)->extension;
- uprv_memset(ut->pExtra, 0, extraSpace); // Purify whines about copying untouched extra [buffer]
- // space when cloning, so init it now.
}
}
} else {
} else {
ut->extraSize = extraSpace;
ut->flags |= UTEXT_EXTRA_HEAP_ALLOCATED;
- uprv_memset(ut->pExtra, 0, extraSpace);
}
}
}
ut->privB = 0;
ut->privC = 0;
ut->privP = NULL;
+ if (ut->pExtra!=NULL && ut->extraSize>0)
+ uprv_memset(ut->pExtra, 0, ut->extraSize);
+
}
return ut;
}
-U_DRAFT UText * U_EXPORT2
+U_CAPI UText * U_EXPORT2
utext_close(UText *ut) {
if (ut==NULL ||
ut->magic != UTEXT_MAGIC ||
adjustPointer(dest, &dest->p, src);
adjustPointer(dest, &dest->q, src);
adjustPointer(dest, &dest->r, src);
+ adjustPointer(dest, (const void **)&dest->chunkContents, src);
return dest;
}
U_CDECL_END
-static struct UTextFuncs utf8Funcs =
+static const struct UTextFuncs utf8Funcs =
{
sizeof(UTextFuncs),
0, 0, 0, // Reserved alignment padding
};
-U_DRAFT UText * U_EXPORT2
+U_CAPI UText * U_EXPORT2
utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status) {
if(U_FAILURE(*status)) {
return NULL;
repTextAccess(ut, nativeIterIndex, TRUE);
}
-static struct UTextFuncs repFuncs =
+static const struct UTextFuncs repFuncs =
{
sizeof(UTextFuncs),
0, 0, 0, // Reserved alignment padding
};
-U_DRAFT UText * U_EXPORT2
+U_CAPI UText * U_EXPORT2
utext_openReplaceable(UText *ut, Replaceable *rep, UErrorCode *status)
{
if(U_FAILURE(*status)) {
}
-static struct UTextFuncs unistrFuncs =
+static const struct UTextFuncs unistrFuncs =
{
sizeof(UTextFuncs),
0, 0, 0, // Reserved alignment padding
U_CDECL_END
-U_DRAFT UText * U_EXPORT2
+U_CAPI UText * U_EXPORT2
utext_openUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status) {
// TODO: use openConstUnicodeString, then add in the differences.
//
-U_DRAFT UText * U_EXPORT2
+U_CAPI UText * U_EXPORT2
utext_openConstUnicodeString(UText *ut, const UnicodeString *s, UErrorCode *status) {
ut = utext_setup(ut, 0, status);
// note: use the standard (writable) function table for UnicodeString.
if (U16_IS_LEAD(str[chunkLimit-1])) {
--chunkLimit;
}
+ // Null-terminated chunk with end still unknown.
+ // Update the chunk length to reflect what has been scanned thus far.
+ // That the full length is still unknown is (still) flagged by
+ // ut->a being < 0.
ut->chunkNativeLimit = chunkLimit;
+ ut->nativeIndexingLimit = chunkLimit;
+ ut->chunkLength = chunkLimit;
}
}
return di;
}
-static struct UTextFuncs ucstrFuncs =
+static const struct UTextFuncs ucstrFuncs =
{
sizeof(UTextFuncs),
0, 0, 0, // Reserved alignment padding
U_CDECL_END
-U_DRAFT UText * U_EXPORT2
+U_CAPI UText * U_EXPORT2
utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status) {
if (U_FAILURE(*status)) {
return NULL;
return desti;
}
-static struct UTextFuncs charIterFuncs =
+static const struct UTextFuncs charIterFuncs =
{
sizeof(UTextFuncs),
0, 0, 0, // Reserved alignment padding
U_CDECL_END
-U_DRAFT UText * U_EXPORT2
+U_CAPI UText * U_EXPORT2
utext_openCharacterIterator(UText *ut, CharacterIterator *ci, UErrorCode *status) {
if (U_FAILURE(*status)) {
return NULL;