summaryrefslogtreecommitdiffstats
path: root/thirdparty/icu4c/common/utext.cpp
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2023-05-23 03:05:01 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2023-05-23 03:26:16 +0300
commitb64df2bf74eddbf28e2e484d05c46a5ad0d7ee14 (patch)
tree92094a0540179f5722b1fe10499ef45155928fcb /thirdparty/icu4c/common/utext.cpp
parentd5c1b9f883adbb54900c145eafcaa789d0fd563c (diff)
downloadredot-engine-b64df2bf74eddbf28e2e484d05c46a5ad0d7ee14.tar.gz
Update HarfBuzz, ICU and FreeType
HarfBuzz: Update to version 7.3.0 ICU4C: Update to version 73.1 FreeType: Update to version 2.13.0
Diffstat (limited to 'thirdparty/icu4c/common/utext.cpp')
-rw-r--r--thirdparty/icu4c/common/utext.cpp281
1 files changed, 142 insertions, 139 deletions
diff --git a/thirdparty/icu4c/common/utext.cpp b/thirdparty/icu4c/common/utext.cpp
index 548e6a60f3..eb0a6984bd 100644
--- a/thirdparty/icu4c/common/utext.cpp
+++ b/thirdparty/icu4c/common/utext.cpp
@@ -124,13 +124,13 @@ utext_setNativeIndex(UText *ut, int64_t index) {
// The convention is that the index must always be on a code point boundary.
// Adjust the index position if it is in the middle of a surrogate pair.
if (ut->chunkOffset<ut->chunkLength) {
- UChar c= ut->chunkContents[ut->chunkOffset];
+ char16_t c= ut->chunkContents[ut->chunkOffset];
if (U16_IS_TRAIL(c)) {
if (ut->chunkOffset==0) {
ut->pFuncs->access(ut, ut->chunkNativeStart, false);
}
if (ut->chunkOffset>0) {
- UChar lead = ut->chunkContents[ut->chunkOffset-1];
+ char16_t lead = ut->chunkContents[ut->chunkOffset-1];
if (U16_IS_LEAD(lead)) {
ut->chunkOffset--;
}
@@ -151,7 +151,7 @@ utext_getPreviousNativeIndex(UText *ut) {
int32_t i = ut->chunkOffset - 1;
int64_t result;
if (i >= 0) {
- UChar c = ut->chunkContents[i];
+ char16_t c = ut->chunkContents[i];
if (U16_IS_TRAIL(c) == false) {
if (i <= ut->nativeIndexingLimit) {
result = ut->chunkNativeStart + i;
@@ -218,13 +218,16 @@ utext_current32(UText *ut) {
// leading surrogate. The attempt to access the trail will fail, but
// the original position before the unpaired lead still needs to be restored.
int64_t nativePosition = ut->chunkNativeLimit;
- int32_t originalOffset = ut->chunkOffset;
if (ut->pFuncs->access(ut, nativePosition, true)) {
trail = ut->chunkContents[ut->chunkOffset];
}
UBool r = ut->pFuncs->access(ut, nativePosition, false); // reverse iteration flag loads preceding chunk
- U_ASSERT(r==true);
- ut->chunkOffset = originalOffset;
+ U_ASSERT(r);
+ // Here we need to restore chunkOffset since the access functions were called with
+ // chunkNativeLimit but that is not where we were (we were 1 code unit before the
+ // limit). Restoring was originally added in ICU-4669 but did not support access
+ // functions that changed the chunk size, the following does.
+ ut->chunkOffset = ut->chunkLength - 1;
if(!r) {
return U_SENTINEL;
}
@@ -425,7 +428,7 @@ utext_previous32From(UText *ut, int64_t index) {
U_CAPI int32_t U_EXPORT2
utext_extract(UText *ut,
int64_t start, int64_t limit,
- UChar *dest, int32_t destCapacity,
+ char16_t *dest, int32_t destCapacity,
UErrorCode *status) {
return ut->pFuncs->extract(ut, start, limit, dest, destCapacity, status);
}
@@ -434,7 +437,7 @@ utext_extract(UText *ut,
U_CAPI UBool U_EXPORT2
utext_equals(const UText *a, const UText *b) {
- if (a==NULL || b==NULL ||
+ if (a==nullptr || b==nullptr ||
a->magic != UTEXT_MAGIC ||
b->magic != UTEXT_MAGIC) {
// Null or invalid arguments don't compare equal to anything.
@@ -485,7 +488,7 @@ utext_hasMetaData(const UText *ut)
U_CAPI int32_t U_EXPORT2
utext_replace(UText *ut,
int64_t nativeStart, int64_t nativeLimit,
- const UChar *replacementText, int32_t replacementLength,
+ const char16_t *replacementText, int32_t replacementLength,
UErrorCode *status)
{
if (U_FAILURE(*status)) {
@@ -527,7 +530,7 @@ utext_clone(UText *dest, const UText *src, UBool deep, UBool readOnly, UErrorCod
if (U_FAILURE(*status)) {
return result;
}
- if (result == NULL) {
+ if (result == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
return result;
}
@@ -580,16 +583,16 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
return ut;
}
- if (ut == NULL) {
+ if (ut == nullptr) {
// We need to heap-allocate storage for the new UText
int32_t spaceRequired = sizeof(UText);
if (extraSpace > 0) {
spaceRequired = sizeof(ExtendedUText) + extraSpace - sizeof(std::max_align_t);
}
ut = (UText *)uprv_malloc(spaceRequired);
- if (ut == NULL) {
+ if (ut == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
+ return nullptr;
} else {
*ut = emptyText;
ut->flags |= UTEXT_HEAP_ALLOCATED;
@@ -607,7 +610,7 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
}
// If the ut is already open and there's a provider supplied close
// function, call it.
- if ((ut->flags & UTEXT_OPEN) && ut->pFuncs->close != NULL) {
+ if ((ut->flags & UTEXT_OPEN) && ut->pFuncs->close != nullptr) {
ut->pFuncs->close(ut);
}
ut->flags &= ~UTEXT_OPEN;
@@ -622,7 +625,7 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
ut->extraSize = 0;
}
ut->pExtra = uprv_malloc(extraSpace);
- if (ut->pExtra == NULL) {
+ if (ut->pExtra == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
} else {
ut->extraSize = extraSpace;
@@ -635,11 +638,11 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
// Initialize all remaining fields of the UText.
//
- ut->context = NULL;
- ut->chunkContents = NULL;
- ut->p = NULL;
- ut->q = NULL;
- ut->r = NULL;
+ ut->context = nullptr;
+ ut->chunkContents = nullptr;
+ ut->p = nullptr;
+ ut->q = nullptr;
+ ut->r = nullptr;
ut->a = 0;
ut->b = 0;
ut->c = 0;
@@ -652,8 +655,8 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
ut->privA = 0;
ut->privB = 0;
ut->privC = 0;
- ut->privP = NULL;
- if (ut->pExtra!=NULL && ut->extraSize>0)
+ ut->privP = nullptr;
+ if (ut->pExtra!=nullptr && ut->extraSize>0)
uprv_memset(ut->pExtra, 0, ut->extraSize);
}
@@ -663,7 +666,7 @@ utext_setup(UText *ut, int32_t extraSpace, UErrorCode *status) {
U_CAPI UText * U_EXPORT2
utext_close(UText *ut) {
- if (ut==NULL ||
+ if (ut==nullptr ||
ut->magic != UTEXT_MAGIC ||
(ut->flags & UTEXT_OPEN) == 0)
{
@@ -674,7 +677,7 @@ utext_close(UText *ut) {
// If the provider gave us a close function, call it now.
// This will clean up anything allocated specifically by the provider.
- if (ut->pFuncs->close != NULL) {
+ if (ut->pFuncs->close != nullptr) {
ut->pFuncs->close(ut);
}
ut->flags &= ~UTEXT_OPEN;
@@ -683,7 +686,7 @@ utext_close(UText *ut) {
// delete it.
if (ut->flags & UTEXT_EXTRA_HEAP_ALLOCATED) {
uprv_free(ut->pExtra);
- ut->pExtra = NULL;
+ ut->pExtra = nullptr;
ut->flags &= ~UTEXT_EXTRA_HEAP_ALLOCATED;
ut->extraSize = 0;
}
@@ -691,7 +694,7 @@ utext_close(UText *ut) {
// Zero out function table of the closed UText. This is a defensive move,
// intended to cause applications that inadvertently use a closed
// utext to crash with null pointer errors.
- ut->pFuncs = NULL;
+ ut->pFuncs = nullptr;
if (ut->flags & UTEXT_HEAP_ALLOCATED) {
// This UText was allocated by UText setup. We need to free it.
@@ -699,7 +702,7 @@ utext_close(UText *ut) {
// tries to reopen another UText using the deleted storage.
ut->magic = 0;
uprv_free(ut);
- ut = NULL;
+ ut = nullptr;
}
return ut;
}
@@ -772,7 +775,7 @@ static void adjustPointer(UText *dest, const void **destPtr, const UText *src) {
static UText * U_CALLCONV
shallowTextClone(UText * dest, const UText * src, UErrorCode * status) {
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
int32_t srcExtraSize = src->extraSize;
@@ -849,8 +852,8 @@ U_CDECL_END
//------------------------------------------------------------------------------
// Chunk size.
-// Must be less than 85 (256/3), because of byte mapping from UChar indexes to native indexes.
-// Worst case is three native bytes to one UChar. (Supplemenaries are 4 native bytes
+// Must be less than 85 (256/3), because of byte mapping from char16_t indexes to native indexes.
+// Worst case is three native bytes to one char16_t. (Supplemenaries are 4 native bytes
// to two UChars.)
// The longest illegal byte sequence treated as a single error (and converted to U+FFFD)
// is a three-byte sequence (truncated four-byte sequence).
@@ -859,7 +862,7 @@ enum { UTF8_TEXT_CHUNK_SIZE=32 };
//
// UTF8Buf Two of these structs will be set up in the UText's extra allocated space.
-// Each contains the UChar chunk buffer, the to and from native maps, and
+// Each contains the char16_t chunk buffer, the to and from native maps, and
// header info.
//
// because backwards iteration fills the buffers starting at the end and
@@ -872,7 +875,7 @@ enum { UTF8_TEXT_CHUNK_SIZE=32 };
//
struct UTF8Buf {
- int32_t bufNativeStart; // Native index of first char in UChar buf
+ int32_t bufNativeStart; // Native index of first char in char16_t buf
int32_t bufNativeLimit; // Native index following last char in buf.
int32_t bufStartIdx; // First filled position in buf.
int32_t bufLimitIdx; // Limit of filled range in buf.
@@ -882,13 +885,13 @@ struct UTF8Buf {
// Set to bufNativeStart when filling forwards.
// Set to computed value when filling backwards.
- UChar buf[UTF8_TEXT_CHUNK_SIZE+4]; // The UChar buffer. Requires one extra position beyond the
+ char16_t buf[UTF8_TEXT_CHUNK_SIZE+4]; // The char16_t buffer. Requires one extra position beyond the
// the chunk size, to allow for surrogate at the end.
// Length must be identical to mapToNative array, below,
// because of the way indexing works when the array is
// filled backwards during a reverse iteration. Thus,
// the additional extra size.
- uint8_t mapToNative[UTF8_TEXT_CHUNK_SIZE+4]; // map UChar index in buf to
+ uint8_t mapToNative[UTF8_TEXT_CHUNK_SIZE+4]; // map char16_t index in buf to
// native offset from bufNativeStart.
// Requires two extra slots,
// one for a supplementary starting in the last normal position,
@@ -941,7 +944,7 @@ utf8TextAccess(UText *ut, int64_t index, UBool forward) {
// return;
//
const uint8_t *s8=(const uint8_t *)ut->context;
- UTF8Buf *u8b = NULL;
+ UTF8Buf *u8b = nullptr;
int32_t length = ut->b; // Length of original utf-8
int32_t ix= (int32_t)index; // Requested index, trimmed to 32 bits.
int32_t mapIndex = 0;
@@ -1209,7 +1212,7 @@ fillForward:
nulTerminated = true;
}
- UChar *buf = u8b_swap->buf;
+ char16_t *buf = u8b_swap->buf;
uint8_t *mapToNative = u8b_swap->mapToNative;
uint8_t *mapToUChars = u8b_swap->mapToUChars;
int32_t destIx = 0;
@@ -1223,7 +1226,7 @@ fillForward:
if (c>0 && c<0x80) {
// Special case ASCII range for speed.
// zero is excluded to simplify bounds checking.
- buf[destIx] = (UChar)c;
+ buf[destIx] = (char16_t)c;
mapToNative[destIx] = (uint8_t)(srcIx - ix);
mapToUChars[srcIx-ix] = (uint8_t)destIx;
srcIx++;
@@ -1317,7 +1320,7 @@ fillReverse:
ut->q = ut->p;
ut->p = u8b_swap;
- UChar *buf = u8b_swap->buf;
+ char16_t *buf = u8b_swap->buf;
uint8_t *mapToNative = u8b_swap->mapToNative;
uint8_t *mapToUChars = u8b_swap->mapToUChars;
int32_t toUCharsMapStart = ix - sizeof(UTF8Buf::mapToUChars) + 1;
@@ -1349,7 +1352,7 @@ fillReverse:
c = s8[srcIx];
if (c<0x80) {
// Special case ASCII range for speed.
- buf[destIx] = (UChar)c;
+ buf[destIx] = (char16_t)c;
U_ASSERT(toUCharsMapStart <= srcIx);
mapToUChars[srcIx - toUCharsMapStart] = (uint8_t)destIx;
mapToNative[destIx] = (uint8_t)(srcIx - toUCharsMapStart);
@@ -1367,7 +1370,7 @@ fillReverse:
// Store the character in UTF-16 buffer.
if (c<0x10000) {
- buf[destIx] = (UChar)c;
+ buf[destIx] = (char16_t)c;
mapToNative[destIx] = (uint8_t)(srcIx - toUCharsMapStart);
} else {
buf[destIx] = U16_TRAIL(c);
@@ -1414,8 +1417,8 @@ fillReverse:
// Inserts a Replacement Char rather than failing on invalid UTF-8
// Removes unnecessary features.
//
-static UChar*
-utext_strFromUTF8(UChar *dest,
+static char16_t*
+utext_strFromUTF8(char16_t *dest,
int32_t destCapacity,
int32_t *pDestLength,
const char* src,
@@ -1424,8 +1427,8 @@ utext_strFromUTF8(UChar *dest,
)
{
- UChar *pDest = dest;
- UChar *pDestLimit = (dest!=NULL)?(dest+destCapacity):NULL;
+ char16_t *pDest = dest;
+ char16_t *pDestLimit = (dest!=nullptr)?(dest+destCapacity):nullptr;
UChar32 ch=0;
int32_t index = 0;
int32_t reqLength = 0;
@@ -1435,11 +1438,11 @@ utext_strFromUTF8(UChar *dest,
while((index < srcLength)&&(pDest<pDestLimit)){
ch = pSrc[index++];
if(ch <=0x7f){
- *pDest++=(UChar)ch;
+ *pDest++=(char16_t)ch;
}else{
ch=utf8_nextCharSafeBody(pSrc, &index, srcLength, ch, -3);
if(U_IS_BMP(ch)){
- *(pDest++)=(UChar)ch;
+ *(pDest++)=(char16_t)ch;
}else{
*(pDest++)=U16_LEAD(ch);
if(pDest<pDestLimit){
@@ -1479,12 +1482,12 @@ utext_strFromUTF8(UChar *dest,
static int32_t U_CALLCONV
utf8TextExtract(UText *ut,
int64_t start, int64_t limit,
- UChar *dest, int32_t destCapacity,
+ char16_t *dest, int32_t destCapacity,
UErrorCode *pErrorCode) {
if(U_FAILURE(*pErrorCode)) {
return 0;
}
- if(destCapacity<0 || (dest==NULL && destCapacity>0)) {
+ if(destCapacity<0 || (dest==nullptr && destCapacity>0)) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
@@ -1579,7 +1582,7 @@ utf8TextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status)
if (deep && U_SUCCESS(*status)) {
int32_t len = (int32_t)utext_nativeLength((UText *)src);
char *copyStr = (char *)uprv_malloc(len+1);
- if (copyStr == NULL) {
+ if (copyStr == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
} else {
uprv_memcpy(copyStr, src->context, len+1);
@@ -1599,7 +1602,7 @@ utf8TextClose(UText *ut) {
if (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_OWNS_TEXT)) {
char *s = (char *)ut->context;
uprv_free(s);
- ut->context = NULL;
+ ut->context = nullptr;
}
}
@@ -1614,14 +1617,14 @@ static const struct UTextFuncs utf8Funcs =
utf8TextLength,
utf8TextAccess,
utf8TextExtract,
- NULL, /* replace*/
- NULL, /* copy */
+ nullptr, /* replace*/
+ nullptr, /* copy */
utf8TextMapOffsetToNative,
utf8TextMapIndexToUTF16,
utf8TextClose,
- NULL, // spare 1
- NULL, // spare 2
- NULL // spare 3
+ nullptr, // spare 1
+ nullptr, // spare 2
+ nullptr // spare 3
};
@@ -1630,15 +1633,15 @@ static const char gEmptyString[] = {0};
U_CAPI UText * U_EXPORT2
utext_openUTF8(UText *ut, const char *s, int64_t length, UErrorCode *status) {
if(U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
- if(s==NULL && length==0) {
+ if(s==nullptr && length==0) {
s = gEmptyString;
}
- if(s==NULL || length<-1 || length>INT32_MAX) {
+ if(s==nullptr || length<-1 || length>INT32_MAX) {
*status=U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
ut = utext_setup(ut, sizeof(UTF8Buf) * 2, status);
@@ -1688,7 +1691,7 @@ struct ReplExtra {
* Chunk UChars.
* +1 to simplify filling with surrogate pair at the end.
*/
- UChar s[REP_TEXT_CHUNK_SIZE+1];
+ char16_t s[REP_TEXT_CHUNK_SIZE+1];
};
@@ -1701,7 +1704,7 @@ repTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status) {
// For deep clones, make a copy of the Replaceable.
// The copied Replaceable storage is owned by the newly created UText clone.
- // A non-NULL pointer in UText.p is the signal to the close() function to delete
+ // A non-nullptr pointer in UText.p is the signal to the close() function to delete
// it.
//
if (deep && U_SUCCESS(*status)) {
@@ -1724,7 +1727,7 @@ repTextClose(UText *ut) {
if (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_OWNS_TEXT)) {
Replaceable *rep = (Replaceable *)ut->context;
delete rep;
- ut->context = NULL;
+ ut->context = nullptr;
}
}
@@ -1751,7 +1754,7 @@ repTextAccess(UText *ut, int64_t index, UBool forward) {
* Compute start/limit boundaries around index, for a segment of text
* to be extracted.
* To allow for the possibility that our user gave an index to the trailing
- * half of a surrogate pair, we must request one extra preceding UChar when
+ * half of a surrogate pair, we must request one extra preceding char16_t when
* going in the forward direction. This will ensure that the buffer has the
* entire code point at the specified index.
*/
@@ -1799,7 +1802,7 @@ repTextAccess(UText *ut, int64_t index, UBool forward) {
// Figure out the bounds of the chunk to extract for reverse iteration.
// Need to worry about chunk not splitting surrogate pairs, and while still
// containing the data we need.
- // Fix by requesting a chunk that includes an extra UChar at the end.
+ // Fix by requesting a chunk that includes an extra char16_t at the end.
// If this turns out to be a lead surrogate, we can lop it off and still have
// the data we wanted.
ut->chunkNativeStart = index32 + 1 - REP_TEXT_CHUNK_SIZE;
@@ -1834,7 +1837,7 @@ repTextAccess(UText *ut, int64_t index, UBool forward) {
}
}
- // if the first UChar in the chunk could be the trailing half of a surrogate pair,
+ // if the first char16_t in the chunk could be the trailing half of a surrogate pair,
// trim it off.
if(ut->chunkNativeStart>0 && U16_IS_TRAIL(ex->s[0])) {
++(ut->chunkContents);
@@ -1857,7 +1860,7 @@ repTextAccess(UText *ut, int64_t index, UBool forward) {
static int32_t U_CALLCONV
repTextExtract(UText *ut,
int64_t start, int64_t limit,
- UChar *dest, int32_t destCapacity,
+ char16_t *dest, int32_t destCapacity,
UErrorCode *status) {
const Replaceable *rep=(const Replaceable *)ut->context;
int32_t length=rep->length();
@@ -1865,7 +1868,7 @@ repTextExtract(UText *ut,
if(U_FAILURE(*status)) {
return 0;
}
- if(destCapacity<0 || (dest==NULL && destCapacity>0)) {
+ if(destCapacity<0 || (dest==nullptr && destCapacity>0)) {
*status=U_ILLEGAL_ARGUMENT_ERROR;
}
if(start>limit) {
@@ -1900,7 +1903,7 @@ repTextExtract(UText *ut,
static int32_t U_CALLCONV
repTextReplace(UText *ut,
int64_t start, int64_t limit,
- const UChar *src, int32_t length,
+ const char16_t *src, int32_t length,
UErrorCode *status) {
Replaceable *rep=(Replaceable *)ut->context;
int32_t oldLength;
@@ -1908,7 +1911,7 @@ repTextReplace(UText *ut,
if(U_FAILURE(*status)) {
return 0;
}
- if(src==NULL && length!=0) {
+ if(src==nullptr && length!=0) {
*status=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
@@ -2025,12 +2028,12 @@ static const struct UTextFuncs repFuncs =
repTextExtract,
repTextReplace,
repTextCopy,
- NULL, // MapOffsetToNative,
- NULL, // MapIndexToUTF16,
+ nullptr, // MapOffsetToNative,
+ nullptr, // MapIndexToUTF16,
repTextClose,
- NULL, // spare 1
- NULL, // spare 2
- NULL // spare 3
+ nullptr, // spare 1
+ nullptr, // spare 2
+ nullptr // spare 3
};
@@ -2038,11 +2041,11 @@ U_CAPI UText * U_EXPORT2
utext_openReplaceable(UText *ut, Replaceable *rep, UErrorCode *status)
{
if(U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
- if(rep==NULL) {
+ if(rep==nullptr) {
*status=U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
ut = utext_setup(ut, sizeof(ReplExtra), status);
if(U_FAILURE(*status)) {
@@ -2077,7 +2080,7 @@ U_CDECL_END
// Use of UText data members:
// context pointer to UnicodeString
// p pointer to UnicodeString IF this UText owns the string
-// and it must be deleted on close(). NULL otherwise.
+// and it must be deleted on close(). nullptr otherwise.
//
//------------------------------------------------------------------------------
@@ -2091,7 +2094,7 @@ unistrTextClone(UText *dest, const UText *src, UBool deep, UErrorCode *status) {
// For deep clones, make a copy of the UnicodeSring.
// The copied UnicodeString storage is owned by the newly created UText clone.
- // A non-NULL pointer in UText.p is the signal to the close() function to delete
+ // A non-nullptr pointer in UText.p is the signal to the close() function to delete
// the UText.
//
if (deep && U_SUCCESS(*status)) {
@@ -2113,7 +2116,7 @@ unistrTextClose(UText *ut) {
if (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_OWNS_TEXT)) {
UnicodeString *str = (UnicodeString *)ut->context;
delete str;
- ut->context = NULL;
+ ut->context = nullptr;
}
}
@@ -2139,7 +2142,7 @@ unistrTextAccess(UText *ut, int64_t index, UBool forward) {
static int32_t U_CALLCONV
unistrTextExtract(UText *t,
int64_t start, int64_t limit,
- UChar *dest, int32_t destCapacity,
+ char16_t *dest, int32_t destCapacity,
UErrorCode *pErrorCode) {
const UnicodeString *us=(const UnicodeString *)t->context;
int32_t length=us->length();
@@ -2147,7 +2150,7 @@ unistrTextExtract(UText *t,
if(U_FAILURE(*pErrorCode)) {
return 0;
}
- if(destCapacity<0 || (dest==NULL && destCapacity>0)) {
+ if(destCapacity<0 || (dest==nullptr && destCapacity>0)) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
}
if(start<0 || start>limit) {
@@ -2159,7 +2162,7 @@ unistrTextExtract(UText *t,
int32_t limit32 = limit<length ? us->getChar32Start((int32_t)limit) : length;
length=limit32-start32;
- if (destCapacity>0 && dest!=NULL) {
+ if (destCapacity>0 && dest!=nullptr) {
int32_t trimmedLength = length;
if(trimmedLength>destCapacity) {
trimmedLength=destCapacity;
@@ -2176,7 +2179,7 @@ unistrTextExtract(UText *t,
static int32_t U_CALLCONV
unistrTextReplace(UText *ut,
int64_t start, int64_t limit,
- const UChar *src, int32_t length,
+ const char16_t *src, int32_t length,
UErrorCode *pErrorCode) {
UnicodeString *us=(UnicodeString *)ut->context;
int32_t oldLength;
@@ -2184,7 +2187,7 @@ unistrTextReplace(UText *ut,
if(U_FAILURE(*pErrorCode)) {
return 0;
}
- if(src==NULL && length!=0) {
+ if(src==nullptr && length!=0) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
}
if(start>limit) {
@@ -2279,12 +2282,12 @@ static const struct UTextFuncs unistrFuncs =
unistrTextExtract,
unistrTextReplace,
unistrTextCopy,
- NULL, // MapOffsetToNative,
- NULL, // MapIndexToUTF16,
+ nullptr, // MapOffsetToNative,
+ nullptr, // MapIndexToUTF16,
unistrTextClose,
- NULL, // spare 1
- NULL, // spare 2
- NULL // spare 3
+ nullptr, // spare 1
+ nullptr, // spare 2
+ nullptr // spare 3
};
@@ -2308,7 +2311,7 @@ utext_openConstUnicodeString(UText *ut, const UnicodeString *s, UErrorCode *stat
if (U_SUCCESS(*status) && s->isBogus()) {
// The UnicodeString is bogus, but we still need to detach the UText
// from whatever it was hooked to before, if anything.
- utext_openUChars(ut, NULL, 0, status);
+ utext_openUChars(ut, nullptr, 0, status);
*status = U_ILLEGAL_ARGUMENT_ERROR;
return ut;
}
@@ -2331,7 +2334,7 @@ utext_openConstUnicodeString(UText *ut, const UnicodeString *s, UErrorCode *stat
//------------------------------------------------------------------------------
//
-// UText implementation for const UChar * strings
+// UText implementation for const char16_t * strings
//
// Use of UText data members:
// context pointer to UnicodeString
@@ -2351,7 +2354,7 @@ ucstrTextClone(UText *dest, const UText * src, UBool deep, UErrorCode * status)
// For deep clones, make a copy of the string.
// The copied storage is owned by the newly created clone.
- // A non-NULL pointer in UText.p is the signal to the close() function to delete
+ // A non-nullptr pointer in UText.p is the signal to the close() function to delete
// it.
//
if (deep && U_SUCCESS(*status)) {
@@ -2359,9 +2362,9 @@ ucstrTextClone(UText *dest, const UText * src, UBool deep, UErrorCode * status)
int32_t len = (int32_t)utext_nativeLength(dest);
// The cloned string IS going to be NUL terminated, whether or not the original was.
- const UChar *srcStr = (const UChar *)src->context;
- UChar *copyStr = (UChar *)uprv_malloc((len+1) * sizeof(UChar));
- if (copyStr == NULL) {
+ const char16_t *srcStr = (const char16_t *)src->context;
+ char16_t *copyStr = (char16_t *)uprv_malloc((len+1) * sizeof(char16_t));
+ if (copyStr == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
} else {
int64_t i;
@@ -2383,9 +2386,9 @@ ucstrTextClose(UText *ut) {
// All that needs to be done here is delete the string if the UText
// owns it. This occurs if the UText was created by cloning.
if (ut->providerProperties & I32_FLAG(UTEXT_PROVIDER_OWNS_TEXT)) {
- UChar *s = (UChar *)ut->context;
+ char16_t *s = (char16_t *)ut->context;
uprv_free(s);
- ut->context = NULL;
+ ut->context = nullptr;
}
}
@@ -2397,7 +2400,7 @@ ucstrTextLength(UText *ut) {
// null terminated, we don't yet know the length. Scan for it.
// Access is not convenient for doing this
// because the current iteration position can't be changed.
- const UChar *str = (const UChar *)ut->context;
+ const char16_t *str = (const char16_t *)ut->context;
for (;;) {
if (str[ut->chunkNativeLimit] == 0) {
break;
@@ -2415,7 +2418,7 @@ ucstrTextLength(UText *ut) {
static UBool U_CALLCONV
ucstrTextAccess(UText *ut, int64_t index, UBool forward) {
- const UChar *str = (const UChar *)ut->context;
+ const char16_t *str = (const char16_t *)ut->context;
// pin the requested index to the bounds of the string,
// and set current iteration position.
@@ -2505,18 +2508,18 @@ breakout:
static int32_t U_CALLCONV
ucstrTextExtract(UText *ut,
int64_t start, int64_t limit,
- UChar *dest, int32_t destCapacity,
+ char16_t *dest, int32_t destCapacity,
UErrorCode *pErrorCode)
{
if(U_FAILURE(*pErrorCode)) {
return 0;
}
- if(destCapacity<0 || (dest==NULL && destCapacity>0) || start>limit) {
+ if(destCapacity<0 || (dest==nullptr && destCapacity>0) || start>limit) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
- //const UChar *s=(const UChar *)ut->context;
+ //const char16_t *s=(const char16_t *)ut->context;
int32_t si, di;
int32_t start32;
@@ -2526,7 +2529,7 @@ ucstrTextExtract(UText *ut,
// Pins 'start' to the length of the string, if it came in out-of-bounds.
// Snaps 'start' to the beginning of a code point.
ucstrTextAccess(ut, start, true);
- const UChar *s=ut->chunkContents;
+ const char16_t *s=ut->chunkContents;
start32 = ut->chunkOffset;
int32_t strLength=(int32_t)ut->a;
@@ -2596,31 +2599,31 @@ static const struct UTextFuncs ucstrFuncs =
ucstrTextLength,
ucstrTextAccess,
ucstrTextExtract,
- NULL, // Replace
- NULL, // Copy
- NULL, // MapOffsetToNative,
- NULL, // MapIndexToUTF16,
+ nullptr, // Replace
+ nullptr, // Copy
+ nullptr, // MapOffsetToNative,
+ nullptr, // MapIndexToUTF16,
ucstrTextClose,
- NULL, // spare 1
- NULL, // spare 2
- NULL, // spare 3
+ nullptr, // spare 1
+ nullptr, // spare 2
+ nullptr, // spare 3
};
U_CDECL_END
-static const UChar gEmptyUString[] = {0};
+static const char16_t gEmptyUString[] = {0};
U_CAPI UText * U_EXPORT2
-utext_openUChars(UText *ut, const UChar *s, int64_t length, UErrorCode *status) {
+utext_openUChars(UText *ut, const char16_t *s, int64_t length, UErrorCode *status) {
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
- if(s==NULL && length==0) {
+ if(s==nullptr && length==0) {
s = gEmptyUString;
}
- if (s==NULL || length < -1 || length>INT32_MAX) {
+ if (s==nullptr || length < -1 || length>INT32_MAX) {
*status = U_ILLEGAL_ARGUMENT_ERROR;
- return NULL;
+ return nullptr;
}
ut = utext_setup(ut, 0, status);
if (U_SUCCESS(*status)) {
@@ -2667,7 +2670,7 @@ charIterTextClose(UText *ut) {
// owns it. This occurs if the UText was created by cloning.
CharacterIterator *ci = (CharacterIterator *)ut->r;
delete ci;
- ut->r = NULL;
+ ut->r = nullptr;
}
static int64_t U_CALLCONV
@@ -2697,7 +2700,7 @@ charIterTextAccess(UText *ut, int64_t index, UBool forward) {
// Find the native index of the start of the buffer containing what we want.
neededIndex -= neededIndex % CIBufSize;
- UChar *buf = NULL;
+ char16_t *buf = nullptr;
UBool needChunkSetup = true;
int i;
if (ut->chunkNativeStart == neededIndex) {
@@ -2705,17 +2708,17 @@ charIterTextAccess(UText *ut, int64_t index, UBool forward) {
needChunkSetup = false;
} else if (ut->b == neededIndex) {
// The first buffer (buffer p) has what we need.
- buf = (UChar *)ut->p;
+ buf = (char16_t *)ut->p;
} else if (ut->c == neededIndex) {
// The second buffer (buffer q) has what we need.
- buf = (UChar *)ut->q;
+ buf = (char16_t *)ut->q;
} else {
// Neither buffer already has what we need.
// Load new data from the character iterator.
// Use the buf that is not the current buffer.
- buf = (UChar *)ut->p;
+ buf = (char16_t *)ut->p;
if (ut->p == ut->chunkContents) {
- buf = (UChar *)ut->q;
+ buf = (char16_t *)ut->q;
}
ci->setIndex(neededIndex);
for (i=0; i<CIBufSize; i++) {
@@ -2748,13 +2751,13 @@ charIterTextAccess(UText *ut, int64_t index, UBool forward) {
static UText * U_CALLCONV
charIterTextClone(UText *dest, const UText *src, UBool deep, UErrorCode * status) {
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
if (deep) {
// There is no CharacterIterator API for cloning the underlying text storage.
*status = U_UNSUPPORTED_ERROR;
- return NULL;
+ return nullptr;
} else {
CharacterIterator *srcCI =(CharacterIterator *)src->context;
srcCI = srcCI->clone();
@@ -2774,13 +2777,13 @@ charIterTextClone(UText *dest, const UText *src, UBool deep, UErrorCode * status
static int32_t U_CALLCONV
charIterTextExtract(UText *ut,
int64_t start, int64_t limit,
- UChar *dest, int32_t destCapacity,
+ char16_t *dest, int32_t destCapacity,
UErrorCode *status)
{
if(U_FAILURE(*status)) {
return 0;
}
- if(destCapacity<0 || (dest==NULL && destCapacity>0) || start>limit) {
+ if(destCapacity<0 || (dest==nullptr && destCapacity>0) || start>limit) {
*status=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
@@ -2823,14 +2826,14 @@ static const struct UTextFuncs charIterFuncs =
charIterTextLength,
charIterTextAccess,
charIterTextExtract,
- NULL, // Replace
- NULL, // Copy
- NULL, // MapOffsetToNative,
- NULL, // MapIndexToUTF16,
+ nullptr, // Replace
+ nullptr, // Copy
+ nullptr, // MapOffsetToNative,
+ nullptr, // MapIndexToUTF16,
charIterTextClose,
- NULL, // spare 1
- NULL, // spare 2
- NULL // spare 3
+ nullptr, // spare 1
+ nullptr, // spare 2
+ nullptr // spare 3
};
U_CDECL_END
@@ -2838,17 +2841,17 @@ U_CDECL_END
U_CAPI UText * U_EXPORT2
utext_openCharacterIterator(UText *ut, CharacterIterator *ci, UErrorCode *status) {
if (U_FAILURE(*status)) {
- return NULL;
+ return nullptr;
}
if (ci->startIndex() > 0) {
// No support for CharacterIterators that do not start indexing from zero.
*status = U_UNSUPPORTED_ERROR;
- return NULL;
+ return nullptr;
}
// Extra space in UText for 2 buffers of CIBufSize UChars each.
- int32_t extraSpace = 2 * CIBufSize * sizeof(UChar);
+ int32_t extraSpace = 2 * CIBufSize * sizeof(char16_t);
ut = utext_setup(ut, extraSpace, status);
if (U_SUCCESS(*status)) {
ut->pFuncs = &charIterFuncs;
@@ -2857,7 +2860,7 @@ utext_openCharacterIterator(UText *ut, CharacterIterator *ci, UErrorCode *status
ut->a = ci->endIndex(); // Length of text
ut->p = ut->pExtra; // First buffer
ut->b = -1; // Native index of first buffer contents
- ut->q = (UChar*)ut->pExtra+CIBufSize; // Second buffer
+ ut->q = (char16_t*)ut->pExtra+CIBufSize; // Second buffer
ut->c = -1; // Native index of second buffer contents
// Initialize current chunk contents to be empty.
@@ -2866,7 +2869,7 @@ utext_openCharacterIterator(UText *ut, CharacterIterator *ci, UErrorCode *status
// so that getNativeIndex() will correctly compute to zero
// if no call to Access() has ever been made. They can't be both
// zero without Access() thinking that the chunk is valid.
- ut->chunkContents = (UChar *)ut->p;
+ ut->chunkContents = (char16_t *)ut->p;
ut->chunkNativeStart = -1;
ut->chunkOffset = 1;
ut->chunkNativeLimit = 0;