feat: updated engine version to 4.4-rc1

This commit is contained in:
Sara 2025-02-23 14:38:14 +01:00
parent ee00efde1f
commit 21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions

View file

@ -25,7 +25,7 @@ Appendable::~Appendable() {}
UBool
Appendable::appendCodePoint(UChar32 c) {
if(c<=0xffff) {
return appendCodeUnit((char16_t)c);
return appendCodeUnit(static_cast<char16_t>(c));
} else {
return appendCodeUnit(U16_LEAD(c)) && appendCodeUnit(U16_TRAIL(c));
}

View file

@ -75,7 +75,7 @@ static void set32x64Bits(uint32_t table[64], int32_t start, int32_t limit) {
int32_t trail=start&0x3f; // Named for UTF-8 2-byte trail byte with lower 6 bits.
// Set one bit indicating an all-one block.
uint32_t bits=(uint32_t)1<<lead;
uint32_t bits = static_cast<uint32_t>(1) << lead;
if((start+1)==limit) { // Single-character shortcut.
table[trail]|=bits;
return;
@ -100,9 +100,9 @@ static void set32x64Bits(uint32_t table[64], int32_t start, int32_t limit) {
++lead;
}
if(lead<limitLead) {
bits=~(((unsigned)1<<lead)-1);
bits = ~((static_cast<unsigned>(1) << lead) - 1);
if(limitLead<0x20) {
bits&=((unsigned)1<<limitLead)-1;
bits &= (static_cast<unsigned>(1) << limitLead) - 1;
}
for(trail=0; trail<64; ++trail) {
table[trail]|=bits;
@ -111,7 +111,7 @@ static void set32x64Bits(uint32_t table[64], int32_t start, int32_t limit) {
// limit<=0x800. If limit==0x800 then limitLead=32 and limitTrail=0.
// In that case, bits=1<<limitLead is undefined but the bits value
// is not used because trail<limitTrail is already false.
bits=(uint32_t)1<<((limitLead == 0x20) ? (limitLead - 1) : limitLead);
bits = static_cast<uint32_t>(1) << ((limitLead == 0x20) ? (limitLead - 1) : limitLead);
for(trail=0; trail<limitTrail; ++trail) {
table[trail]|=bits;
}
@ -290,22 +290,22 @@ int32_t BMPSet::findCodePoint(UChar32 c, int32_t lo, int32_t hi) const {
UBool
BMPSet::contains(UChar32 c) const {
if((uint32_t)c<=0xff) {
return (UBool)latin1Contains[c];
} else if((uint32_t)c<=0x7ff) {
return (UBool)((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0);
} else if((uint32_t)c<0xd800 || (c>=0xe000 && c<=0xffff)) {
if (static_cast<uint32_t>(c) <= 0xff) {
return latin1Contains[c];
} else if (static_cast<uint32_t>(c) <= 0x7ff) {
return (table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0;
} else if (static_cast<uint32_t>(c) < 0xd800 || (c >= 0xe000 && c <= 0xffff)) {
int lead=c>>12;
uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
if(twoBits<=1) {
// All 64 code points with the same bits 15..6
// are either in the set or not.
return (UBool)twoBits;
return twoBits;
} else {
// Look up the code point in its 4k block of code points.
return containsSlow(c, list4kStarts[lead], list4kStarts[lead+1]);
}
} else if((uint32_t)c<=0x10ffff) {
} else if (static_cast<uint32_t>(c) <= 0x10ffff) {
// surrogate or supplementary code point
return containsSlow(c, list4kStarts[0xd], list4kStarts[0x11]);
} else {
@ -332,7 +332,7 @@ BMPSet::span(const char16_t *s, const char16_t *limit, USetSpanCondition spanCon
break;
}
} else if(c<=0x7ff) {
if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))==0) {
if ((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) == 0) {
break;
}
} else if(c<0xd800 || c>=0xe000) {
@ -372,7 +372,7 @@ BMPSet::span(const char16_t *s, const char16_t *limit, USetSpanCondition spanCon
break;
}
} else if(c<=0x7ff) {
if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0) {
if ((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0) {
break;
}
} else if(c<0xd800 || c>=0xe000) {
@ -421,7 +421,7 @@ BMPSet::spanBack(const char16_t *s, const char16_t *limit, USetSpanCondition spa
break;
}
} else if(c<=0x7ff) {
if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))==0) {
if ((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) == 0) {
break;
}
} else if(c<0xd800 || c>=0xe000) {
@ -464,7 +464,7 @@ BMPSet::spanBack(const char16_t *s, const char16_t *limit, USetSpanCondition spa
break;
}
} else if(c<=0x7ff) {
if((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0) {
if ((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0) {
break;
}
} else if(c<0xd800 || c>=0xe000) {
@ -527,7 +527,7 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
b=*s;
} while(U8_IS_SINGLE(b));
}
length=(int32_t)(limit-s);
length = static_cast<int32_t>(limit - s);
}
if(spanCondition!=USET_SPAN_NOT_CONTAINED) {
@ -547,7 +547,7 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
* the truncated sequence.
*/
b=*(limit-1);
if((int8_t)b<0) {
if (static_cast<int8_t>(b) < 0) {
// b>=0x80: lead or trail byte
if(b<0xc0) {
// single trail byte, check for preceding 3- or 4-byte lead byte
@ -602,15 +602,15 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
if(b>=0xe0) {
if(b<0xf0) {
if( /* handle U+0000..U+FFFF inline */
(t1=(uint8_t)(s[0]-0x80)) <= 0x3f &&
(t2=(uint8_t)(s[1]-0x80)) <= 0x3f
(t1 = static_cast<uint8_t>(s[0] - 0x80)) <= 0x3f &&
(t2 = static_cast<uint8_t>(s[1] - 0x80)) <= 0x3f
) {
b&=0xf;
uint32_t twoBits=(bmpBlockBits[t1]>>b)&0x10001;
if(twoBits<=1) {
// All 64 code points with this lead byte and middle trail byte
// are either in the set or not.
if(twoBits!=(uint32_t)spanCondition) {
if (twoBits != static_cast<uint32_t>(spanCondition)) {
return s-1;
}
} else {
@ -624,12 +624,12 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
continue;
}
} else if( /* handle U+10000..U+10FFFF inline */
(t1=(uint8_t)(s[0]-0x80)) <= 0x3f &&
(t2=(uint8_t)(s[1]-0x80)) <= 0x3f &&
(t3=(uint8_t)(s[2]-0x80)) <= 0x3f
(t1 = static_cast<uint8_t>(s[0] - 0x80)) <= 0x3f &&
(t2 = static_cast<uint8_t>(s[1] - 0x80)) <= 0x3f &&
(t3 = static_cast<uint8_t>(s[2] - 0x80)) <= 0x3f
) {
// Give an illegal sequence the same value as the result of contains(FFFD).
UChar32 c=((UChar32)(b-0xf0)<<18)|((UChar32)t1<<12)|(t2<<6)|t3;
UChar32 c = (static_cast<UChar32>(b - 0xf0) << 18) | (static_cast<UChar32>(t1) << 12) | (t2 << 6) | t3;
if( ( (0x10000<=c && c<=0x10ffff) ?
containsSlow(c, list4kStarts[0x10], list4kStarts[0x11]) :
containsFFFD
@ -643,9 +643,9 @@ BMPSet::spanUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanConditi
} else {
if( /* handle U+0000..U+07FF inline */
b>=0xc0 &&
(t1=(uint8_t)(*s-0x80)) <= 0x3f
(t1 = static_cast<uint8_t>(*s - 0x80)) <= 0x3f
) {
if((USetSpanCondition)((table7FF[t1]&((uint32_t)1<<(b&0x1f)))!=0) != spanCondition) {
if (static_cast<USetSpanCondition>((table7FF[t1] & (static_cast<uint32_t>(1) << (b & 0x1f))) != 0) != spanCondition) {
return s-1;
}
++s;
@ -711,7 +711,7 @@ BMPSet::spanBackUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCon
c=utf8_prevCharSafeBody(s, 0, &length, b, -3);
// c is a valid code point, not ASCII, not a surrogate
if(c<=0x7ff) {
if((USetSpanCondition)((table7FF[c&0x3f]&((uint32_t)1<<(c>>6)))!=0) != spanCondition) {
if (static_cast<USetSpanCondition>((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0) != spanCondition) {
return prev+1;
}
} else if(c<=0xffff) {
@ -720,7 +720,7 @@ BMPSet::spanBackUTF8(const uint8_t *s, int32_t length, USetSpanCondition spanCon
if(twoBits<=1) {
// All 64 code points with the same bits 15..6
// are either in the set or not.
if(twoBits!=(uint32_t)spanCondition) {
if (twoBits != static_cast<uint32_t>(spanCondition)) {
return prev+1;
}
} else {

View file

@ -156,7 +156,7 @@ private:
};
inline UBool BMPSet::containsSlow(UChar32 c, int32_t lo, int32_t hi) const {
return (UBool)(findCodePoint(c, lo, hi) & 1);
return findCodePoint(c, lo, hi) & 1;
}
U_NAMESPACE_END

View file

@ -86,7 +86,7 @@ UnhandledEngine::findBreaks( UText *text,
if (U_FAILURE(status)) return 0;
utext_setNativeIndex(text, startPos);
UChar32 c = utext_current32(text);
while((int32_t)utext_getNativeIndex(text) < endPos && fHandled->contains(c)) {
while (static_cast<int32_t>(utext_getNativeIndex(text)) < endPos && fHandled->contains(c)) {
utext_next32(text); // TODO: recast loop to work with post-increment operations.
c = utext_current32(text);
}
@ -146,7 +146,7 @@ ICULanguageBreakFactory::getEngineFor(UChar32 c, const char* locale) {
Mutex m(&gBreakEngineMutex);
int32_t i = fEngines->size();
while (--i >= 0) {
lbe = (const LanguageBreakEngine *)(fEngines->elementAt(i));
lbe = static_cast<const LanguageBreakEngine*>(fEngines->elementAt(i));
if (lbe != nullptr && lbe->handles(c, locale)) {
return lbe;
}
@ -259,7 +259,7 @@ ICULanguageBreakFactory::loadDictionaryMatcherFor(UScriptCode script) {
CharString ext;
const char16_t *extStart = u_memrchr(dictfname, 0x002e, dictnlength); // last dot
if (extStart != nullptr) {
int32_t len = (int32_t)(extStart - dictfname);
int32_t len = static_cast<int32_t>(extStart - dictfname);
ext.appendInvariantChars(UnicodeString(false, extStart + 1, dictnlength - len - 1), status);
dictnlength = len;
}
@ -269,18 +269,18 @@ ICULanguageBreakFactory::loadDictionaryMatcherFor(UScriptCode script) {
UDataMemory *file = udata_open(U_ICUDATA_BRKITR, ext.data(), dictnbuf.data(), &status);
if (U_SUCCESS(status)) {
// build trie
const uint8_t *data = (const uint8_t *)udata_getMemory(file);
const int32_t *indexes = (const int32_t *)data;
const uint8_t* data = static_cast<const uint8_t*>(udata_getMemory(file));
const int32_t* indexes = reinterpret_cast<const int32_t*>(data);
const int32_t offset = indexes[DictionaryData::IX_STRING_TRIE_OFFSET];
const int32_t trieType = indexes[DictionaryData::IX_TRIE_TYPE] & DictionaryData::TRIE_TYPE_MASK;
DictionaryMatcher *m = nullptr;
if (trieType == DictionaryData::TRIE_TYPE_BYTES) {
const int32_t transform = indexes[DictionaryData::IX_TRANSFORM];
const char *characters = (const char *)(data + offset);
const char* characters = reinterpret_cast<const char*>(data + offset);
m = new BytesDictionaryMatcher(characters, transform, file);
}
else if (trieType == DictionaryData::TRIE_TYPE_UCHARS) {
const char16_t *characters = (const char16_t *)(data + offset);
const char16_t* characters = reinterpret_cast<const char16_t*>(data + offset);
m = new UCharsDictionaryMatcher(characters, file);
}
if (m == nullptr) {
@ -337,12 +337,12 @@ int32_t BreakEngineWrapper::findBreaks(
// extends towards the start or end of the text, depending on 'reverse'.
utext_setNativeIndex(text, startPos);
int32_t start = (int32_t)utext_getNativeIndex(text);
int32_t start = static_cast<int32_t>(utext_getNativeIndex(text));
int32_t current;
int32_t rangeStart;
int32_t rangeEnd;
UChar32 c = utext_current32(text);
while((current = (int32_t)utext_getNativeIndex(text)) < endPos && delegate->handles(c)) {
while ((current = static_cast<int32_t>(utext_getNativeIndex(text))) < endPos && delegate->handles(c)) {
utext_next32(text); // TODO: recast loop for postincrement
c = utext_current32(text);
}

View file

@ -85,7 +85,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
// Get the actual string
brkfname = ures_getString(brkName, &size, &status);
U_ASSERT((size_t)size<sizeof(fnbuff));
if ((size_t)size>=sizeof(fnbuff)) {
if (static_cast<size_t>(size) >= sizeof(fnbuff)) {
size=0;
if (U_SUCCESS(status)) {
status = U_BUFFER_OVERFLOW_ERROR;
@ -99,7 +99,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, UErrorCode &st
char16_t* extStart=u_strchr(brkfname, 0x002e);
int len = 0;
if (extStart != nullptr){
len = (int)(extStart-brkfname);
len = static_cast<int>(extStart - brkfname);
u_UCharsToChars(extStart+1, ext, sizeof(ext)); // nul terminates the buff
u_UCharsToChars(brkfname, fnbuff, len);
}

View file

@ -64,7 +64,7 @@ ByteSinkUtil::appendChange(const uint8_t *s, const uint8_t *limit,
errorCode = U_INDEX_OUTOFBOUNDS_ERROR;
return false;
}
return appendChange((int32_t)(limit - s), s16, s16Length, sink, edits, errorCode);
return appendChange(static_cast<int32_t>(limit - s), s16, s16Length, sink, edits, errorCode);
}
void
@ -81,15 +81,15 @@ ByteSinkUtil::appendCodePoint(int32_t length, UChar32 c, ByteSink &sink, Edits *
namespace {
// See unicode/utf8.h U8_APPEND_UNSAFE().
inline uint8_t getTwoByteLead(UChar32 c) { return (uint8_t)((c >> 6) | 0xc0); }
inline uint8_t getTwoByteTrail(UChar32 c) { return (uint8_t)((c & 0x3f) | 0x80); }
inline uint8_t getTwoByteLead(UChar32 c) { return static_cast<uint8_t>((c >> 6) | 0xc0); }
inline uint8_t getTwoByteTrail(UChar32 c) { return static_cast<uint8_t>((c & 0x3f) | 0x80); }
} // namespace
void
ByteSinkUtil::appendTwoBytes(UChar32 c, ByteSink &sink) {
U_ASSERT(0x80 <= c && c <= 0x7ff); // 2-byte UTF-8
char s8[2] = { (char)getTwoByteLead(c), (char)getTwoByteTrail(c) };
char s8[2] = {static_cast<char>(getTwoByteLead(c)), static_cast<char>(getTwoByteTrail(c))};
sink.Append(s8, 2);
}
@ -114,7 +114,7 @@ ByteSinkUtil::appendUnchanged(const uint8_t *s, const uint8_t *limit,
errorCode = U_INDEX_OUTOFBOUNDS_ERROR;
return false;
}
int32_t length = (int32_t)(limit - s);
int32_t length = static_cast<int32_t>(limit - s);
if (length > 0) {
appendNonEmptyUnchanged(s, length, sink, options, edits);
}

View file

@ -73,7 +73,7 @@ public:
/** The few bytes at [src, nextSrc[ were mapped/changed to valid code point c. */
static inline void appendCodePoint(const uint8_t *src, const uint8_t *nextSrc, UChar32 c,
ByteSink &sink, Edits *edits = nullptr) {
appendCodePoint((int32_t)(nextSrc - src), c, sink, edits);
appendCodePoint(static_cast<int32_t>(nextSrc - src), c, sink, edits);
}
/** Append the two-byte character (U+0080..U+07FF). */

View file

@ -327,7 +327,7 @@ BytesTrie::findUniqueValueFromBranch(const uint8_t *pos, int32_t length,
++pos; // ignore a comparison byte
// handle its value
int32_t node=*pos++;
UBool isFinal=(UBool)(node&kValueIsFinal);
UBool isFinal = static_cast<UBool>(node & kValueIsFinal);
int32_t value=readValue(pos, node>>1);
pos=skipValue(pos, node);
if(isFinal) {
@ -366,7 +366,7 @@ BytesTrie::findUniqueValue(const uint8_t *pos, UBool haveUniqueValue, int32_t &u
// linear-match node
pos+=node-kMinLinearMatch+1; // Ignore the match bytes.
} else {
UBool isFinal=(UBool)(node&kValueIsFinal);
UBool isFinal = static_cast<UBool>(node & kValueIsFinal);
int32_t value=readValue(pos, node>>1);
if(haveUniqueValue) {
if(value!=uniqueValue) {
@ -434,7 +434,7 @@ BytesTrie::getNextBranchBytes(const uint8_t *pos, int32_t length, ByteSink &out)
void
BytesTrie::append(ByteSink &out, int c) {
char ch=(char)c;
char ch = static_cast<char>(c);
out.Append(&ch, 1);
}

View file

@ -43,10 +43,10 @@ public:
int32_t offset=stringOffset;
int32_t length;
if(offset>=0) {
length=(uint8_t)strings[offset++];
length = static_cast<uint8_t>(strings[offset++]);
} else {
offset=~offset;
length=((int32_t)(uint8_t)strings[offset]<<8)|(uint8_t)strings[offset+1];
length = (static_cast<int32_t>(static_cast<uint8_t>(strings[offset])) << 8) | static_cast<uint8_t>(strings[offset + 1]);
offset+=2;
}
return StringPiece(strings.data()+offset, length);
@ -54,10 +54,10 @@ public:
int32_t getStringLength(const CharString &strings) const {
int32_t offset=stringOffset;
if(offset>=0) {
return (uint8_t)strings[offset];
return static_cast<uint8_t>(strings[offset]);
} else {
offset=~offset;
return ((int32_t)(uint8_t)strings[offset]<<8)|(uint8_t)strings[offset+1];
return (static_cast<int32_t>(static_cast<uint8_t>(strings[offset])) << 8) | static_cast<uint8_t>(strings[offset + 1]);
}
}
@ -102,9 +102,9 @@ BytesTrieElement::setTo(StringPiece s, int32_t val,
int32_t offset=strings.length();
if(length>0xff) {
offset=~offset;
strings.append((char)(length>>8), errorCode);
strings.append(static_cast<char>(length >> 8), errorCode);
}
strings.append((char)length, errorCode);
strings.append(static_cast<char>(length), errorCode);
stringOffset=offset;
value=val;
strings.append(s, errorCode);
@ -229,7 +229,7 @@ BytesTrieBuilder::buildBytes(UStringTrieBuildOption buildOption, UErrorCode &err
errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
return;
}
uprv_sortArray(elements, elementsLength, (int32_t)sizeof(BytesTrieElement),
uprv_sortArray(elements, elementsLength, static_cast<int32_t>(sizeof(BytesTrieElement)),
compareElementStrings, strings,
false, // need not be a stable sort
&errorCode);
@ -284,7 +284,7 @@ BytesTrieBuilder::getElementStringLength(int32_t i) const {
char16_t
BytesTrieBuilder::getElementUnit(int32_t i, int32_t byteIndex) const {
return (uint8_t)elements[i].charAt(byteIndex, *strings);
return static_cast<uint8_t>(elements[i].charAt(byteIndex, *strings));
}
int32_t
@ -330,7 +330,7 @@ BytesTrieBuilder::skipElementsBySomeUnits(int32_t i, int32_t byteIndex, int32_t
int32_t
BytesTrieBuilder::indexOfElementWithNextUnit(int32_t i, int32_t byteIndex, char16_t byte) const {
char b=(char)byte;
char b = static_cast<char>(byte);
while(b==elements[i].charAt(byteIndex, *strings)) {
++i;
}
@ -404,7 +404,7 @@ BytesTrieBuilder::write(int32_t byte) {
int32_t newLength=bytesLength+1;
if(ensureCapacity(newLength)) {
bytesLength=newLength;
bytes[bytesCapacity-bytesLength]=(char)byte;
bytes[bytesCapacity - bytesLength] = static_cast<char>(byte);
}
return bytesLength;
}
@ -432,30 +432,30 @@ BytesTrieBuilder::writeValueAndFinal(int32_t i, UBool isFinal) {
char intBytes[5];
int32_t length=1;
if(i<0 || i>0xffffff) {
intBytes[0]=(char)BytesTrie::kFiveByteValueLead;
intBytes[1]=(char)((uint32_t)i>>24);
intBytes[2]=(char)((uint32_t)i>>16);
intBytes[3]=(char)((uint32_t)i>>8);
intBytes[4]=(char)i;
intBytes[0] = static_cast<char>(BytesTrie::kFiveByteValueLead);
intBytes[1] = static_cast<char>(static_cast<uint32_t>(i) >> 24);
intBytes[2] = static_cast<char>(static_cast<uint32_t>(i) >> 16);
intBytes[3] = static_cast<char>(static_cast<uint32_t>(i) >> 8);
intBytes[4] = static_cast<char>(i);
length=5;
// } else if(i<=BytesTrie::kMaxOneByteValue) {
// intBytes[0]=(char)(BytesTrie::kMinOneByteValueLead+i);
} else {
if(i<=BytesTrie::kMaxTwoByteValue) {
intBytes[0]=(char)(BytesTrie::kMinTwoByteValueLead+(i>>8));
intBytes[0] = static_cast<char>(BytesTrie::kMinTwoByteValueLead + (i >> 8));
} else {
if(i<=BytesTrie::kMaxThreeByteValue) {
intBytes[0]=(char)(BytesTrie::kMinThreeByteValueLead+(i>>16));
intBytes[0] = static_cast<char>(BytesTrie::kMinThreeByteValueLead + (i >> 16));
} else {
intBytes[0]=(char)BytesTrie::kFourByteValueLead;
intBytes[1]=(char)(i>>16);
intBytes[0] = static_cast<char>(BytesTrie::kFourByteValueLead);
intBytes[1] = static_cast<char>(i >> 16);
length=2;
}
intBytes[length++]=(char)(i>>8);
intBytes[length++] = static_cast<char>(i >> 8);
}
intBytes[length++]=(char)i;
intBytes[length++] = static_cast<char>(i);
}
intBytes[0]=(char)((intBytes[0]<<1)|isFinal);
intBytes[0] = static_cast<char>((intBytes[0] << 1) | isFinal);
return write(intBytes, length);
}
@ -484,28 +484,28 @@ int32_t
BytesTrieBuilder::internalEncodeDelta(int32_t i, char intBytes[]) {
U_ASSERT(i>=0);
if(i<=BytesTrie::kMaxOneByteDelta) {
intBytes[0]=(char)i;
intBytes[0] = static_cast<char>(i);
return 1;
}
int32_t length=1;
if(i<=BytesTrie::kMaxTwoByteDelta) {
intBytes[0]=(char)(BytesTrie::kMinTwoByteDeltaLead+(i>>8));
intBytes[0] = static_cast<char>(BytesTrie::kMinTwoByteDeltaLead + (i >> 8));
} else {
if(i<=BytesTrie::kMaxThreeByteDelta) {
intBytes[0]=(char)(BytesTrie::kMinThreeByteDeltaLead+(i>>16));
intBytes[0] = static_cast<char>(BytesTrie::kMinThreeByteDeltaLead + (i >> 16));
} else {
if(i<=0xffffff) {
intBytes[0]=(char)BytesTrie::kFourByteDeltaLead;
intBytes[0] = static_cast<char>(BytesTrie::kFourByteDeltaLead);
} else {
intBytes[0]=(char)BytesTrie::kFiveByteDeltaLead;
intBytes[1]=(char)(i>>24);
intBytes[0] = static_cast<char>(BytesTrie::kFiveByteDeltaLead);
intBytes[1] = static_cast<char>(i >> 24);
length=2;
}
intBytes[length++]=(char)(i>>16);
intBytes[length++] = static_cast<char>(i >> 16);
}
intBytes[length++]=(char)(i>>8);
intBytes[length++] = static_cast<char>(i >> 8);
}
intBytes[length++]=(char)i;
intBytes[length++] = static_cast<char>(i);
return length;
}

View file

@ -115,14 +115,14 @@ BytesTrie::Iterator::next(UErrorCode &errorCode) {
pos=bytes_+stack_->elementAti(stackSize-2);
stack_->setSize(stackSize-2);
str_->truncate(length&0xffff);
length=(int32_t)((uint32_t)length>>16);
length = static_cast<int32_t>(static_cast<uint32_t>(length) >> 16);
if(length>1) {
pos=branchNext(pos, length, errorCode);
if(pos==nullptr) {
return true; // Reached a final value.
}
} else {
str_->append((char)*pos++, errorCode);
str_->append(static_cast<char>(*pos++), errorCode);
}
}
if(remainingMatchLength_>=0) {
@ -134,7 +134,7 @@ BytesTrie::Iterator::next(UErrorCode &errorCode) {
int32_t node=*pos++;
if(node>=kMinValueLead) {
// Deliver value for the byte sequence so far.
UBool isFinal=(UBool)(node&kValueIsFinal);
UBool isFinal = static_cast<UBool>(node & kValueIsFinal);
value_=readValue(pos, node>>1);
if(isFinal || (maxLength_>0 && str_->length()==maxLength_)) {
pos_=nullptr;
@ -186,7 +186,7 @@ BytesTrie::Iterator::branchNext(const uint8_t *pos, int32_t length, UErrorCode &
while(length>kMaxBranchLinearSubNodeLength) {
++pos; // ignore the comparison byte
// Push state for the greater-or-equal edge.
stack_->addElement((int32_t)(skipDelta(pos)-bytes_), errorCode);
stack_->addElement(static_cast<int32_t>(skipDelta(pos) - bytes_), errorCode);
stack_->addElement(((length-(length>>1))<<16)|str_->length(), errorCode);
// Follow the less-than edge.
length>>=1;
@ -196,12 +196,12 @@ BytesTrie::Iterator::branchNext(const uint8_t *pos, int32_t length, UErrorCode &
// Read the first (key, value) pair.
uint8_t trieByte=*pos++;
int32_t node=*pos++;
UBool isFinal=(UBool)(node&kValueIsFinal);
UBool isFinal = static_cast<UBool>(node & kValueIsFinal);
int32_t value=readValue(pos, node>>1);
pos=skipValue(pos, node);
stack_->addElement((int32_t)(pos-bytes_), errorCode);
stack_->addElement(static_cast<int32_t>(pos - bytes_), errorCode);
stack_->addElement(((length-1)<<16)|str_->length(), errorCode);
str_->append((char)trieByte, errorCode);
str_->append(static_cast<char>(trieByte), errorCode);
if(isFinal) {
pos_=nullptr;
value_=value;

View file

@ -183,10 +183,10 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
// catch degenerate case
if (newSource.length() == 0) {
pieces = (UnicodeString **)uprv_malloc(sizeof(UnicodeString *));
pieces_lengths = (int32_t*)uprv_malloc(1 * sizeof(int32_t));
pieces = static_cast<UnicodeString**>(uprv_malloc(sizeof(UnicodeString*)));
pieces_lengths = static_cast<int32_t*>(uprv_malloc(1 * sizeof(int32_t)));
pieces_length = 1;
current = (int32_t*)uprv_malloc(1 * sizeof(int32_t));
current = static_cast<int32_t*>(uprv_malloc(1 * sizeof(int32_t)));
current_length = 1;
if (pieces == nullptr || pieces_lengths == nullptr || current == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
@ -229,10 +229,10 @@ void CanonicalIterator::setSource(const UnicodeString &newSource, UErrorCode &st
// allocate the arrays, and find the strings that are CE to each segment
pieces = (UnicodeString **)uprv_malloc(list_length * sizeof(UnicodeString *));
pieces = static_cast<UnicodeString**>(uprv_malloc(list_length * sizeof(UnicodeString*)));
pieces_length = list_length;
pieces_lengths = (int32_t*)uprv_malloc(list_length * sizeof(int32_t));
current = (int32_t*)uprv_malloc(list_length * sizeof(int32_t));
pieces_lengths = static_cast<int32_t*>(uprv_malloc(list_length * sizeof(int32_t)));
current = static_cast<int32_t*>(uprv_malloc(list_length * sizeof(int32_t)));
current_length = list_length;
if (pieces == nullptr || pieces_lengths == nullptr || current == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
@ -330,7 +330,7 @@ void U_EXPORT2 CanonicalIterator::permute(UnicodeString &source, UBool skipZeros
// prefix this character to all of them
ne = subpermute.nextElement(el);
while (ne != nullptr) {
UnicodeString *permRes = (UnicodeString *)(ne->value.pointer);
UnicodeString* permRes = static_cast<UnicodeString*>(ne->value.pointer);
UnicodeString *chStr = new UnicodeString(cp);
//test for nullptr
if (chStr == nullptr) {
@ -363,6 +363,9 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
char16_t USeg[256];
int32_t segLen = segment.extract(USeg, 256, status);
getEquivalents2(&basic, USeg, segLen, status);
if (U_FAILURE(status)) {
return nullptr;
}
// now get all the permutations
// add only the ones that are canonically equivalent
@ -375,7 +378,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
//while (it.hasNext())
while (ne != nullptr) {
//String item = (String) it.next();
UnicodeString item = *((UnicodeString *)(ne->value.pointer));
UnicodeString item = *static_cast<UnicodeString*>(ne->value.pointer);
permutations.removeAll();
permute(item, CANITER_SKIP_ZEROES, &permutations, status);
@ -387,7 +390,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
while (ne2 != nullptr) {
//String possible = (String) it2.next();
//UnicodeString *possible = new UnicodeString(*((UnicodeString *)(ne2->value.pointer)));
UnicodeString possible(*((UnicodeString *)(ne2->value.pointer)));
UnicodeString possible(*static_cast<UnicodeString*>(ne2->value.pointer));
UnicodeString attempt;
nfd->normalize(possible, attempt, status);
@ -429,7 +432,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i
el = UHASH_FIRST;
ne = result.nextElement(el);
while(ne != nullptr) {
finalResult[result_len++] = *((UnicodeString *)(ne->value.pointer));
finalResult[result_len++] = *static_cast<UnicodeString*>(ne->value.pointer);
ne = result.nextElement(el);
}
@ -466,6 +469,9 @@ Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const cha
Hashtable remainder(status);
remainder.setValueDeleter(uprv_deleteUObject);
if (extract(&remainder, cp2, segment, segLen, i, status) == nullptr) {
if (U_FAILURE(status)) {
return nullptr;
}
continue;
}
@ -476,7 +482,7 @@ Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const cha
int32_t el = UHASH_FIRST;
const UHashElement *ne = remainder.nextElement(el);
while (ne != nullptr) {
UnicodeString item = *((UnicodeString *)(ne->value.pointer));
UnicodeString item = *static_cast<UnicodeString*>(ne->value.pointer);
UnicodeString *toAdd = new UnicodeString(prefix);
/* test for nullptr */
if (toAdd == nullptr) {
@ -490,6 +496,13 @@ Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const cha
ne = remainder.nextElement(el);
}
// ICU-22642 Guards against strings that have so many permutations
// that they would otherwise hang the function.
constexpr int32_t kResultLimit = 4096;
if (fillinResult->count() > kResultLimit) {
status = U_UNSUPPORTED_ERROR;
return nullptr;
}
}
}

View file

@ -58,17 +58,17 @@ icu::UMutex cpMutex;
// Does not use uset.h to reduce code dependencies
void U_CALLCONV
_set_add(USet *set, UChar32 c) {
((UnicodeSet *)set)->add(c);
reinterpret_cast<UnicodeSet*>(set)->add(c);
}
void U_CALLCONV
_set_addRange(USet *set, UChar32 start, UChar32 end) {
((UnicodeSet *)set)->add(start, end);
reinterpret_cast<UnicodeSet*>(set)->add(start, end);
}
void U_CALLCONV
_set_addString(USet *set, const char16_t *str, int32_t length) {
((UnicodeSet *)set)->add(icu::UnicodeString((UBool)(length<0), str, length));
reinterpret_cast<UnicodeSet*>(set)->add(icu::UnicodeString(static_cast<UBool>(length < 0), str, length));
}
UBool U_CALLCONV characterproperties_cleanup() {
@ -103,7 +103,7 @@ void U_CALLCONV initInclusion(UPropertySource src, UErrorCode &errorCode) {
return;
}
USetAdder sa = {
(USet *)incl.getAlias(),
reinterpret_cast<USet*>(incl.getAlias()),
_set_add,
_set_addRange,
_set_addString,
@ -184,8 +184,12 @@ void U_CALLCONV initInclusion(UPropertySource src, UErrorCode &errorCode) {
sa.add(sa.set, 0x2FFF + 1);
break;
case UPROPS_SRC_ID_COMPAT_MATH:
case UPROPS_SRC_MCM:
uprops_addPropertyStarts(src, &sa, &errorCode);
break;
case UPROPS_SRC_BLOCK:
ublock_addPropertyStarts(&sa, errorCode);
break;
default:
errorCode = U_INTERNAL_PROGRAM_ERROR;
break;
@ -289,7 +293,7 @@ UnicodeSet *makeSet(UProperty property, UErrorCode &errorCode) {
const icu::EmojiProps *ep = icu::EmojiProps::getSingleton(errorCode);
if (U_FAILURE(errorCode)) { return nullptr; }
USetAdder sa = {
(USet *)set.getAlias(),
reinterpret_cast<USet*>(set.getAlias()),
_set_add,
_set_addRange,
_set_addString,

View file

@ -126,7 +126,7 @@ T_CString_toLowerCase(char* str)
if (str) {
do
*str = (char)uprv_tolower(*str);
*str = uprv_tolower(*str);
while (*(str++));
}
@ -140,7 +140,7 @@ T_CString_toUpperCase(char* str)
if (str) {
do
*str = (char)uprv_toupper(*str);
*str = uprv_toupper(*str);
while (*(str++));
}

View file

@ -61,12 +61,12 @@ DictionaryBreakEngine::findBreaks( UText *text,
// extends towards the start or end of the text, depending on 'reverse'.
utext_setNativeIndex(text, startPos);
int32_t start = (int32_t)utext_getNativeIndex(text);
int32_t start = static_cast<int32_t>(utext_getNativeIndex(text));
int32_t current;
int32_t rangeStart;
int32_t rangeEnd;
UChar32 c = utext_current32(text);
while((current = (int32_t)utext_getNativeIndex(text)) < endPos && fSet.contains(c)) {
while ((current = static_cast<int32_t>(utext_getNativeIndex(text))) < endPos && fSet.contains(c)) {
utext_next32(text); // TODO: recast loop for postincrement
c = utext_current32(text);
}
@ -137,7 +137,7 @@ public:
int32_t PossibleWord::candidates( UText *text, DictionaryMatcher *dict, int32_t rangeEnd ) {
// TODO: If getIndex is too slow, use offset < 0 and add discardAll()
int32_t start = (int32_t)utext_getNativeIndex(text);
int32_t start = static_cast<int32_t>(utext_getNativeIndex(text));
if (start != offset) {
offset = start;
count = dict->matches(text, rangeEnd-start, UPRV_LENGTHOF(cuLengths), cuLengths, cpLengths, nullptr, &prefix);
@ -253,7 +253,7 @@ ThaiBreakEngine::divideUpDictionaryRange( UText *text,
utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) {
while (U_SUCCESS(status) && (current = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd) {
cpWordLength = 0;
cuWordLength = 0;
@ -269,7 +269,7 @@ ThaiBreakEngine::divideUpDictionaryRange( UText *text,
// If there was more than one, see which one can take us forward the most words
else if (candidates > 1) {
// If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest;
}
do {
@ -278,7 +278,7 @@ ThaiBreakEngine::divideUpDictionaryRange( UText *text,
words[wordsFound%THAI_LOOKAHEAD].markCurrent();
// If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest;
}
@ -308,7 +308,7 @@ foundBest:
// The text iterator should now be positioned at the end of the word we found.
UChar32 uc = 0;
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cpWordLength < THAI_ROOT_COMBINE_THRESHOLD) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cpWordLength < THAI_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize
@ -320,9 +320,9 @@ foundBest:
UChar32 pc;
int32_t chars = 0;
for (;;) {
int32_t pcIndex = (int32_t)utext_getNativeIndex(text);
int32_t pcIndex = static_cast<int32_t>(utext_getNativeIndex(text));
pc = utext_next32(text);
int32_t pcSize = (int32_t)utext_getNativeIndex(text) - pcIndex;
int32_t pcSize = static_cast<int32_t>(utext_getNativeIndex(text)) - pcIndex;
chars += pcSize;
remaining -= pcSize;
if (remaining <= 0) {
@ -356,28 +356,28 @@ foundBest:
utext_setNativeIndex(text, current+cuWordLength);
}
}
// Never stop before a combining mark.
int32_t currPos;
while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
while ((currPos = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - currPos;
cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - currPos;
}
// Look ahead for possible suffixes if a dictionary word does not follow.
// We do this in code rather than using a rule so that the heuristic
// resynch continues to function. For example, one of the suffix characters
// could be a typo in the middle of a word.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cuWordLength > 0) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cuWordLength > 0) {
if (words[wordsFound%THAI_LOOKAHEAD].candidates(text, fDictionary, rangeEnd) <= 0
&& fSuffixSet.contains(uc = utext_current32(text))) {
if (uc == THAI_PAIYANNOI) {
if (!fSuffixSet.contains(utext_previous32(text))) {
// Skip over previous end and PAIYANNOI
utext_next32(text);
int32_t paiyannoiIndex = (int32_t)utext_getNativeIndex(text);
int32_t paiyannoiIndex = static_cast<int32_t>(utext_getNativeIndex(text));
utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - paiyannoiIndex; // Add PAIYANNOI to word
cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - paiyannoiIndex; // Add PAIYANNOI to word
uc = utext_current32(text); // Fetch next character
}
else {
@ -389,9 +389,9 @@ foundBest:
if (utext_previous32(text) != THAI_MAIYAMOK) {
// Skip over previous end and MAIYAMOK
utext_next32(text);
int32_t maiyamokIndex = (int32_t)utext_getNativeIndex(text);
int32_t maiyamokIndex = static_cast<int32_t>(utext_getNativeIndex(text));
utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - maiyamokIndex; // Add MAIYAMOK to word
cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - maiyamokIndex; // Add MAIYAMOK to word
}
else {
// Restore prior position
@ -489,7 +489,7 @@ LaoBreakEngine::divideUpDictionaryRange( UText *text,
utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) {
while (U_SUCCESS(status) && (current = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd) {
cuWordLength = 0;
cpWordLength = 0;
@ -514,7 +514,7 @@ LaoBreakEngine::divideUpDictionaryRange( UText *text,
words[wordsFound%LAO_LOOKAHEAD].markCurrent();
// If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest;
}
@ -541,7 +541,7 @@ foundBest:
// just found (if there is one), but only if the preceding word does not exceed
// the threshold.
// The text iterator should now be positioned at the end of the word we found.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cpWordLength < LAO_ROOT_COMBINE_THRESHOLD) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cpWordLength < LAO_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize
@ -554,9 +554,9 @@ foundBest:
UChar32 uc;
int32_t chars = 0;
for (;;) {
int32_t pcIndex = (int32_t)utext_getNativeIndex(text);
int32_t pcIndex = static_cast<int32_t>(utext_getNativeIndex(text));
pc = utext_next32(text);
int32_t pcSize = (int32_t)utext_getNativeIndex(text) - pcIndex;
int32_t pcSize = static_cast<int32_t>(utext_getNativeIndex(text)) - pcIndex;
chars += pcSize;
remaining -= pcSize;
if (remaining <= 0) {
@ -590,9 +590,9 @@ foundBest:
// Never stop before a combining mark.
int32_t currPos;
while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
while ((currPos = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - currPos;
cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - currPos;
}
// Look ahead for possible suffixes if a dictionary word does not follow.
@ -682,7 +682,7 @@ BurmeseBreakEngine::divideUpDictionaryRange( UText *text,
utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) {
while (U_SUCCESS(status) && (current = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd) {
cuWordLength = 0;
cpWordLength = 0;
@ -707,7 +707,7 @@ BurmeseBreakEngine::divideUpDictionaryRange( UText *text,
words[wordsFound%BURMESE_LOOKAHEAD].markCurrent();
// If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest;
}
@ -734,7 +734,7 @@ foundBest:
// just found (if there is one), but only if the preceding word does not exceed
// the threshold.
// The text iterator should now be positioned at the end of the word we found.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cpWordLength < BURMESE_ROOT_COMBINE_THRESHOLD) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cpWordLength < BURMESE_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize
@ -747,9 +747,9 @@ foundBest:
UChar32 uc;
int32_t chars = 0;
for (;;) {
int32_t pcIndex = (int32_t)utext_getNativeIndex(text);
int32_t pcIndex = static_cast<int32_t>(utext_getNativeIndex(text));
pc = utext_next32(text);
int32_t pcSize = (int32_t)utext_getNativeIndex(text) - pcIndex;
int32_t pcSize = static_cast<int32_t>(utext_getNativeIndex(text)) - pcIndex;
chars += pcSize;
remaining -= pcSize;
if (remaining <= 0) {
@ -783,9 +783,9 @@ foundBest:
// Never stop before a combining mark.
int32_t currPos;
while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
while ((currPos = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - currPos;
cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - currPos;
}
// Look ahead for possible suffixes if a dictionary word does not follow.
@ -888,7 +888,7 @@ KhmerBreakEngine::divideUpDictionaryRange( UText *text,
utext_setNativeIndex(text, rangeStart);
while (U_SUCCESS(status) && (current = (int32_t)utext_getNativeIndex(text)) < rangeEnd) {
while (U_SUCCESS(status) && (current = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd) {
cuWordLength = 0;
cpWordLength = 0;
@ -905,7 +905,7 @@ KhmerBreakEngine::divideUpDictionaryRange( UText *text,
// If there was more than one, see which one can take us forward the most words
else if (candidates > 1) {
// If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest;
}
do {
@ -914,7 +914,7 @@ KhmerBreakEngine::divideUpDictionaryRange( UText *text,
words[wordsFound % KHMER_LOOKAHEAD].markCurrent();
// If we're already at the end of the range, we're done
if ((int32_t)utext_getNativeIndex(text) >= rangeEnd) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) >= rangeEnd) {
goto foundBest;
}
@ -941,7 +941,7 @@ foundBest:
// just found (if there is one), but only if the preceding word does not exceed
// the threshold.
// The text iterator should now be positioned at the end of the word we found.
if ((int32_t)utext_getNativeIndex(text) < rangeEnd && cpWordLength < KHMER_ROOT_COMBINE_THRESHOLD) {
if (static_cast<int32_t>(utext_getNativeIndex(text)) < rangeEnd && cpWordLength < KHMER_ROOT_COMBINE_THRESHOLD) {
// if it is a dictionary word, do nothing. If it isn't, then if there is
// no preceding word, or the non-word shares less than the minimum threshold
// of characters with a dictionary word, then scan to resynchronize
@ -954,9 +954,9 @@ foundBest:
UChar32 uc;
int32_t chars = 0;
for (;;) {
int32_t pcIndex = (int32_t)utext_getNativeIndex(text);
int32_t pcIndex = static_cast<int32_t>(utext_getNativeIndex(text));
pc = utext_next32(text);
int32_t pcSize = (int32_t)utext_getNativeIndex(text) - pcIndex;
int32_t pcSize = static_cast<int32_t>(utext_getNativeIndex(text)) - pcIndex;
chars += pcSize;
remaining -= pcSize;
if (remaining <= 0) {
@ -989,9 +989,9 @@ foundBest:
// Never stop before a combining mark.
int32_t currPos;
while ((currPos = (int32_t)utext_getNativeIndex(text)) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
while ((currPos = static_cast<int32_t>(utext_getNativeIndex(text))) < rangeEnd && fMarkSet.contains(utext_current32(text))) {
utext_next32(text);
cuWordLength += (int32_t)utext_getNativeIndex(text) - currPos;
cuWordLength += static_cast<int32_t>(utext_getNativeIndex(text)) - currPos;
}
// Look ahead for possible suffixes if a dictionary word does not follow.
@ -1120,7 +1120,7 @@ static inline bool isKatakana(UChar32 value) {
// Replicates an internal UText function.
static inline int32_t utext_i32_flag(int32_t bitIndex) {
return (int32_t)1 << bitIndex;
return static_cast<int32_t>(1) << bitIndex;
}
/*
@ -1167,14 +1167,14 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
int32_t limit = rangeEnd;
U_ASSERT(limit <= utext_nativeLength(inText));
if (limit > utext_nativeLength(inText)) {
limit = (int32_t)utext_nativeLength(inText);
limit = static_cast<int32_t>(utext_nativeLength(inText));
}
inputMap.adoptInsteadAndCheckErrorCode(new UVector32(status), status);
if (U_FAILURE(status)) {
return 0;
}
while (utext_getNativeIndex(inText) < limit) {
int32_t nativePosition = (int32_t)utext_getNativeIndex(inText);
int32_t nativePosition = static_cast<int32_t>(utext_getNativeIndex(inText));
UChar32 c = utext_next32(inText);
U_ASSERT(c != U_SENTINEL);
inString.append(c);
@ -1304,7 +1304,7 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
int32_t ix = 0;
bool is_prev_katakana = false;
for (int32_t i = 0; i < numCodePts; ++i, ix = inString.moveIndex32(ix, 1)) {
if ((uint32_t)bestSnlp.elementAti(i) == kuint32max) {
if (static_cast<uint32_t>(bestSnlp.elementAti(i)) == kuint32max) {
continue;
}
@ -1327,9 +1327,9 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
}
for (int32_t j = 0; j < count; j++) {
uint32_t newSnlp = (uint32_t)bestSnlp.elementAti(i) + (uint32_t)values.elementAti(j);
uint32_t newSnlp = static_cast<uint32_t>(bestSnlp.elementAti(i)) + static_cast<uint32_t>(values.elementAti(j));
int32_t ln_j_i = lengths.elementAti(j) + i;
if (newSnlp < (uint32_t)bestSnlp.elementAti(ln_j_i)) {
if (newSnlp < static_cast<uint32_t>(bestSnlp.elementAti(ln_j_i))) {
bestSnlp.setElementAt(newSnlp, ln_j_i);
prev.setElementAt(i, ln_j_i);
}
@ -1353,7 +1353,7 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
}
if (katakanaRunLength < kMaxKatakanaGroupLength) {
uint32_t newSnlp = bestSnlp.elementAti(i) + getKatakanaCost(katakanaRunLength);
if (newSnlp < (uint32_t)bestSnlp.elementAti(i+katakanaRunLength)) {
if (newSnlp < static_cast<uint32_t>(bestSnlp.elementAti(i + katakanaRunLength))) {
bestSnlp.setElementAt(newSnlp, i+katakanaRunLength);
prev.setElementAt(i, i+katakanaRunLength); // prev[j] = i;
}
@ -1371,7 +1371,7 @@ CjkBreakEngine::divideUpDictionaryRange( UText *inText,
int32_t numBreaks = 0;
// No segmentation found, set boundary to end of range
if ((uint32_t)bestSnlp.elementAti(numCodePts) == kuint32max) {
if (static_cast<uint32_t>(bestSnlp.elementAti(numCodePts)) == kuint32max) {
t_boundary.addElement(numCodePts, status);
numBreaks++;
} else if (isPhraseBreaking) {

View file

@ -47,13 +47,13 @@ int32_t UCharsDictionaryMatcher::matches(UText *text, int32_t maxLength, int32_t
int32_t *prefix) const {
UCharsTrie uct(characters);
int32_t startingTextIndex = (int32_t)utext_getNativeIndex(text);
int32_t startingTextIndex = static_cast<int32_t>(utext_getNativeIndex(text));
int32_t wordCount = 0;
int32_t codePointsMatched = 0;
for (UChar32 c = utext_next32(text); c >= 0; c=utext_next32(text)) {
UStringTrieResult result = (codePointsMatched == 0) ? uct.first(c) : uct.next(c);
int32_t lengthMatched = (int32_t)utext_getNativeIndex(text) - startingTextIndex;
int32_t lengthMatched = static_cast<int32_t>(utext_getNativeIndex(text)) - startingTextIndex;
codePointsMatched += 1;
if (USTRINGTRIE_HAS_VALUE(result)) {
if (wordCount < limit) {
@ -101,7 +101,7 @@ UChar32 BytesDictionaryMatcher::transform(UChar32 c) const {
if (delta < 0 || 0xFD < delta) {
return U_SENTINEL;
}
return (UChar32)delta;
return static_cast<UChar32>(delta);
}
return c;
}
@ -114,13 +114,13 @@ int32_t BytesDictionaryMatcher::matches(UText *text, int32_t maxLength, int32_t
int32_t *lengths, int32_t *cpLengths, int32_t *values,
int32_t *prefix) const {
BytesTrie bt(characters);
int32_t startingTextIndex = (int32_t)utext_getNativeIndex(text);
int32_t startingTextIndex = static_cast<int32_t>(utext_getNativeIndex(text));
int32_t wordCount = 0;
int32_t codePointsMatched = 0;
for (UChar32 c = utext_next32(text); c >= 0; c=utext_next32(text)) {
UStringTrieResult result = (codePointsMatched == 0) ? bt.first(transform(c)) : bt.next(transform(c));
int32_t lengthMatched = (int32_t)utext_getNativeIndex(text) - startingTextIndex;
int32_t lengthMatched = static_cast<int32_t>(utext_getNativeIndex(text)) - startingTextIndex;
codePointsMatched += 1;
if (USTRINGTRIE_HAS_VALUE(result)) {
if (wordCount < limit) {

View file

@ -47,7 +47,7 @@ Edits &Edits::copyArray(const Edits &other) {
return *this;
}
if (length > capacity) {
uint16_t *newArray = (uint16_t *)uprv_malloc((size_t)length * 2);
uint16_t* newArray = static_cast<uint16_t*>(uprv_malloc(static_cast<size_t>(length) * 2));
if (newArray == nullptr) {
length = delta = numChanges = 0;
errorCode_ = U_MEMORY_ALLOCATION_ERROR;
@ -186,30 +186,30 @@ void Edits::addReplace(int32_t oldLength, int32_t newLength) {
head |= oldLength << 6;
} else if(oldLength <= 0x7fff) {
head |= LENGTH_IN_1TRAIL << 6;
array[limit++] = (uint16_t)(0x8000 | oldLength);
array[limit++] = static_cast<uint16_t>(0x8000 | oldLength);
} else {
head |= (LENGTH_IN_2TRAIL + (oldLength >> 30)) << 6;
array[limit++] = (uint16_t)(0x8000 | (oldLength >> 15));
array[limit++] = (uint16_t)(0x8000 | oldLength);
array[limit++] = static_cast<uint16_t>(0x8000 | (oldLength >> 15));
array[limit++] = static_cast<uint16_t>(0x8000 | oldLength);
}
if(newLength < LENGTH_IN_1TRAIL) {
head |= newLength;
} else if(newLength <= 0x7fff) {
head |= LENGTH_IN_1TRAIL;
array[limit++] = (uint16_t)(0x8000 | newLength);
array[limit++] = static_cast<uint16_t>(0x8000 | newLength);
} else {
head |= LENGTH_IN_2TRAIL + (newLength >> 30);
array[limit++] = (uint16_t)(0x8000 | (newLength >> 15));
array[limit++] = (uint16_t)(0x8000 | newLength);
array[limit++] = static_cast<uint16_t>(0x8000 | (newLength >> 15));
array[limit++] = static_cast<uint16_t>(0x8000 | newLength);
}
array[length] = (uint16_t)head;
array[length] = static_cast<uint16_t>(head);
length = limit;
}
}
void Edits::append(int32_t r) {
if(length < capacity || growArray()) {
array[length++] = (uint16_t)r;
array[length++] = static_cast<uint16_t>(r);
}
}
@ -232,7 +232,7 @@ UBool Edits::growArray() {
errorCode_ = U_INDEX_OUTOFBOUNDS_ERROR;
return false;
}
uint16_t *newArray = (uint16_t *)uprv_malloc((size_t)newCapacity * 2);
uint16_t* newArray = static_cast<uint16_t*>(uprv_malloc(static_cast<size_t>(newCapacity) * 2));
if (newArray == nullptr) {
errorCode_ = U_MEMORY_ALLOCATION_ERROR;
return false;
@ -415,7 +415,7 @@ int32_t Edits::Iterator::readLength(int32_t head) {
U_ASSERT(array[index] >= 0x8000);
U_ASSERT(array[index + 1] >= 0x8000);
int32_t len = ((head & 1) << 30) |
((int32_t)(array[index] & 0x7fff) << 15) |
(static_cast<int32_t>(array[index] & 0x7fff) << 15) |
(array[index + 1] & 0x7fff);
index += 2;
return len;

View file

@ -83,8 +83,8 @@ void
EmojiProps::load(UErrorCode &errorCode) {
memory = udata_openChoice(nullptr, "icu", "uemoji", isAcceptable, this, &errorCode);
if (U_FAILURE(errorCode)) { return; }
const uint8_t *inBytes = (const uint8_t *)udata_getMemory(memory);
const int32_t *inIndexes = (const int32_t *)inBytes;
const uint8_t* inBytes = static_cast<const uint8_t*>(udata_getMemory(memory));
const int32_t* inIndexes = reinterpret_cast<const int32_t*>(inBytes);
int32_t indexesLength = inIndexes[IX_CPTRIE_OFFSET] / 4;
if (indexesLength <= IX_RGI_EMOJI_ZWJ_SEQUENCE_TRIE_OFFSET) {
errorCode = U_INVALID_FORMAT_ERROR; // Not enough indexes.
@ -104,7 +104,7 @@ EmojiProps::load(UErrorCode &errorCode) {
offset = inIndexes[i];
nextOffset = inIndexes[i + 1];
// Set/leave nullptr if there is no UCharsTrie.
const char16_t *p = nextOffset > offset ? (const char16_t *)(inBytes + offset) : nullptr;
const char16_t* p = nextOffset > offset ? reinterpret_cast<const char16_t*>(inBytes + offset) : nullptr;
stringTries[getStringTrieIndex(i)] = p;
}
}

View file

@ -50,8 +50,8 @@ static void _fb_trace(const char *m, const UnicodeString *s, UBool b, int32_t d,
* Used with sortedInsert()
*/
static int32_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) {
const UnicodeString &a = *(const UnicodeString*)t1.pointer;
const UnicodeString &b = *(const UnicodeString*)t2.pointer;
const UnicodeString& a = *static_cast<const UnicodeString*>(t1.pointer);
const UnicodeString& b = *static_cast<const UnicodeString*>(t2.pointer);
return a.compare(b);
}
@ -76,7 +76,7 @@ class UStringSet : public UVector {
* Return the ith UnicodeString alias
*/
inline const UnicodeString* getStringAt(int32_t i) const {
return (const UnicodeString*)elementAt(i);
return static_cast<const UnicodeString*>(elementAt(i));
}
/**
* Adopt the UnicodeString if not already contained.

View file

@ -747,7 +747,7 @@ uplug_init(UErrorCode *status) {
FILE *f;
CharString pluginFile;
#ifdef OS390BATCH
#ifdef ICU_PLUGINS_DD
/* There are potentially a lot of ways to implement a plugin directory on OS390/zOS */
/* Keeping in mind that unauthorized file access is logged, monitored, and enforced */
/* I've chosen to open a DDNAME if BATCH and leave it alone for (presumably) UNIX */

View file

@ -63,7 +63,7 @@ LoadedNormalizer2Impl::isAcceptable(void * /*context*/,
pInfo->dataFormat[1]==0x72 &&
pInfo->dataFormat[2]==0x6d &&
pInfo->dataFormat[3]==0x32 &&
pInfo->formatVersion[0]==4
pInfo->formatVersion[0]==5
) {
// Normalizer2Impl *me=(Normalizer2Impl *)context;
// uprv_memcpy(me->dataVersion, pInfo->dataVersion, 4);
@ -82,8 +82,8 @@ LoadedNormalizer2Impl::load(const char *packageName, const char *name, UErrorCod
if(U_FAILURE(errorCode)) {
return;
}
const uint8_t *inBytes=(const uint8_t *)udata_getMemory(memory);
const int32_t *inIndexes=(const int32_t *)inBytes;
const uint8_t* inBytes = static_cast<const uint8_t*>(udata_getMemory(memory));
const int32_t* inIndexes = reinterpret_cast<const int32_t*>(inBytes);
int32_t indexesLength=inIndexes[IX_NORM_TRIE_OFFSET]/4;
if(indexesLength<=IX_MIN_LCCC_CP) {
errorCode=U_INVALID_FORMAT_ERROR; // Not enough indexes.
@ -101,7 +101,7 @@ LoadedNormalizer2Impl::load(const char *packageName, const char *name, UErrorCod
offset=nextOffset;
nextOffset=inIndexes[IX_SMALL_FCD_OFFSET];
const uint16_t *inExtraData=(const uint16_t *)(inBytes+offset);
const uint16_t* inExtraData = reinterpret_cast<const uint16_t*>(inBytes + offset);
// smallFCD: new in formatVersion 2
offset=nextOffset;
@ -311,7 +311,7 @@ Normalizer2::getInstance(const char *packageName,
{
Mutex lock;
if(cache!=nullptr) {
allModes=(Norm2AllModes *)uhash_get(cache, name);
allModes = static_cast<Norm2AllModes*>(uhash_get(cache, name));
}
}
if(allModes==nullptr) {
@ -331,7 +331,7 @@ Normalizer2::getInstance(const char *packageName,
void *temp=uhash_get(cache, name);
if(temp==nullptr) {
int32_t keyLength= static_cast<int32_t>(uprv_strlen(name)+1);
char *nameCopy=(char *)uprv_malloc(keyLength);
char* nameCopy = static_cast<char*>(uprv_malloc(keyLength));
if(nameCopy==nullptr) {
errorCode=U_MEMORY_ALLOCATION_ERROR;
return nullptr;
@ -341,7 +341,7 @@ Normalizer2::getInstance(const char *packageName,
uhash_put(cache, nameCopy, localAllModes.orphan(), &errorCode);
} else {
// race condition
allModes=(Norm2AllModes *)temp;
allModes = static_cast<Norm2AllModes*>(temp);
}
}
}

View file

@ -1,6 +1,8 @@
// © 2019 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
#include <optional>
#include <string_view>
#include <utility>
#include "bytesinkutil.h" // StringByteSink<CharString>
@ -162,12 +164,15 @@ _isKeywordValue(const char* key, const char* value, int32_t value_len)
// otherwise: unicode extension value
// We need to convert from legacy key/value to unicode
// key/value
const char* unicode_locale_key = uloc_toUnicodeLocaleKey(key);
const char* unicode_locale_type = uloc_toUnicodeLocaleType(key, value);
std::optional<std::string_view> unicode_locale_key = ulocimp_toBcpKeyWithFallback(key);
std::optional<std::string_view> unicode_locale_type = ulocimp_toBcpTypeWithFallback(key, value);
return unicode_locale_key && unicode_locale_type &&
ultag_isUnicodeLocaleKey(unicode_locale_key, -1) &&
ultag_isUnicodeLocaleType(unicode_locale_type, -1);
return unicode_locale_key.has_value() &&
unicode_locale_type.has_value() &&
ultag_isUnicodeLocaleKey(unicode_locale_key->data(),
static_cast<int32_t>(unicode_locale_key->size())) &&
ultag_isUnicodeLocaleType(unicode_locale_type->data(),
static_cast<int32_t>(unicode_locale_type->size()));
}
void

File diff suppressed because it is too large Load diff

View file

@ -780,7 +780,7 @@ int32_t acceptLanguage(UEnumeration &supportedLocales, Locale::Iterator &desired
ULOC_ACCEPT_VALID : ULOC_ACCEPT_FALLBACK;
}
const char *bestStr = result.getSupportedLocale()->getName();
int32_t bestLength = (int32_t)uprv_strlen(bestStr);
int32_t bestLength = static_cast<int32_t>(uprv_strlen(bestStr));
if (bestLength <= capacity) {
uprv_memcpy(dest, bestStr, bestLength);
}

View file

@ -99,7 +99,7 @@ inline LocaleBased::LocaleBased(char* validAlias, char* actualAlias) :
inline LocaleBased::LocaleBased(const char* validAlias,
const char* actualAlias) :
// ugh: cast away const
valid((char*)validAlias), actual((char*)actualAlias) {
valid(const_cast<char*>(validAlias)), actual(const_cast<char*>(actualAlias)) {
}
U_NAMESPACE_END

View file

@ -245,7 +245,7 @@ Locale::getDisplayName(const Locale &displayLocale,
return result;
}
#if ! UCONFIG_NO_BREAK_ITERATION
#if !UCONFIG_NO_BREAK_ITERATION
// -------------------------------------
// Gets the objectLocale display name in the default locale language.
@ -351,7 +351,7 @@ _getStringOrCopyKey(const char *path, const char *locale,
}
} else {
/* no string from a resource bundle: convert the substitute */
length=(int32_t)uprv_strlen(substitute);
length = static_cast<int32_t>(uprv_strlen(substitute));
u_charsToUChars(substitute, dest, uprv_min(length, destCapacity));
errorCode = U_USING_DEFAULT_WARNING;
}
@ -835,7 +835,10 @@ uloc_getDisplayKeywordValue( const char* locale,
}
/* get the keyword value */
CharString keywordValue = ulocimp_getKeywordValue(locale, keyword, *status);
CharString keywordValue;
if (keyword != nullptr && *keyword != '\0') {
keywordValue = ulocimp_getKeywordValue(locale, keyword, *status);
}
/*
* if the keyword is equal to currency .. then to get the display name

View file

@ -336,10 +336,11 @@ LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
{
while (length-- > 0) {
UDisplayContext value = *contexts++;
UDisplayContextType selector = (UDisplayContextType)((uint32_t)value >> 8);
UDisplayContextType selector =
static_cast<UDisplayContextType>(static_cast<uint32_t>(value) >> 8);
switch (selector) {
case UDISPCTX_TYPE_DIALECT_HANDLING:
dialectHandling = (UDialectHandling)value;
dialectHandling = static_cast<UDialectHandling>(value);
break;
case UDISPCTX_TYPE_CAPITALIZATION:
capitalizationContext = value;
@ -407,7 +408,7 @@ LocaleDisplayNamesImpl::CapitalizationContextSink::~CapitalizationContextSink()
void
LocaleDisplayNamesImpl::initialize() {
LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this;
LocaleDisplayNamesImpl* nonConstThis = this;
nonConstThis->locale = langData.getLocale() == Locale::getRoot()
? regionData.getLocale()
: langData.getLocale();
@ -426,16 +427,16 @@ LocaleDisplayNamesImpl::initialize() {
pattern = UnicodeString("{0} ({1})", -1, US_INV);
}
format.applyPatternMinMaxArguments(pattern, 2, 2, status);
if (pattern.indexOf((char16_t)0xFF08) >= 0) {
formatOpenParen.setTo((char16_t)0xFF08); // fullwidth (
formatReplaceOpenParen.setTo((char16_t)0xFF3B); // fullwidth [
formatCloseParen.setTo((char16_t)0xFF09); // fullwidth )
formatReplaceCloseParen.setTo((char16_t)0xFF3D); // fullwidth ]
if (pattern.indexOf(static_cast<char16_t>(0xFF08)) >= 0) {
formatOpenParen.setTo(static_cast<char16_t>(0xFF08)); // fullwidth (
formatReplaceOpenParen.setTo(static_cast<char16_t>(0xFF3B)); // fullwidth [
formatCloseParen.setTo(static_cast<char16_t>(0xFF09)); // fullwidth )
formatReplaceCloseParen.setTo(static_cast<char16_t>(0xFF3D)); // fullwidth ]
} else {
formatOpenParen.setTo((char16_t)0x0028); // (
formatReplaceOpenParen.setTo((char16_t)0x005B); // [
formatCloseParen.setTo((char16_t)0x0029); // )
formatReplaceCloseParen.setTo((char16_t)0x005D); // ]
formatOpenParen.setTo(static_cast<char16_t>(0x0028)); // (
formatReplaceOpenParen.setTo(static_cast<char16_t>(0x005B)); // [
formatCloseParen.setTo(static_cast<char16_t>(0x0029)); // )
formatReplaceCloseParen.setTo(static_cast<char16_t>(0x005D)); // ]
}
UnicodeString ktPattern;
@ -495,7 +496,7 @@ UDisplayContext
LocaleDisplayNamesImpl::getContext(UDisplayContextType type) const {
switch (type) {
case UDISPCTX_TYPE_DIALECT_HANDLING:
return (UDisplayContext)dialectHandling;
return static_cast<UDisplayContext>(dialectHandling);
case UDISPCTX_TYPE_CAPITALIZATION:
return capitalizationContext;
case UDISPCTX_TYPE_DISPLAY_LENGTH:
@ -505,7 +506,7 @@ LocaleDisplayNamesImpl::getContext(UDisplayContextType type) const {
default:
break;
}
return (UDisplayContext)0;
return static_cast<UDisplayContext>(0);
}
UnicodeString&
@ -652,7 +653,7 @@ LocaleDisplayNamesImpl::localeDisplayName(const Locale& loc,
appendWithSep(resultRemainder, temp3);
} else {
appendWithSep(resultRemainder, temp)
.append((char16_t)0x3d /* = */)
.append(static_cast<char16_t>(0x3d) /* = */)
.append(temp2);
}
}

View file

@ -31,6 +31,8 @@
******************************************************************************
*/
#include <optional>
#include <string_view>
#include <utility>
#include "unicode/bytestream.h"
@ -109,7 +111,7 @@ namespace {
//
void U_CALLCONV
deleteLocale(void *obj) {
delete (icu::Locale *) obj;
delete static_cast<icu::Locale*>(obj);
}
UBool U_CALLCONV locale_cleanup()
@ -132,7 +134,7 @@ void U_CALLCONV locale_init(UErrorCode &status) {
U_NAMESPACE_USE
U_ASSERT(gLocaleCache == nullptr);
gLocaleCache = new Locale[(int)eMAX_LOCALES];
gLocaleCache = new Locale[static_cast<int>(eMAX_LOCALES)];
if (gLocaleCache == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
@ -194,7 +196,7 @@ Locale *locale_set_default_internal(const char *id, UErrorCode& status) {
ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
}
Locale *newDefault = (Locale *)uhash_get(gDefaultLocalesHashT, localeNameBuf.data());
Locale* newDefault = static_cast<Locale*>(uhash_get(gDefaultLocalesHashT, localeNameBuf.data()));
if (newDefault == nullptr) {
newDefault = new Locale(Locale::eBOGUS);
if (newDefault == nullptr) {
@ -202,7 +204,7 @@ Locale *locale_set_default_internal(const char *id, UErrorCode& status) {
return gDefaultLocale;
}
newDefault->init(localeNameBuf.data(), false);
uhash_put(gDefaultLocalesHashT, (char*) newDefault->getName(), newDefault, &status);
uhash_put(gDefaultLocalesHashT, const_cast<char*>(newDefault->getName()), newDefault, &status);
if (U_FAILURE(status)) {
return gDefaultLocale;
}
@ -296,7 +298,7 @@ Locale::Locale( const char * newLanguage,
// Language
if ( newLanguage != nullptr )
{
lsize = (int32_t)uprv_strlen(newLanguage);
lsize = static_cast<int32_t>(uprv_strlen(newLanguage));
if ( lsize < 0 || lsize > ULOC_STRING_LIMIT ) { // int32 wrap
setToBogus();
return;
@ -308,7 +310,7 @@ Locale::Locale( const char * newLanguage,
// _Country
if ( newCountry != nullptr )
{
csize = (int32_t)uprv_strlen(newCountry);
csize = static_cast<int32_t>(uprv_strlen(newCountry));
if ( csize < 0 || csize > ULOC_STRING_LIMIT ) { // int32 wrap
setToBogus();
return;
@ -325,7 +327,7 @@ Locale::Locale( const char * newLanguage,
}
// remove trailing _'s
vsize = (int32_t)uprv_strlen(newVariant);
vsize = static_cast<int32_t>(uprv_strlen(newVariant));
if ( vsize < 0 || vsize > ULOC_STRING_LIMIT ) { // int32 wrap
setToBogus();
return;
@ -338,7 +340,7 @@ Locale::Locale( const char * newLanguage,
if ( newKeywords != nullptr)
{
ksize = (int32_t)uprv_strlen(newKeywords);
ksize = static_cast<int32_t>(uprv_strlen(newKeywords));
if ( ksize < 0 || ksize > ULOC_STRING_LIMIT ) {
setToBogus();
return;
@ -1200,8 +1202,8 @@ AliasReplacer::parseLanguageReplacement(
return;
}
// We have multiple field so we have to allocate and parse
CharString* str = new CharString(
replacement, (int32_t)uprv_strlen(replacement), status);
CharString* str =
new CharString(replacement, static_cast<int32_t>(uprv_strlen(replacement)), status);
LocalPointer<CharString> lpStr(str, status);
toBeFreed.adoptElement(lpStr.orphan(), status);
if (U_FAILURE(status)) {
@ -1213,7 +1215,7 @@ AliasReplacer::parseLanguageReplacement(
*endOfField = '\0'; // null terminiate it.
endOfField++;
const char* start = endOfField;
endOfField = (char*) uprv_strchr(start, '_');
endOfField = const_cast<char*>(uprv_strchr(start, '_'));
size_t len = 0;
if (endOfField == nullptr) {
len = uprv_strlen(start);
@ -1228,7 +1230,7 @@ AliasReplacer::parseLanguageReplacement(
return;
}
start = endOfField++;
endOfField = (char*)uprv_strchr(start, '_');
endOfField = const_cast<char*>(uprv_strchr(start, '_'));
if (endOfField == nullptr) {
len = uprv_strlen(start);
} else {
@ -1243,7 +1245,7 @@ AliasReplacer::parseLanguageReplacement(
return;
}
start = endOfField++;
endOfField = (char*)uprv_strchr(start, '_');
endOfField = const_cast<char*>(uprv_strchr(start, '_'));
if (endOfField == nullptr) {
len = uprv_strlen(start);
} else {
@ -1285,7 +1287,7 @@ AliasReplacer::replaceLanguage(
variant_index++) {
if (checkVariants) {
U_ASSERT(variant_index < variant_size);
searchVariant = (const char*)(variants.elementAt(variant_index));
searchVariant = static_cast<const char*>(variants.elementAt(variant_index));
}
if (searchVariant != nullptr && uprv_strlen(searchVariant) < 4) {
@ -1406,13 +1408,13 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status)
U_ASSERT(foundInReplacement[len] == ' ' ||
foundInReplacement[len] == '\0');
item.adoptInsteadAndCheckErrorCode(
new CharString(foundInReplacement, (int32_t)len, status), status);
new CharString(foundInReplacement, static_cast<int32_t>(len), status), status);
}
}
if (item.isNull() && U_SUCCESS(status)) {
item.adoptInsteadAndCheckErrorCode(
new CharString(replacement,
(int32_t)(firstSpace - replacement), status), status);
static_cast<int32_t>(firstSpace - replacement), status), status);
}
if (U_FAILURE(status)) { return false; }
replacedRegion = item->data();
@ -1454,7 +1456,7 @@ AliasReplacer::replaceVariant(UErrorCode& status)
}
// Since we may have more than one variant, we need to loop through them.
for (int32_t i = 0; i < variants.size(); i++) {
const char *variant = (const char*)(variants.elementAt(i));
const char* variant = static_cast<const char*>(variants.elementAt(i));
const char *replacement = data->variantMap().get(variant);
if (replacement == nullptr) {
// Found no replacement data for this variant.
@ -1496,7 +1498,7 @@ AliasReplacer::replaceSubdivision(
size_t len = (firstSpace != nullptr) ?
(firstSpace - replacement) : uprv_strlen(replacement);
if (2 <= len && len <= 8) {
output.append(replacement, (int32_t)len, status);
output.append(replacement, static_cast<int32_t>(len), status);
if (2 == len) {
// Add 'zzzz' based on changes to UTS #35 for CLDR-14312.
output.append("zzzz", 4, status);
@ -1546,7 +1548,7 @@ AliasReplacer::replaceTransformedExtensions(
}
const char* nextTKey = ultag_getTKeyStart(tvalue);
if (nextTKey != nullptr) {
*((char*)(nextTKey-1)) = '\0'; // NUL terminate tvalue
*const_cast<char*>(nextTKey - 1) = '\0'; // NUL terminate tvalue
}
tfields.insertElementAt((void*)tkey, tfields.size(), status);
if (U_FAILURE(status)) {
@ -1561,17 +1563,17 @@ AliasReplacer::replaceTransformedExtensions(
if (output.length() > 0) {
output.append('-', status);
}
const char* tfield = (const char*) tfields.elementAt(i);
const char* tfield = static_cast<const char*>(tfields.elementAt(i));
const char* tvalue = uprv_strchr(tfield, '-');
if (tvalue == nullptr) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return false;
}
// Split the "tkey-tvalue" pair string so that we can canonicalize the tvalue.
*((char*)tvalue++) = '\0'; // NUL terminate tkey
*const_cast<char*>(tvalue++) = '\0'; // NUL terminate tkey
output.append(tfield, status).append('-', status);
const char* bcpTValue = ulocimp_toBcpType(tfield, tvalue, nullptr, nullptr);
output.append((bcpTValue == nullptr) ? tvalue : bcpTValue, status);
std::optional<std::string_view> bcpTValue = ulocimp_toBcpType(tfield, tvalue);
output.append(bcpTValue.has_value() ? *bcpTValue : tvalue, status);
}
}
if (U_FAILURE(status)) {
@ -1604,7 +1606,7 @@ AliasReplacer::outputToString(
int32_t variantsStart = out.length();
for (int32_t i = 0; i < variants.size(); i++) {
out.append(SEP_CHAR, status)
.append((const char*)(variants.elementAt(i)),
.append(static_cast<const char*>(variants.elementAt(i)),
status);
}
T_CString_toUpperCase(out.data() + variantsStart);
@ -1673,7 +1675,7 @@ AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode& status
int changed = 0;
// A UVector to to hold CharString allocated by the replace* method
// and freed when out of scope from his function.
UVector stringsToBeFreed([](void *obj){ delete ((CharString*) obj); },
UVector stringsToBeFreed([](void *obj) { delete static_cast<CharString*>(obj); },
nullptr, 10, status);
while (U_SUCCESS(status)) {
// Something wrong with the data cause looping here more than 10 times
@ -1866,14 +1868,14 @@ Locale& Locale::init(const char* localeID, UBool canonicalize)
uloc_canonicalize(localeID, fullName, sizeof(fullNameBuffer), &err) :
uloc_getName(localeID, fullName, sizeof(fullNameBuffer), &err);
if(err == U_BUFFER_OVERFLOW_ERROR || length >= (int32_t)sizeof(fullNameBuffer)) {
if (err == U_BUFFER_OVERFLOW_ERROR || length >= static_cast<int32_t>(sizeof(fullNameBuffer))) {
U_ASSERT(baseName == nullptr);
/*Go to heap for the fullName if necessary*/
fullName = (char *)uprv_malloc(sizeof(char)*(length + 1));
if (fullName == nullptr) {
fullName = fullNameBuffer;
char* newFullName = static_cast<char*>(uprv_malloc(sizeof(char) * (length + 1)));
if (newFullName == nullptr) {
break; // error: out of memory
}
fullName = newFullName;
err = U_ZERO_ERROR;
length = canonicalize ?
uloc_canonicalize(localeID, fullName, length+1, &err) :
@ -1895,7 +1897,7 @@ Locale& Locale::init(const char* localeID, UBool canonicalize)
fieldIdx < UPRV_LENGTHOF(field)-1 &&
(at == nullptr || separator < at)) {
field[fieldIdx] = separator + 1;
fieldLen[fieldIdx-1] = (int32_t)(separator - field[fieldIdx-1]);
fieldLen[fieldIdx - 1] = static_cast<int32_t>(separator - field[fieldIdx - 1]);
fieldIdx++;
}
// variant may contain @foo or .foo POSIX cruft; remove it
@ -1905,12 +1907,12 @@ Locale& Locale::init(const char* localeID, UBool canonicalize)
if (separator==nullptr || (sep2!=nullptr && separator > sep2)) {
separator = sep2;
}
fieldLen[fieldIdx-1] = (int32_t)(separator - field[fieldIdx-1]);
fieldLen[fieldIdx - 1] = static_cast<int32_t>(separator - field[fieldIdx - 1]);
} else {
fieldLen[fieldIdx-1] = length - (int32_t)(field[fieldIdx-1] - fullName);
fieldLen[fieldIdx - 1] = length - static_cast<int32_t>(field[fieldIdx - 1] - fullName);
}
if (fieldLen[0] >= (int32_t)(sizeof(language)))
if (fieldLen[0] >= static_cast<int32_t>(sizeof(language)))
{
break; // error: the language field is too long
}
@ -1941,7 +1943,7 @@ Locale& Locale::init(const char* localeID, UBool canonicalize)
if (fieldLen[variantField] > 0) {
/* We have a variant */
variantBegin = (int32_t)(field[variantField] - fullName);
variantBegin = static_cast<int32_t>(field[variantField] - fullName);
}
err = U_ZERO_ERROR;
@ -1991,12 +1993,13 @@ Locale::initBaseName(UErrorCode &status) {
const char *eqPtr = uprv_strchr(fullName, '=');
if (atPtr && eqPtr && atPtr < eqPtr) {
// Key words exist.
int32_t baseNameLength = (int32_t)(atPtr - fullName);
baseName = (char *)uprv_malloc(baseNameLength + 1);
if (baseName == nullptr) {
int32_t baseNameLength = static_cast<int32_t>(atPtr - fullName);
char* newBaseName = static_cast<char*>(uprv_malloc(baseNameLength + 1));
if (newBaseName == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
baseName = newBaseName;
uprv_strncpy(baseName, fullName, baseNameLength);
baseName[baseNameLength] = 0;
@ -2434,7 +2437,7 @@ public:
UErrorCode status = U_ZERO_ERROR;
return new KeywordEnumeration(
keywords.data(), keywords.length(),
(int32_t)(current - keywords.data()), status);
static_cast<int32_t>(current - keywords.data()), status);
}
virtual int32_t count(UErrorCode& status) const override {
@ -2453,7 +2456,7 @@ public:
int32_t len;
if(U_SUCCESS(status) && *current != 0) {
result = current;
len = (int32_t)uprv_strlen(current);
len = static_cast<int32_t>(uprv_strlen(current));
current += len+1;
if(resultLength != nullptr) {
*resultLength = len;
@ -2596,13 +2599,7 @@ Locale::getKeywordValue(StringPiece keywordName, ByteSink& sink, UErrorCode& sta
return;
}
// TODO: Remove the need for a const char* to a NUL terminated buffer.
const CharString keywordName_nul(keywordName, status);
if (U_FAILURE(status)) {
return;
}
ulocimp_getKeywordValue(fullName, keywordName_nul.data(), sink, status);
ulocimp_getKeywordValue(fullName, keywordName, sink, status);
}
void
@ -2613,75 +2610,26 @@ Locale::getUnicodeKeywordValue(StringPiece keywordName,
return;
}
// TODO: Remove the need for a const char* to a NUL terminated buffer.
const CharString keywordName_nul(keywordName, status);
if (U_FAILURE(status)) {
return;
}
const char* legacy_key = uloc_toLegacyKey(keywordName_nul.data());
if (legacy_key == nullptr) {
std::optional<std::string_view> legacy_key = ulocimp_toLegacyKeyWithFallback(keywordName);
if (!legacy_key.has_value()) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
auto legacy_value = getKeywordValue<CharString>(legacy_key, status);
auto legacy_value = getKeywordValue<CharString>(*legacy_key, status);
if (U_FAILURE(status)) {
return;
}
const char* unicode_value = uloc_toUnicodeLocaleType(
keywordName_nul.data(), legacy_value.data());
if (unicode_value == nullptr) {
std::optional<std::string_view> unicode_value =
ulocimp_toBcpTypeWithFallback(keywordName, legacy_value.toStringPiece());
if (!unicode_value.has_value()) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
sink.Append(unicode_value, static_cast<int32_t>(uprv_strlen(unicode_value)));
}
void
Locale::setKeywordValue(const char* keywordName, const char* keywordValue, UErrorCode &status)
{
if (U_FAILURE(status)) {
return;
}
if (status == U_STRING_NOT_TERMINATED_WARNING) {
status = U_ZERO_ERROR;
}
int32_t bufferLength = uprv_max((int32_t)(uprv_strlen(fullName) + 1), ULOC_FULLNAME_CAPACITY);
int32_t newLength = uloc_setKeywordValue(keywordName, keywordValue, fullName,
bufferLength, &status) + 1;
U_ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
/* Handle the case the current buffer is not enough to hold the new id */
if (status == U_BUFFER_OVERFLOW_ERROR) {
U_ASSERT(newLength > bufferLength);
char* newFullName = (char *)uprv_malloc(newLength);
if (newFullName == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_strcpy(newFullName, fullName);
if (fullName != fullNameBuffer) {
// if full Name is already on the heap, need to free it.
uprv_free(fullName);
if (baseName == fullName) {
baseName = newFullName; // baseName should not point to freed memory.
}
}
fullName = newFullName;
status = U_ZERO_ERROR;
uloc_setKeywordValue(keywordName, keywordValue, fullName, newLength, &status);
U_ASSERT(status != U_STRING_NOT_TERMINATED_WARNING);
} else {
U_ASSERT(newLength <= bufferLength);
}
if (U_SUCCESS(status) && baseName == fullName) {
// May have added the first keyword, meaning that the fullName is no longer also the baseName.
initBaseName(status);
}
sink.Append(unicode_value->data(), static_cast<int32_t>(unicode_value->size()));
}
void
@ -2689,10 +2637,60 @@ Locale::setKeywordValue(StringPiece keywordName,
StringPiece keywordValue,
UErrorCode& status) {
if (U_FAILURE(status)) { return; }
// TODO: Remove the need for a const char* to a NUL terminated buffer.
const CharString keywordName_nul(keywordName, status);
const CharString keywordValue_nul(keywordValue, status);
setKeywordValue(keywordName_nul.data(), keywordValue_nul.data(), status);
if (keywordName.empty()) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
if (status == U_STRING_NOT_TERMINATED_WARNING) {
status = U_ZERO_ERROR;
}
int32_t length = static_cast<int32_t>(uprv_strlen(fullName));
int32_t capacity = fullName == fullNameBuffer ? ULOC_FULLNAME_CAPACITY : length + 1;
const char* start = locale_getKeywordsStart(fullName);
int32_t offset = start == nullptr ? length : start - fullName;
for (;;) {
// Remove -1 from the capacity so that this function can guarantee NUL termination.
CheckedArrayByteSink sink(fullName + offset, capacity - offset - 1);
int32_t reslen = ulocimp_setKeywordValue(
{fullName + offset, static_cast<std::string_view::size_type>(length - offset)},
keywordName,
keywordValue,
sink,
status);
if (status == U_BUFFER_OVERFLOW_ERROR) {
capacity = reslen + offset + 1;
char* newFullName = static_cast<char*>(uprv_malloc(capacity));
if (newFullName == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_memcpy(newFullName, fullName, length + 1);
if (fullName != fullNameBuffer) {
if (baseName == fullName) {
baseName = newFullName; // baseName should not point to freed memory.
}
// if fullName is already on the heap, need to free it.
uprv_free(fullName);
}
fullName = newFullName;
status = U_ZERO_ERROR;
continue;
}
if (U_FAILURE(status)) { return; }
u_terminateChars(fullName, capacity, reslen + offset, &status);
break;
}
if (baseName == fullName) {
// May have added the first keyword, meaning that the fullName is no longer also the baseName.
initBaseName(status);
}
}
void
@ -2703,32 +2701,25 @@ Locale::setUnicodeKeywordValue(StringPiece keywordName,
return;
}
// TODO: Remove the need for a const char* to a NUL terminated buffer.
const CharString keywordName_nul(keywordName, status);
const CharString keywordValue_nul(keywordValue, status);
if (U_FAILURE(status)) {
return;
}
const char* legacy_key = uloc_toLegacyKey(keywordName_nul.data());
if (legacy_key == nullptr) {
std::optional<std::string_view> legacy_key = ulocimp_toLegacyKeyWithFallback(keywordName);
if (!legacy_key.has_value()) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
const char* legacy_value = nullptr;
std::string_view value;
if (!keywordValue_nul.isEmpty()) {
legacy_value =
uloc_toLegacyType(keywordName_nul.data(), keywordValue_nul.data());
if (legacy_value == nullptr) {
if (!keywordValue.empty()) {
std::optional<std::string_view> legacy_value =
ulocimp_toLegacyTypeWithFallback(keywordName, keywordValue);
if (!legacy_value.has_value()) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
value = *legacy_value;
}
setKeywordValue(legacy_key, legacy_value, status);
setKeywordValue(*legacy_key, value, status);
}
const char *

View file

@ -19,6 +19,7 @@
* that then do not depend on resource bundle code and likely-subtags data.
*/
#include <string_view>
#include <utility>
#include "unicode/bytestream.h"
@ -170,7 +171,7 @@ _uloc_addLikelySubtags(const char* localeID,
return;
}
int32_t trailingLength = (int32_t)uprv_strlen(trailing);
int32_t trailingLength = static_cast<int32_t>(uprv_strlen(trailing));
const icu::LikelySubtags* likelySubtags = icu::LikelySubtags::getSingleton(err);
if (U_FAILURE(err)) {
@ -193,11 +194,11 @@ _uloc_addLikelySubtags(const char* localeID,
}
createTagStringWithAlternates(
language,
(int32_t)uprv_strlen(language),
static_cast<int32_t>(uprv_strlen(language)),
lsr.script,
(int32_t)uprv_strlen(lsr.script),
static_cast<int32_t>(uprv_strlen(lsr.script)),
lsr.region,
(int32_t)uprv_strlen(lsr.region),
static_cast<int32_t>(uprv_strlen(lsr.region)),
variant.data(),
variant.length(),
trailing,
@ -235,7 +236,7 @@ _uloc_minimizeSubtags(const char* localeID,
return;
}
int32_t trailingLength = (int32_t)uprv_strlen(trailing);
int32_t trailingLength = static_cast<int32_t>(uprv_strlen(trailing));
const icu::LikelySubtags* likelySubtags = icu::LikelySubtags::getSingleton(err);
if (U_FAILURE(err)) {
@ -256,11 +257,11 @@ _uloc_minimizeSubtags(const char* localeID,
}
createTagStringWithAlternates(
language,
(int32_t)uprv_strlen(language),
static_cast<int32_t>(uprv_strlen(language)),
lsr.script,
(int32_t)uprv_strlen(lsr.script),
static_cast<int32_t>(uprv_strlen(lsr.script)),
lsr.region,
(int32_t)uprv_strlen(lsr.region),
static_cast<int32_t>(uprv_strlen(lsr.region)),
variant.data(),
variant.length(),
trailing,
@ -388,21 +389,32 @@ U_NAMESPACE_END
namespace {
icu::CharString
GetRegionFromKey(const char* localeID, const char* key, UErrorCode& status) {
GetRegionFromKey(const char* localeID, std::string_view key, UErrorCode& status) {
icu::CharString result;
// First check for keyword value
icu::CharString kw = ulocimp_getKeywordValue(localeID, key, status);
int32_t len = kw.length();
if (U_SUCCESS(status) && len >= 3 && len <= 7) {
// chop off the subdivision code (which will generally be "zzzz" anyway)
const char* const data = kw.data();
if (uprv_isASCIILetter(data[0])) {
result.append(uprv_toupper(data[0]), status);
result.append(uprv_toupper(data[1]), status);
} else {
// assume three-digit region code
result.append(data, 3, status);
// In UTS35
// type = alphanum{3,8} (sep alphanum{3,8})* ;
// so we know the subdivision must fit the type already.
//
// unicode_subdivision_id = unicode_region_subtag unicode_subdivision_suffix ;
// unicode_region_subtag = (alpha{2} | digit{3}) ;
// unicode_subdivision_suffix = alphanum{1,4} ;
// But we also know there are no id in start with digit{3} in
// https://github.com/unicode-org/cldr/blob/main/common/validity/subdivision.xml
// Therefore we can simplify as
// unicode_subdivision_id = alpha{2} alphanum{1,4}
//
// and only need to accept/reject the code based on the alpha{2} and the length.
if (U_SUCCESS(status) && len >= 3 && len <= 6 &&
uprv_isASCIILetter(kw[0]) && uprv_isASCIILetter(kw[1])) {
// Additional Check
static icu::RegionValidateMap valid;
const char region[] = {kw[0], kw[1], '\0'};
if (valid.isSet(region)) {
result.append(uprv_toupper(kw[0]), status);
result.append(uprv_toupper(kw[1]), status);
}
}
return result;
@ -435,3 +447,55 @@ ulocimp_getRegionForSupplementalData(const char *localeID, bool inferRegion,
return rgBuf;
}
namespace {
// The following data is generated by unit test code inside
// test/intltest/regiontst.cpp from the resource data while
// the test failed.
const uint32_t gValidRegionMap[] = {
0xeedf597c, 0xdeddbdef, 0x15943f3f, 0x0e00d580,
0xb0095c00, 0x0015fb9f, 0x781c068d, 0x0340400f,
0xf42b1d00, 0xfd4f8141, 0x25d7fffc, 0x0100084b,
0x538f3c40, 0x40000001, 0xfdf15100, 0x9fbb7ae7,
0x0410419a, 0x00408557, 0x00004002, 0x00100001,
0x00400408, 0x00000001,
};
} // namespace
//
U_NAMESPACE_BEGIN
RegionValidateMap::RegionValidateMap() {
uprv_memcpy(map, gValidRegionMap, sizeof(map));
}
RegionValidateMap::~RegionValidateMap() {
}
bool RegionValidateMap::isSet(const char* region) const {
int32_t index = value(region);
if (index < 0) {
return false;
}
return 0 != (map[index / 32] & (1L << (index % 32)));
}
bool RegionValidateMap::equals(const RegionValidateMap& that) const {
return uprv_memcmp(map, that.map, sizeof(map)) == 0;
}
// The code transform two letter a-z to a integer valued between -1, 26x26.
// -1 indicate the region is outside the range of two letter a-z
// the rest of value is between 0 and 676 (= 26x26) and used as an index
// the the bigmap in map. The map is an array of 22 int32_t.
// since 32x21 < 676/32 < 32x22 we store this 676 bits bitmap into 22 int32_t.
int32_t RegionValidateMap::value(const char* region) const {
if (uprv_isASCIILetter(region[0]) && uprv_isASCIILetter(region[1]) &&
region[2] == '\0') {
return (uprv_toupper(region[0])-'A') * 26 +
(uprv_toupper(region[1])-'A');
}
return -1;
}
U_NAMESPACE_END

View file

@ -564,47 +564,40 @@ LSR LikelySubtags::makeMaximizedLsr(const char *language, const char *script, co
// Handle pseudolocales like en-XA, ar-XB, fr-PSCRACK.
// They should match only themselves,
// not other locales with what looks like the same language and script subtags.
char c1;
if (region[0] == 'X' && (c1 = region[1]) != 0 && region[2] == 0) {
switch (c1) {
case 'A':
if (returnInputIfUnmatch) {
return LSR(language, script, region, LSR::EXPLICIT_LSR);
if (!returnInputIfUnmatch) {
char c1;
if (region[0] == 'X' && (c1 = region[1]) != 0 && region[2] == 0) {
switch (c1) {
case 'A':
return LSR(PSEUDO_ACCENTS_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'B':
return LSR(PSEUDO_BIDI_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'C':
return LSR(PSEUDO_CRACKED_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
default: // normal locale
break;
}
return LSR(PSEUDO_ACCENTS_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'B':
if (returnInputIfUnmatch) {
return LSR(language, script, region, LSR::EXPLICIT_LSR);
}
return LSR(PSEUDO_BIDI_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
case 'C':
if (returnInputIfUnmatch) {
return LSR(language, script, region, LSR::EXPLICIT_LSR);
}
return LSR(PSEUDO_CRACKED_PREFIX, language, script, region,
LSR::EXPLICIT_LSR, errorCode);
default: // normal locale
break;
}
}
if (variant[0] == 'P' && variant[1] == 'S') {
int32_t lsrFlags = *region == 0 ?
LSR::EXPLICIT_LANGUAGE | LSR::EXPLICIT_SCRIPT : LSR::EXPLICIT_LSR;
if (uprv_strcmp(variant, "PSACCENT") == 0) {
return LSR(PSEUDO_ACCENTS_PREFIX, language, script,
*region == 0 ? "XA" : region, lsrFlags, errorCode);
} else if (uprv_strcmp(variant, "PSBIDI") == 0) {
return LSR(PSEUDO_BIDI_PREFIX, language, script,
*region == 0 ? "XB" : region, lsrFlags, errorCode);
} else if (uprv_strcmp(variant, "PSCRACK") == 0) {
return LSR(PSEUDO_CRACKED_PREFIX, language, script,
*region == 0 ? "XC" : region, lsrFlags, errorCode);
if (variant[0] == 'P' && variant[1] == 'S') {
int32_t lsrFlags = *region == 0 ?
LSR::EXPLICIT_LANGUAGE | LSR::EXPLICIT_SCRIPT : LSR::EXPLICIT_LSR;
if (uprv_strcmp(variant, "PSACCENT") == 0) {
return LSR(PSEUDO_ACCENTS_PREFIX, language, script,
*region == 0 ? "XA" : region, lsrFlags, errorCode);
} else if (uprv_strcmp(variant, "PSBIDI") == 0) {
return LSR(PSEUDO_BIDI_PREFIX, language, script,
*region == 0 ? "XB" : region, lsrFlags, errorCode);
} else if (uprv_strcmp(variant, "PSCRACK") == 0) {
return LSR(PSEUDO_CRACKED_PREFIX, language, script,
*region == 0 ? "XC" : region, lsrFlags, errorCode);
}
// else normal locale
}
// else normal locale
}
} // end of if (!returnInputIfUnmatch)
language = getCanonical(languageAliases, language);
// (We have no script mappings.)
@ -616,9 +609,9 @@ LSR LikelySubtags::maximize(const char *language, const char *script, const char
bool returnInputIfUnmatch,
UErrorCode &errorCode) const {
if (U_FAILURE(errorCode)) { return {}; }
return maximize({language, (int32_t)uprv_strlen(language)},
{script, (int32_t)uprv_strlen(script)},
{region, (int32_t)uprv_strlen(region)},
return maximize({language, static_cast<int32_t>(uprv_strlen(language))},
{script, static_cast<int32_t>(uprv_strlen(script))},
{region, static_cast<int32_t>(uprv_strlen(region))},
returnInputIfUnmatch,
errorCode);
}

View file

@ -979,7 +979,7 @@ getHostID(const ILcidPosixMap *this_0, const char* posixID, UErrorCode& status)
if (U_FAILURE(status)) { return locmap_root->hostID; }
int32_t bestIdx = 0;
int32_t bestIdxDiff = 0;
int32_t posixIDlen = (int32_t)uprv_strlen(posixID);
int32_t posixIDlen = static_cast<int32_t>(uprv_strlen(posixID));
uint32_t idx;
for (idx = 0; idx < this_0->numRegions; idx++ ) {

View file

@ -171,7 +171,7 @@ LocaleUtility::initLocaleFromName(const UnicodeString& id, Locale& result)
prev = 0;
UErrorCode status = U_ZERO_ERROR;
do {
i = id.indexOf((char16_t)0x40, prev);
i = id.indexOf(static_cast<char16_t>(0x40), prev);
if(i < 0) {
// no @ between prev and the rest of the string
buffer.appendInvariantChars(id.tempSubString(prev), status);
@ -224,7 +224,7 @@ LocaleUtility::getAvailableLocaleNames(const UnicodeString& bundleID)
Hashtable* htp;
umtx_lock(nullptr);
htp = (Hashtable*) cache->get(bundleID);
htp = static_cast<Hashtable*>(cache->get(bundleID));
umtx_unlock(nullptr);
if (htp == nullptr) {

View file

@ -164,7 +164,7 @@ public:
Array1D() : memory_(nullptr), data_(nullptr), d1_(0) {}
Array1D(int32_t d1, UErrorCode &status)
: memory_(uprv_malloc(d1 * sizeof(float))),
data_((float*)memory_), d1_(d1) {
data_(static_cast<float*>(memory_)), d1_(d1) {
if (U_SUCCESS(status)) {
if (memory_ == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
@ -301,7 +301,7 @@ public:
Array2D() : memory_(nullptr), data_(nullptr), d1_(0), d2_(0) {}
Array2D(int32_t d1, int32_t d2, UErrorCode &status)
: memory_(uprv_malloc(d1 * d2 * sizeof(float))),
data_((float*)memory_), d1_(d1), d2_(d2) {
data_(static_cast<float*>(memory_)), d1_(d1), d2_(d2) {
if (U_SUCCESS(status)) {
if (memory_ == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
@ -526,11 +526,11 @@ void CodePointsVectorizer::vectorize(
int32_t current;
char16_t str[2] = {0, 0};
while (U_SUCCESS(status) &&
(current = (int32_t)utext_getNativeIndex(text)) < endPos) {
(current = static_cast<int32_t>(utext_getNativeIndex(text))) < endPos) {
// Since the LSTMBreakEngine is currently only accept chars in BMP,
// we can ignore the possibility of hitting supplementary code
// point.
str[0] = (char16_t) utext_next32(text);
str[0] = static_cast<char16_t>(utext_next32(text));
U_ASSERT(!U_IS_SURROGATE(str[0]));
offsets.addElement(current, status);
indices.addElement(stringToIndex(str), status);
@ -733,7 +733,7 @@ LSTMBreakEngine::divideUpDictionaryRange( UText *text,
#endif // LSTM_DEBUG
// current = argmax(logp)
LSTMClass current = (LSTMClass)logp.maxIndex();
LSTMClass current = static_cast<LSTMClass>(logp.maxIndex());
// BIES logic.
if (current == BEGIN || current == SINGLE) {
if (i != 0) {

View file

@ -351,7 +351,7 @@ MessagePattern::autoQuoteApostropheDeep() const {
for(int32_t i=count; i>0;) {
const Part &part=getPart(--i);
if(part.getType()==UMSGPAT_PART_TYPE_INSERT_CHAR) {
modified.insert(part.index, (char16_t)part.value);
modified.insert(part.index, static_cast<char16_t>(part.value));
}
}
return modified;
@ -437,7 +437,7 @@ MessagePattern::parseMessage(int32_t index, int32_t msgStartLength,
if(U_FAILURE(errorCode)) {
return 0;
}
if(nestingLevel>Part::MAX_VALUE) {
if(nestingLevel>Part::MAX_NESTED_LEVELS) {
errorCode=U_INDEX_OUTOFBOUNDS_ERROR;
return 0;
}
@ -628,7 +628,7 @@ MessagePattern::parseArg(int32_t index, int32_t argStartLength, int32_t nestingL
}
}
// change the ARG_START type from NONE to argType
partsList->a[argStart].value=(int16_t)argType;
partsList->a[argStart].value = static_cast<int16_t>(argType);
if(argType==UMSGPAT_ARG_TYPE_SIMPLE) {
addPart(UMSGPAT_PART_TYPE_ARG_TYPE, typeIndex, length, 0, errorCode);
}
@ -980,13 +980,13 @@ MessagePattern::parseDouble(int32_t start, int32_t limit, UBool allowInfinity,
}
// Let Double.parseDouble() throw a NumberFormatException.
char numberChars[128];
int32_t capacity=(int32_t)sizeof(numberChars);
int32_t capacity = static_cast<int32_t>(sizeof(numberChars));
int32_t length=limit-start;
if(length>=capacity) {
break; // number too long
}
msg.extract(start, length, numberChars, capacity, US_INV);
if((int32_t)uprv_strlen(numberChars)<length) {
if (static_cast<int32_t>(uprv_strlen(numberChars)) < length) {
break; // contains non-invariant character that was turned into NUL
}
char *end;
@ -1006,7 +1006,7 @@ MessagePattern::skipWhiteSpace(int32_t index) {
const char16_t *s=msg.getBuffer();
int32_t msgLength=msg.length();
const char16_t *t=PatternProps::skipWhiteSpace(s+index, msgLength-index);
return (int32_t)(t-s);
return static_cast<int32_t>(t - s);
}
int32_t
@ -1014,7 +1014,7 @@ MessagePattern::skipIdentifier(int32_t index) {
const char16_t *s=msg.getBuffer();
int32_t msgLength=msg.length();
const char16_t *t=PatternProps::skipIdentifier(s+index, msgLength-index);
return (int32_t)(t-s);
return static_cast<int32_t>(t - s);
}
int32_t
@ -1105,8 +1105,8 @@ MessagePattern::addPart(UMessagePatternPartType type, int32_t index, int32_t len
Part &part=partsList->a[partsLength++];
part.type=type;
part.index=index;
part.length=(uint16_t)length;
part.value=(int16_t)value;
part.length = static_cast<uint16_t>(length);
part.value = static_cast<int16_t>(value);
part.limitPartIndex=0;
}
}

View file

@ -57,12 +57,12 @@ int32_t MlBreakEngine::divideUpRange(UText *inText, int32_t rangeStart, int32_t
// moving forward, finally the last six values in the indexList are
// [length-4, length-3, length-2, length-1, -1, -1]. The "+4" here means four extra "-1".
int32_t indexSize = codePointLength + 4;
int32_t *indexList = (int32_t *)uprv_malloc(indexSize * sizeof(int32_t));
if (indexList == nullptr) {
LocalMemory<int32_t> indexList(static_cast<int32_t*>(uprv_malloc(indexSize * sizeof(int32_t))));
if (indexList.isNull()) {
status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
int32_t numCodeUnits = initIndexList(inString, indexList, status);
int32_t numCodeUnits = initIndexList(inString, indexList.getAlias(), status);
// Add a break for the start.
boundary.addElement(0, status);
@ -71,13 +71,12 @@ int32_t MlBreakEngine::divideUpRange(UText *inText, int32_t rangeStart, int32_t
for (int32_t idx = 0; idx + 1 < codePointLength && U_SUCCESS(status); idx++) {
numBreaks =
evaluateBreakpoint(inString, indexList, idx, numCodeUnits, numBreaks, boundary, status);
evaluateBreakpoint(inString, indexList.getAlias(), idx, numCodeUnits, numBreaks, boundary, status);
if (idx + 4 < codePointLength) {
indexList[idx + 6] = numCodeUnits;
numCodeUnits += U16_LENGTH(inString.char32At(indexList[idx + 6]));
}
}
uprv_free(indexList);
if (U_FAILURE(status)) return 0;

File diff suppressed because it is too large Load diff

View file

@ -174,7 +174,7 @@ public:
errorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
return (int32_t)(spanQuickCheckYes(sArray, sArray+s.length(), errorCode)-sArray);
return static_cast<int32_t>(spanQuickCheckYes(sArray, sArray + s.length(), errorCode) - sArray);
}
virtual const char16_t *
spanQuickCheckYes(const char16_t *src, const char16_t *limit, UErrorCode &errorCode) const = 0;

View file

@ -380,8 +380,8 @@ normalizeSecondAndAppend(const UNormalizer2 *norm2,
firstLength=firstString.length(); // In case it was -1.
// secondLength==0: Nothing to do, and n2wi->normalizeAndAppend(nullptr, nullptr, buffer, ...) would crash.
if(secondLength!=0) {
const Normalizer2 *n2=(const Normalizer2 *)norm2;
const Normalizer2WithImpl *n2wi=dynamic_cast<const Normalizer2WithImpl *>(n2);
const Normalizer2* n2 = reinterpret_cast<const Normalizer2*>(norm2);
const Normalizer2WithImpl* n2wi = dynamic_cast<const Normalizer2WithImpl*>(n2);
if(n2wi!=nullptr) {
// Avoid duplicate argument checking and support NUL-terminated src.
UnicodeString safeMiddle;

View file

@ -53,9 +53,9 @@ namespace {
*/
inline uint8_t leadByteForCP(UChar32 c) {
if (c <= 0x7f) {
return (uint8_t)c;
return static_cast<uint8_t>(c);
} else if (c <= 0x7ff) {
return (uint8_t)(0xc0+(c>>6));
return static_cast<uint8_t>(0xc0 + (c >> 6));
} else {
// Should not occur because ccc(U+0300)!=0.
return 0xe0;
@ -82,7 +82,7 @@ UChar32 codePointFromValidUTF8(const uint8_t *cpStart, const uint8_t *cpLimit) {
return ((c&0x1f)<<6) | (cpStart[1]&0x3f);
case 3:
// no need for (c&0xf) because the upper bits are truncated after <<12 in the cast to (char16_t)
return (char16_t)((c<<12) | ((cpStart[1]&0x3f)<<6) | (cpStart[2]&0x3f));
return static_cast<char16_t>((c << 12) | ((cpStart[1] & 0x3f) << 6) | (cpStart[2] & 0x3f));
case 4:
return ((c&7)<<18) | ((cpStart[1]&0x3f)<<12) | ((cpStart[2]&0x3f)<<6) | (cpStart[3]&0x3f);
default:
@ -100,8 +100,8 @@ UChar32 previousHangulOrJamo(const uint8_t *start, const uint8_t *p) {
uint8_t l = *p;
uint8_t t1, t2;
if (0xe1 <= l && l <= 0xed &&
(t1 = (uint8_t)(p[1] - 0x80)) <= 0x3f &&
(t2 = (uint8_t)(p[2] - 0x80)) <= 0x3f &&
(t1 = static_cast<uint8_t>(p[1] - 0x80)) <= 0x3f &&
(t2 = static_cast<uint8_t>(p[2] - 0x80)) <= 0x3f &&
(l < 0xed || t1 <= 0x1f)) {
return ((l & 0xf) << 12) | (t1 << 6) | t2;
}
@ -125,7 +125,7 @@ int32_t getJamoTMinusBase(const uint8_t *src, const uint8_t *limit) {
}
} else if (src[1] == 0x87) {
uint8_t t = src[2];
if ((int8_t)t <= (int8_t)0x82u) {
if (static_cast<int8_t>(t) <= static_cast<int8_t>(0x82u)) {
return t - (0xa7 - 0x40);
}
}
@ -138,10 +138,10 @@ appendCodePointDelta(const uint8_t *cpStart, const uint8_t *cpLimit, int32_t del
ByteSink &sink, Edits *edits) {
char buffer[U8_MAX_LENGTH];
int32_t length;
int32_t cpLength = (int32_t)(cpLimit - cpStart);
int32_t cpLength = static_cast<int32_t>(cpLimit - cpStart);
if (cpLength == 1) {
// The builder makes ASCII map to ASCII.
buffer[0] = (uint8_t)(*cpStart + delta);
buffer[0] = static_cast<uint8_t>(*cpStart + delta);
length = 1;
} else {
int32_t trail = *(cpLimit-1) + delta;
@ -150,7 +150,7 @@ appendCodePointDelta(const uint8_t *cpStart, const uint8_t *cpLimit, int32_t del
--cpLimit;
length = 0;
do { buffer[length++] = *cpStart++; } while (cpStart < cpLimit);
buffer[length++] = (uint8_t)trail;
buffer[length++] = static_cast<uint8_t>(trail);
} else {
// Decode the code point, add the delta, re-encode.
UChar32 c = codePointFromValidUTF8(cpStart, cpLimit) + delta;
@ -205,16 +205,16 @@ UBool ReorderingBuffer::init(int32_t destCapacity, UErrorCode &errorCode) {
}
UBool ReorderingBuffer::equals(const char16_t *otherStart, const char16_t *otherLimit) const {
int32_t length=(int32_t)(limit-start);
int32_t length = static_cast<int32_t>(limit - start);
return
length==(int32_t)(otherLimit-otherStart) &&
length == static_cast<int32_t>(otherLimit - otherStart) &&
0==u_memcmp(start, otherStart, length);
}
UBool ReorderingBuffer::equals(const uint8_t *otherStart, const uint8_t *otherLimit) const {
U_ASSERT((otherLimit - otherStart) <= INT32_MAX); // ensured by caller
int32_t length = (int32_t)(limit - start);
int32_t otherLength = (int32_t)(otherLimit - otherStart);
int32_t length = static_cast<int32_t>(limit - start);
int32_t otherLength = static_cast<int32_t>(otherLimit - otherStart);
// For equal strings, UTF-8 is at least as long as UTF-16, and at most three times as long.
if (otherLength < length || (otherLength / 3) > length) {
return false;
@ -284,7 +284,7 @@ UBool ReorderingBuffer::append(const char16_t *s, int32_t length, UBool isNFD,
U16_NEXT(s, i, length, c);
if(i<length) {
if (isNFD) {
leadCC = Normalizer2Impl::getCCFromYesOrMaybe(impl.getRawNorm16(c));
leadCC = Normalizer2Impl::getCCFromYesOrMaybeYes(impl.getRawNorm16(c));
} else {
leadCC = impl.getCC(impl.getNorm16(c));
}
@ -304,7 +304,7 @@ UBool ReorderingBuffer::appendZeroCC(UChar32 c, UErrorCode &errorCode) {
}
remainingCapacity-=cpLength;
if(cpLength==1) {
*limit++=(char16_t)c;
*limit++ = static_cast<char16_t>(c);
} else {
limit[0]=U16_LEAD(c);
limit[1]=U16_TRAIL(c);
@ -319,7 +319,7 @@ UBool ReorderingBuffer::appendZeroCC(const char16_t *s, const char16_t *sLimit,
if(s==sLimit) {
return true;
}
int32_t length=(int32_t)(sLimit-s);
int32_t length = static_cast<int32_t>(sLimit - s);
if(remainingCapacity<length && !resize(length, errorCode)) {
return false;
}
@ -350,8 +350,8 @@ void ReorderingBuffer::removeSuffix(int32_t suffixLength) {
}
UBool ReorderingBuffer::resize(int32_t appendLength, UErrorCode &errorCode) {
int32_t reorderStartIndex=(int32_t)(reorderStart-start);
int32_t length=(int32_t)(limit-start);
int32_t reorderStartIndex = static_cast<int32_t>(reorderStart - start);
int32_t length = static_cast<int32_t>(limit - start);
str.releaseBuffer(length);
int32_t newCapacity=length+appendLength;
int32_t doubleCapacity=2*str.getCapacity();
@ -392,7 +392,7 @@ uint8_t ReorderingBuffer::previousCC() {
--codePointStart;
c=U16_GET_SUPPLEMENTARY(c2, c);
}
return impl.getCCFromYesOrMaybeCP(c);
return impl.getCCFromYesOrMaybeYesCP(c);
}
// Inserts c somewhere before the last character.
@ -440,15 +440,14 @@ Normalizer2Impl::init(const int32_t *inIndexes, const UCPTrie *inTrie,
minNoNoCompNoMaybeCC = static_cast<uint16_t>(inIndexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC]);
minNoNoEmpty = static_cast<uint16_t>(inIndexes[IX_MIN_NO_NO_EMPTY]);
limitNoNo = static_cast<uint16_t>(inIndexes[IX_LIMIT_NO_NO]);
minMaybeNo = static_cast<uint16_t>(inIndexes[IX_MIN_MAYBE_NO]);
minMaybeNoCombinesFwd = static_cast<uint16_t>(inIndexes[IX_MIN_MAYBE_NO_COMBINES_FWD]);
minMaybeYes = static_cast<uint16_t>(inIndexes[IX_MIN_MAYBE_YES]);
U_ASSERT((minMaybeYes & 7) == 0); // 8-aligned for noNoDelta bit fields
centerNoNoDelta = (minMaybeYes >> DELTA_SHIFT) - MAX_DELTA - 1;
U_ASSERT((minMaybeNo & 7) == 0); // 8-aligned for noNoDelta bit fields
centerNoNoDelta = (minMaybeNo >> DELTA_SHIFT) - MAX_DELTA - 1;
normTrie=inTrie;
maybeYesCompositions=inExtraData;
extraData=maybeYesCompositions+((MIN_NORMAL_MAYBE_YES-minMaybeYes)>>OFFSET_SHIFT);
extraData=inExtraData;
smallFCD=inSmallFCD;
}
@ -486,7 +485,7 @@ Normalizer2Impl::addPropertyStarts(const USetAdder *sa, UErrorCode & /*errorCode
while ((end = ucptrie_getRange(normTrie, start, UCPMAP_RANGE_FIXED_LEAD_SURROGATES, INERT,
nullptr, nullptr, &value)) >= 0) {
sa->add(sa->set, start);
if (start != end && isAlgorithmicNoNo((uint16_t)value) &&
if (start != end && isAlgorithmicNoNo(static_cast<uint16_t>(value)) &&
(value & Normalizer2Impl::DELTA_TCCC_MASK) > Normalizer2Impl::DELTA_TCCC_1) {
// Range of code points with same-norm16-value algorithmic decompositions.
// They might have different non-zero FCD16 values.
@ -570,7 +569,7 @@ Normalizer2Impl::decompose(const char16_t *src, const char16_t *limit,
int32_t destLengthEstimate,
UErrorCode &errorCode) const {
if(destLengthEstimate<0 && limit!=nullptr) {
destLengthEstimate=(int32_t)(limit-src);
destLengthEstimate = static_cast<int32_t>(limit - src);
}
dest.remove();
ReorderingBuffer buffer(*this, dest);
@ -650,7 +649,7 @@ Normalizer2Impl::decompose(const char16_t *src, const char16_t *limit,
}
} else {
if(isDecompYes(norm16)) {
uint8_t cc=getCCFromYesOrMaybe(norm16);
uint8_t cc=getCCFromYesOrMaybeYes(norm16);
if(prevCC<=cc || cc==0) {
prevCC=cc;
if(cc<=1) {
@ -702,12 +701,13 @@ UBool Normalizer2Impl::decompose(UChar32 c, uint16_t norm16,
UErrorCode &errorCode) const {
// get the decomposition and the lead and trail cc's
if (norm16 >= limitNoNo) {
if (isMaybeOrNonZeroCC(norm16)) {
return buffer.append(c, getCCFromYesOrMaybe(norm16), errorCode);
if (isMaybeYesOrNonZeroCC(norm16)) {
return buffer.append(c, getCCFromYesOrMaybeYes(norm16), errorCode);
} else if (norm16 < minMaybeNo) {
// Maps to an isCompYesAndZeroCC.
c=mapAlgorithmic(c, norm16);
norm16=getRawNorm16(c);
}
// Maps to an isCompYesAndZeroCC.
c=mapAlgorithmic(c, norm16);
norm16=getRawNorm16(c);
}
if (norm16 < minYesNo) {
// c does not decompose
@ -718,17 +718,17 @@ UBool Normalizer2Impl::decompose(UChar32 c, uint16_t norm16,
return buffer.appendZeroCC(jamos, jamos+Hangul::decompose(c, jamos), errorCode);
}
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16);
const uint16_t *mapping=getData(norm16);
uint16_t firstUnit=*mapping;
int32_t length=firstUnit&MAPPING_LENGTH_MASK;
uint8_t leadCC, trailCC;
trailCC=(uint8_t)(firstUnit>>8);
trailCC = static_cast<uint8_t>(firstUnit >> 8);
if(firstUnit&MAPPING_HAS_CCC_LCCC_WORD) {
leadCC=(uint8_t)(*(mapping-1)>>8);
leadCC = static_cast<uint8_t>(*(mapping - 1) >> 8);
} else {
leadCC=0;
}
return buffer.append((const char16_t *)mapping+1, length, true, leadCC, trailCC, errorCode);
return buffer.append(reinterpret_cast<const char16_t*>(mapping) + 1, length, true, leadCC, trailCC, errorCode);
}
// Dual functionality:
@ -787,9 +787,9 @@ Normalizer2Impl::decomposeUTF8(uint32_t options,
}
// Medium-fast path: Quick check.
if (isMaybeOrNonZeroCC(norm16)) {
if (isMaybeYesOrNonZeroCC(norm16)) {
// Does not decompose.
uint8_t cc = getCCFromYesOrMaybe(norm16);
uint8_t cc = getCCFromYesOrMaybeYes(norm16);
if (prevCC <= cc || cc == 0) {
prevCC = cc;
if (cc <= 1) {
@ -836,7 +836,7 @@ Normalizer2Impl::decomposeUTF8(uint32_t options,
}
// We already know there was a change if the original character decomposed;
// otherwise compare.
if (isMaybeOrNonZeroCC(norm16) && buffer.equals(prevBoundary, src)) {
if (isMaybeYesOrNonZeroCC(norm16) && buffer.equals(prevBoundary, src)) {
if (!ByteSinkUtil::appendUnchanged(prevBoundary, src,
*sink, options, edits, errorCode)) {
break;
@ -867,9 +867,9 @@ Normalizer2Impl::decomposeShort(const uint8_t *src, const uint8_t *limit,
// Get the decomposition and the lead and trail cc's.
UChar32 c = U_SENTINEL;
if (norm16 >= limitNoNo) {
if (isMaybeOrNonZeroCC(norm16)) {
if (isMaybeYesOrNonZeroCC(norm16)) {
// No comp boundaries around this character.
uint8_t cc = getCCFromYesOrMaybe(norm16);
uint8_t cc = getCCFromYesOrMaybeYes(norm16);
if (cc == 0 && stopAt == STOP_AT_DECOMP_BOUNDARY) {
return prevSrc;
}
@ -881,14 +881,15 @@ Normalizer2Impl::decomposeShort(const uint8_t *src, const uint8_t *limit,
return src;
}
continue;
} else if (norm16 < minMaybeNo) {
// Maps to an isCompYesAndZeroCC.
if (stopAt != STOP_AT_LIMIT) {
return prevSrc;
}
c = codePointFromValidUTF8(prevSrc, src);
c = mapAlgorithmic(c, norm16);
norm16 = getRawNorm16(c);
}
// Maps to an isCompYesAndZeroCC.
if (stopAt != STOP_AT_LIMIT) {
return prevSrc;
}
c = codePointFromValidUTF8(prevSrc, src);
c = mapAlgorithmic(c, norm16);
norm16 = getRawNorm16(c);
} else if (stopAt != STOP_AT_LIMIT && norm16 < minNoNoCompNoMaybeCC) {
return prevSrc;
}
@ -918,20 +919,20 @@ Normalizer2Impl::decomposeShort(const uint8_t *src, const uint8_t *limit,
}
} else {
// The character decomposes, get everything from the variable-length extra data.
const uint16_t *mapping = getMapping(norm16);
const uint16_t *mapping = getData(norm16);
uint16_t firstUnit = *mapping;
int32_t length = firstUnit & MAPPING_LENGTH_MASK;
uint8_t trailCC = (uint8_t)(firstUnit >> 8);
uint8_t trailCC = static_cast<uint8_t>(firstUnit >> 8);
uint8_t leadCC;
if (firstUnit & MAPPING_HAS_CCC_LCCC_WORD) {
leadCC = (uint8_t)(*(mapping-1) >> 8);
leadCC = static_cast<uint8_t>(*(mapping - 1) >> 8);
} else {
leadCC = 0;
}
if (leadCC == 0 && stopAt == STOP_AT_DECOMP_BOUNDARY) {
return prevSrc;
}
if (!buffer.append((const char16_t *)mapping+1, length, true, leadCC, trailCC, errorCode)) {
if (!buffer.append(reinterpret_cast<const char16_t*>(mapping) + 1, length, true, leadCC, trailCC, errorCode)) {
return nullptr;
}
}
@ -946,7 +947,7 @@ Normalizer2Impl::decomposeShort(const uint8_t *src, const uint8_t *limit,
const char16_t *
Normalizer2Impl::getDecomposition(UChar32 c, char16_t buffer[4], int32_t &length) const {
uint16_t norm16;
if(c<minDecompNoCP || isMaybeOrNonZeroCC(norm16=getNorm16(c))) {
if(c<minDecompNoCP || isMaybeYesOrNonZeroCC(norm16=getNorm16(c))) {
// c does not decompose
return nullptr;
}
@ -968,9 +969,9 @@ Normalizer2Impl::getDecomposition(UChar32 c, char16_t buffer[4], int32_t &length
return buffer;
}
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16);
const uint16_t *mapping=getData(norm16);
length=*mapping&MAPPING_LENGTH_MASK;
return (const char16_t *)mapping+1;
return reinterpret_cast<const char16_t*>(mapping) + 1;
}
// The capacity of the buffer must be 30=MAPPING_LENGTH_MASK-1
@ -995,7 +996,7 @@ Normalizer2Impl::getRawDecomposition(UChar32 c, char16_t buffer[30], int32_t &le
return buffer;
}
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16);
const uint16_t *mapping=getData(norm16);
uint16_t firstUnit=*mapping;
int32_t mLength=firstUnit&MAPPING_LENGTH_MASK; // length of normal mapping
if(firstUnit&MAPPING_HAS_RAW_MAPPING) {
@ -1005,17 +1006,17 @@ Normalizer2Impl::getRawDecomposition(UChar32 c, char16_t buffer[30], int32_t &le
uint16_t rm0=*rawMapping;
if(rm0<=MAPPING_LENGTH_MASK) {
length=rm0;
return (const char16_t *)rawMapping-rm0;
return reinterpret_cast<const char16_t*>(rawMapping) - rm0;
} else {
// Copy the normal mapping and replace its first two code units with rm0.
buffer[0]=(char16_t)rm0;
u_memcpy(buffer+1, (const char16_t *)mapping+1+2, mLength-2);
buffer[0] = static_cast<char16_t>(rm0);
u_memcpy(buffer + 1, reinterpret_cast<const char16_t*>(mapping) + 1 + 2, mLength - 2);
length=mLength-1;
return buffer;
}
} else {
length=mLength;
return (const char16_t *)mapping+1;
return reinterpret_cast<const char16_t*>(mapping) + 1;
}
}
@ -1052,7 +1053,7 @@ void Normalizer2Impl::decomposeAndAppend(const char16_t *src, const char16_t *li
limit=u_strchr(p, 0);
}
if (buffer.append(src, (int32_t)(p - src), false, firstCC, prevCC, errorCode)) {
if (buffer.append(src, static_cast<int32_t>(p - src), false, firstCC, prevCC, errorCode)) {
buffer.appendZeroCC(p, limit, errorCode);
}
}
@ -1070,7 +1071,7 @@ UBool Normalizer2Impl::norm16HasDecompBoundaryBefore(uint16_t norm16) const {
return norm16 <= MIN_NORMAL_MAYBE_YES || norm16 == JAMO_VT;
}
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16);
const uint16_t *mapping=getDataForYesOrNo(norm16);
uint16_t firstUnit=*mapping;
// true if leadCC==0 (hasFCDBoundaryBefore())
return (firstUnit&MAPPING_HAS_CCC_LCCC_WORD)==0 || (*(mapping-1)&0xff00)==0;
@ -1091,14 +1092,15 @@ UBool Normalizer2Impl::norm16HasDecompBoundaryAfter(uint16_t norm16) const {
return true;
}
if (norm16 >= limitNoNo) {
if (isMaybeOrNonZeroCC(norm16)) {
if (isMaybeYesOrNonZeroCC(norm16)) {
return norm16 <= MIN_NORMAL_MAYBE_YES || norm16 == JAMO_VT;
} else if (norm16 < minMaybeNo) {
// Maps to an isCompYesAndZeroCC.
return (norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1;
}
// Maps to an isCompYesAndZeroCC.
return (norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1;
}
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16);
const uint16_t *mapping=getData(norm16);
uint16_t firstUnit=*mapping;
// decomp after-boundary: same as hasFCDBoundaryAfter(),
// fcd16<=1 || trailCC==0
@ -1140,13 +1142,13 @@ int32_t Normalizer2Impl::combine(const uint16_t *list, UChar32 trail) {
if(trail<COMP_1_TRAIL_LIMIT) {
// trail character is 0..33FF
// result entry may have 2 or 3 units
key1=(uint16_t)(trail<<1);
key1 = static_cast<uint16_t>(trail << 1);
while(key1>(firstUnit=*list)) {
list+=2+(firstUnit&COMP_1_TRIPLE);
}
if(key1==(firstUnit&COMP_1_TRAIL_MASK)) {
if(firstUnit&COMP_1_TRIPLE) {
return ((int32_t)list[1]<<16)|list[2];
return (static_cast<int32_t>(list[1]) << 16) | list[2];
} else {
return list[1];
}
@ -1154,10 +1156,10 @@ int32_t Normalizer2Impl::combine(const uint16_t *list, UChar32 trail) {
} else {
// trail character is 3400..10FFFF
// result entry has 3 units
key1=(uint16_t)(COMP_1_TRAIL_LIMIT+
key1 = static_cast<uint16_t>(COMP_1_TRAIL_LIMIT +
(((trail>>COMP_1_TRAIL_SHIFT))&
~COMP_1_TRIPLE));
uint16_t key2=(uint16_t)(trail<<COMP_2_TRAIL_SHIFT);
uint16_t key2 = static_cast<uint16_t>(trail << COMP_2_TRAIL_SHIFT);
uint16_t secondUnit;
for(;;) {
if(key1>(firstUnit=*list)) {
@ -1170,7 +1172,7 @@ int32_t Normalizer2Impl::combine(const uint16_t *list, UChar32 trail) {
list+=3;
}
} else if(key2==(secondUnit&COMP_2_TRAIL_MASK)) {
return ((int32_t)(secondUnit&~COMP_2_TRAIL_MASK)<<16)|list[2];
return (static_cast<int32_t>(secondUnit & ~COMP_2_TRAIL_MASK) << 16) | list[2];
} else {
break;
}
@ -1195,7 +1197,7 @@ void Normalizer2Impl::addComposites(const uint16_t *list, UnicodeSet &set) const
compositeAndFwd=list[1];
list+=2;
} else {
compositeAndFwd=(((int32_t)list[1]&~COMP_2_TRAIL_MASK)<<16)|list[2];
compositeAndFwd = ((static_cast<int32_t>(list[1]) & ~COMP_2_TRAIL_MASK) << 16) | list[2];
list+=3;
}
UChar32 composite=compositeAndFwd>>1;
@ -1240,7 +1242,7 @@ void Normalizer2Impl::recompose(ReorderingBuffer &buffer, int32_t recomposeStart
for(;;) {
UCPTRIE_FAST_U16_NEXT(normTrie, UCPTRIE_16, p, limit, c, norm16);
cc=getCCFromYesOrMaybe(norm16);
cc=getCCFromYesOrMaybeYes(norm16);
if( // this character combines backward and
isMaybe(norm16) &&
// we have seen a starter that combines forward and
@ -1252,15 +1254,15 @@ void Normalizer2Impl::recompose(ReorderingBuffer &buffer, int32_t recomposeStart
// c is a Jamo V/T, see if we can compose it with the previous character.
if(c<Hangul::JAMO_T_BASE) {
// c is a Jamo Vowel, compose with previous Jamo L and following Jamo T.
char16_t prev=(char16_t)(*starter-Hangul::JAMO_L_BASE);
char16_t prev = static_cast<char16_t>(*starter - Hangul::JAMO_L_BASE);
if(prev<Hangul::JAMO_L_COUNT) {
pRemove=p-1;
char16_t syllable=(char16_t)
(Hangul::HANGUL_BASE+
char16_t syllable = static_cast<char16_t>(
Hangul::HANGUL_BASE +
(prev*Hangul::JAMO_V_COUNT+(c-Hangul::JAMO_V_BASE))*
Hangul::JAMO_T_COUNT);
char16_t t;
if(p!=limit && (t=(char16_t)(*p-Hangul::JAMO_T_BASE))<Hangul::JAMO_T_COUNT) {
if (p != limit && (t = static_cast<char16_t>(*p - Hangul::JAMO_T_BASE)) < Hangul::JAMO_T_COUNT) {
++p;
syllable+=t; // The next character was a Jamo T.
}
@ -1298,7 +1300,7 @@ void Normalizer2Impl::recompose(ReorderingBuffer &buffer, int32_t recomposeStart
starter[0]=U16_LEAD(composite);
starter[1]=U16_TRAIL(composite);
} else {
*starter=(char16_t)composite;
*starter = static_cast<char16_t>(composite);
// The composite is shorter than the starter,
// move the intermediate characters forward one.
starterIsSupplementary=false;
@ -1323,7 +1325,7 @@ void Normalizer2Impl::recompose(ReorderingBuffer &buffer, int32_t recomposeStart
*--starter=U16_LEAD(composite); // undo the temporary increment
} else {
// both are on the BMP
*starter=(char16_t)composite;
*starter = static_cast<char16_t>(composite);
}
/* remove the combining mark by moving the following text over it */
@ -1414,17 +1416,22 @@ Normalizer2Impl::composePair(UChar32 a, UChar32 b) const {
}
} else {
// 'a' has a compositions list in extraData
list=getMapping(norm16);
list=getDataForYesOrNo(norm16);
if(norm16>minYesNo) { // composite 'a' has both mapping & compositions list
list+= // mapping pointer
1+ // +1 to skip the first unit with the mapping length
(*list&MAPPING_LENGTH_MASK); // + mapping length
}
}
} else if(norm16<minMaybeYes || MIN_NORMAL_MAYBE_YES<=norm16) {
} else if(norm16<minMaybeNoCombinesFwd || MIN_NORMAL_MAYBE_YES<=norm16) {
return U_SENTINEL;
} else {
list=getCompositionsListForMaybe(norm16);
list=getDataForMaybe(norm16);
if(norm16<minMaybeYes) { // composite 'a' has both mapping & compositions list
list+= // mapping pointer
1+ // +1 to skip the first unit with the mapping length
(*list&MAPPING_LENGTH_MASK); // + mapping length
}
}
if(b<0 || 0x10ffff<b) { // combine(list, b) requires a valid code point b
return U_SENTINEL;
@ -1502,12 +1509,12 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
}
// isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo.
// The current character is either a "noNo" (has a mapping)
// or a "maybeYes" (combines backward)
// or a "maybeYes" / "maybeNo" (combines backward)
// or a "yesYes" with ccc!=0.
// It is not a Hangul syllable or Jamo L because those have "yes" properties.
// Medium-fast path: Handle cases that do not require full decomposition and recomposition.
if (!isMaybeOrNonZeroCC(norm16)) { // minNoNo <= norm16 < minMaybeYes
if (norm16 < minMaybeNo) { // minNoNo <= norm16 < minMaybeNo
if (!doCompose) {
return false;
}
@ -1534,7 +1541,7 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) {
break;
}
const char16_t *mapping = reinterpret_cast<const char16_t *>(getMapping(norm16));
const char16_t *mapping = reinterpret_cast<const char16_t *>(getDataForYesOrNo(norm16));
int32_t length = *mapping++ & MAPPING_LENGTH_MASK;
if(!buffer.appendZeroCC(mapping, mapping + length, errorCode)) {
break;
@ -1562,14 +1569,14 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
if(c<Hangul::JAMO_T_BASE) {
// The current character is a Jamo Vowel,
// compose with previous Jamo L and following Jamo T.
char16_t l = (char16_t)(prev-Hangul::JAMO_L_BASE);
char16_t l = static_cast<char16_t>(prev - Hangul::JAMO_L_BASE);
if(l<Hangul::JAMO_L_COUNT) {
if (!doCompose) {
return false;
}
int32_t t;
if (src != limit &&
0 < (t = ((int32_t)*src - Hangul::JAMO_T_BASE)) &&
0 < (t = (static_cast<int32_t>(*src) - Hangul::JAMO_T_BASE)) &&
t < Hangul::JAMO_T_COUNT) {
// The next character is a Jamo T.
++src;
@ -1587,7 +1594,7 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) {
break;
}
if(!buffer.appendBMP((char16_t)syllable, 0, errorCode)) {
if (!buffer.appendBMP(static_cast<char16_t>(syllable), 0, errorCode)) {
break;
}
prevBoundary = src;
@ -1612,7 +1619,7 @@ Normalizer2Impl::compose(const char16_t *src, const char16_t *limit,
if (prevBoundary != prevSrc && !buffer.appendZeroCC(prevBoundary, prevSrc, errorCode)) {
break;
}
if(!buffer.appendBMP((char16_t)syllable, 0, errorCode)) {
if (!buffer.appendBMP(static_cast<char16_t>(syllable), 0, errorCode)) {
break;
}
prevBoundary = src;
@ -1763,7 +1770,7 @@ Normalizer2Impl::composeQuickCheck(const char16_t *src, const char16_t *limit,
}
// isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo.
// The current character is either a "noNo" (has a mapping)
// or a "maybeYes" (combines backward)
// or a "maybeYes" / "maybeNo" (combines backward)
// or a "yesYes" with ccc!=0.
// It is not a Hangul syllable or Jamo L because those have "yes" properties.
@ -1784,8 +1791,9 @@ Normalizer2Impl::composeQuickCheck(const char16_t *src, const char16_t *limit,
}
}
if(isMaybeOrNonZeroCC(norm16)) {
uint8_t cc=getCCFromYesOrMaybe(norm16);
if (norm16 >= minMaybeNo) {
uint16_t fcd16 = getFCD16FromMaybeOrNonZeroCC(norm16);
uint8_t cc = fcd16 >> 8;
if (onlyContiguous /* FCC */ && cc != 0 &&
getTrailCCFromCompYesAndZeroCC(prevNorm16) > cc) {
// The [prevBoundary..prevSrc[ character
@ -1806,11 +1814,12 @@ Normalizer2Impl::composeQuickCheck(const char16_t *src, const char16_t *limit,
if (src == limit) {
return src;
}
uint8_t prevCC = cc;
uint8_t prevCC = fcd16;
nextSrc = src;
UCPTRIE_FAST_U16_NEXT(normTrie, UCPTRIE_16, nextSrc, limit, c, norm16);
if (isMaybeOrNonZeroCC(norm16)) {
cc = getCCFromYesOrMaybe(norm16);
if (norm16 >= minMaybeNo) {
fcd16 = getFCD16FromMaybeOrNonZeroCC(norm16);
cc = fcd16 >> 8;
if (!(prevCC <= cc || cc == 0)) {
break;
}
@ -1845,11 +1854,11 @@ void Normalizer2Impl::composeAndAppend(const char16_t *src, const char16_t *limi
if(src!=firstStarterInSrc) {
const char16_t *lastStarterInDest=findPreviousCompBoundary(buffer.getStart(),
buffer.getLimit(), onlyContiguous);
int32_t destSuffixLength=(int32_t)(buffer.getLimit()-lastStarterInDest);
int32_t destSuffixLength = static_cast<int32_t>(buffer.getLimit() - lastStarterInDest);
UnicodeString middle(lastStarterInDest, destSuffixLength);
buffer.removeSuffix(destSuffixLength);
safeMiddle=middle;
middle.append(src, (int32_t)(firstStarterInSrc-src));
middle.append(src, static_cast<int32_t>(firstStarterInSrc - src));
const char16_t *middleStart=middle.getBuffer();
compose(middleStart, middleStart+middle.length(), onlyContiguous,
true, buffer, errorCode);
@ -1903,12 +1912,12 @@ Normalizer2Impl::composeUTF8(uint32_t options, UBool onlyContiguous,
}
// isCompYesAndZeroCC(norm16) is false, that is, norm16>=minNoNo.
// The current character is either a "noNo" (has a mapping)
// or a "maybeYes" (combines backward)
// or a "maybeYes" / "maybeNo" (combines backward)
// or a "yesYes" with ccc!=0.
// It is not a Hangul syllable or Jamo L because those have "yes" properties.
// Medium-fast path: Handle cases that do not require full decomposition and recomposition.
if (!isMaybeOrNonZeroCC(norm16)) { // minNoNo <= norm16 < minMaybeYes
if (norm16 < minMaybeNo) { // minNoNo <= norm16 < minMaybeNo
if (sink == nullptr) {
return false;
}
@ -1937,9 +1946,9 @@ Normalizer2Impl::composeUTF8(uint32_t options, UBool onlyContiguous,
*sink, options, edits, errorCode)) {
break;
}
const uint16_t *mapping = getMapping(norm16);
const uint16_t *mapping = getDataForYesOrNo(norm16);
int32_t length = *mapping++ & MAPPING_LENGTH_MASK;
if (!ByteSinkUtil::appendChange(prevSrc, src, (const char16_t *)mapping, length,
if (!ByteSinkUtil::appendChange(prevSrc, src, reinterpret_cast<const char16_t*>(mapping), length,
*sink, edits, errorCode)) {
break;
}
@ -1958,7 +1967,7 @@ Normalizer2Impl::composeUTF8(uint32_t options, UBool onlyContiguous,
break;
}
if (edits != nullptr) {
edits->addReplace((int32_t)(src - prevSrc), 0);
edits->addReplace(static_cast<int32_t>(src - prevSrc), 0);
}
prevBoundary = src;
continue;
@ -1976,7 +1985,7 @@ Normalizer2Impl::composeUTF8(uint32_t options, UBool onlyContiguous,
// The current character is a Jamo Vowel,
// compose with previous Jamo L and following Jamo T.
UChar32 l = prev - Hangul::JAMO_L_BASE;
if ((uint32_t)l < Hangul::JAMO_L_COUNT) {
if (static_cast<uint32_t>(l) < Hangul::JAMO_L_COUNT) {
if (sink == nullptr) {
return false;
}
@ -2204,20 +2213,20 @@ uint8_t Normalizer2Impl::getPreviousTrailCC(const char16_t *start, const char16_
if (start == p) {
return 0;
}
int32_t i = (int32_t)(p - start);
int32_t i = static_cast<int32_t>(p - start);
UChar32 c;
U16_PREV(start, 0, i, c);
return (uint8_t)getFCD16(c);
return static_cast<uint8_t>(getFCD16(c));
}
uint8_t Normalizer2Impl::getPreviousTrailCC(const uint8_t *start, const uint8_t *p) const {
if (start == p) {
return 0;
}
int32_t i = (int32_t)(p - start);
int32_t i = static_cast<int32_t>(p - start);
UChar32 c;
U8_PREV(start, 0, i, c);
return (uint8_t)getFCD16(c);
return static_cast<uint8_t>(getFCD16(c));
}
// Note: normalizer2impl.cpp r30982 (2011-nov-27)
@ -2245,7 +2254,7 @@ uint16_t Normalizer2Impl::getFCD16FromNormData(UChar32 c) const {
return norm16|(norm16<<8);
} else if(norm16>=minMaybeYes) {
return 0;
} else { // isDecompNoAlgorithmic(norm16)
} else if(norm16<minMaybeNo) { // isDecompNoAlgorithmic(norm16)
uint16_t deltaTrailCC = norm16 & DELTA_TCCC_MASK;
if (deltaTrailCC <= DELTA_TCCC_1) {
return deltaTrailCC >> OFFSET_SHIFT;
@ -2260,7 +2269,7 @@ uint16_t Normalizer2Impl::getFCD16FromNormData(UChar32 c) const {
return 0;
}
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16);
const uint16_t *mapping=getData(norm16);
uint16_t firstUnit=*mapping;
norm16=firstUnit>>8; // tccc
if(firstUnit&MAPPING_HAS_CCC_LCCC_WORD) {
@ -2272,6 +2281,23 @@ uint16_t Normalizer2Impl::getFCD16FromNormData(UChar32 c) const {
#pragma optimize( "", on )
#endif
uint16_t Normalizer2Impl::getFCD16FromMaybeOrNonZeroCC(uint16_t norm16) const {
U_ASSERT(norm16 >= minMaybeNo);
if (norm16 >= MIN_NORMAL_MAYBE_YES) {
// combining mark
norm16 = getCCFromNormalYesOrMaybe(norm16);
return norm16 | (norm16<<8);
} else if (norm16 >= minMaybeYes) {
return 0;
}
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping = getDataForMaybe(norm16);
uint16_t firstUnit = *mapping;
// maybeNo has lccc = 0
U_ASSERT((firstUnit & MAPPING_HAS_CCC_LCCC_WORD) == 0 || (*(mapping - 1) & 0xff00) == 0);
return firstUnit >> 8; // tccc
}
// Dual functionality:
// buffer!=nullptr: normalize
// buffer==nullptr: isNormalized/quickCheck/spanQuickCheckYes
@ -2395,7 +2421,7 @@ Normalizer2Impl::makeFCD(const char16_t *src, const char16_t *limit,
* already but is now going to be decomposed.
* prevSrc is set to after what was copied/appended.
*/
buffer->removeSuffix((int32_t)(prevSrc-prevBoundary));
buffer->removeSuffix(static_cast<int32_t>(prevSrc - prevBoundary));
/*
* Find the part of the source that needs to be decomposed,
* up to the next safe boundary.
@ -2426,11 +2452,11 @@ void Normalizer2Impl::makeFCDAndAppend(const char16_t *src, const char16_t *limi
if(src!=firstBoundaryInSrc) {
const char16_t *lastBoundaryInDest=findPreviousFCDBoundary(buffer.getStart(),
buffer.getLimit());
int32_t destSuffixLength=(int32_t)(buffer.getLimit()-lastBoundaryInDest);
int32_t destSuffixLength = static_cast<int32_t>(buffer.getLimit() - lastBoundaryInDest);
UnicodeString middle(lastBoundaryInDest, destSuffixLength);
buffer.removeSuffix(destSuffixLength);
safeMiddle=middle;
middle.append(src, (int32_t)(firstBoundaryInSrc-src));
middle.append(src, static_cast<int32_t>(firstBoundaryInSrc - src));
const char16_t *middleStart=middle.getBuffer();
makeFCD(middleStart, middleStart+middle.length(), &buffer, errorCode);
if(U_FAILURE(errorCode)) {
@ -2507,8 +2533,8 @@ void CanonIterData::addToStartSet(UChar32 origin, UChar32 decompLead, UErrorCode
if(U_FAILURE(errorCode)) {
return;
}
UChar32 firstOrigin=(UChar32)(canonValue&CANON_VALUE_MASK);
canonValue=(canonValue&~CANON_VALUE_MASK)|CANON_HAS_SET|(uint32_t)canonStartSets.size();
UChar32 firstOrigin = static_cast<UChar32>(canonValue & CANON_VALUE_MASK);
canonValue = (canonValue & ~CANON_VALUE_MASK) | CANON_HAS_SET | static_cast<uint32_t>(canonStartSets.size());
umutablecptrie_set(mutableTrie, decompLead, canonValue, &errorCode);
canonStartSets.adoptElement(lpSet.orphan(), errorCode);
if (U_FAILURE(errorCode)) {
@ -2518,7 +2544,7 @@ void CanonIterData::addToStartSet(UChar32 origin, UChar32 decompLead, UErrorCode
set->add(firstOrigin);
}
} else {
set=(UnicodeSet *)canonStartSets[(int32_t)(canonValue&CANON_VALUE_MASK)];
set = static_cast<UnicodeSet*>(canonStartSets[static_cast<int32_t>(canonValue & CANON_VALUE_MASK)]);
}
set->add(origin);
}
@ -2575,9 +2601,11 @@ void InitCanonIterData::doInit(Normalizer2Impl *impl, UErrorCode &errorCode) {
void Normalizer2Impl::makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, const uint16_t norm16,
CanonIterData &newData,
UErrorCode &errorCode) const {
if(isInert(norm16) || (minYesNo<=norm16 && norm16<minNoNo)) {
if(isInert(norm16) ||
(minYesNo<=norm16 && norm16<minNoNo) ||
(minMaybeNo<=norm16 && norm16<minMaybeYes)) {
// Inert, or 2-way mapping (including Hangul syllable).
// We do not write a canonStartSet for any yesNo character.
// We do not write a canonStartSet for any yesNo/maybeNo character.
// Composites from 2-way mappings are added at runtime from the
// starter's compositions list, and the other characters in
// 2-way mappings get CANON_NOT_SEGMENT_STARTER set because they are
@ -2587,7 +2615,7 @@ void Normalizer2Impl::makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, co
for(UChar32 c=start; c<=end; ++c) {
uint32_t oldValue = umutablecptrie_get(newData.mutableTrie, c);
uint32_t newValue=oldValue;
if(isMaybeOrNonZeroCC(norm16)) {
if(isMaybeYesOrNonZeroCC(norm16)) {
// not a segment starter if it occurs in a decomposition or has cc!=0
newValue|=CANON_NOT_SEGMENT_STARTER;
if(norm16<MIN_NORMAL_MAYBE_YES) {
@ -2609,7 +2637,7 @@ void Normalizer2Impl::makeCanonIterDataFromNorm16(UChar32 start, UChar32 end, co
}
if (norm16_2 > minYesNo) {
// c decomposes, get everything from the variable-length extra data
const uint16_t *mapping=getMapping(norm16_2);
const uint16_t *mapping=getDataForYesOrNo(norm16_2);
uint16_t firstUnit=*mapping;
int32_t length=firstUnit&MAPPING_LENGTH_MASK;
if((firstUnit&MAPPING_HAS_CCC_LCCC_WORD)!=0) {
@ -2657,11 +2685,11 @@ UBool Normalizer2Impl::ensureCanonIterData(UErrorCode &errorCode) const {
}
int32_t Normalizer2Impl::getCanonValue(UChar32 c) const {
return (int32_t)ucptrie_get(fCanonIterData->trie, c);
return static_cast<int32_t>(ucptrie_get(fCanonIterData->trie, c));
}
const UnicodeSet &Normalizer2Impl::getCanonStartSet(int32_t n) const {
return *(const UnicodeSet *)fCanonIterData->canonStartSets[n];
return *static_cast<const UnicodeSet*>(fCanonIterData->canonStartSets[n]);
}
UBool Normalizer2Impl::isCanonSegmentStarter(UChar32 c) const {
@ -2684,7 +2712,7 @@ UBool Normalizer2Impl::getCanonStartSet(UChar32 c, UnicodeSet &set) const {
uint16_t norm16=getRawNorm16(c);
if(norm16==JAMO_L) {
UChar32 syllable=
(UChar32)(Hangul::HANGUL_BASE+(c-Hangul::JAMO_L_BASE)*Hangul::JAMO_VT_COUNT);
static_cast<UChar32>(Hangul::HANGUL_BASE + (c - Hangul::JAMO_L_BASE) * Hangul::JAMO_VT_COUNT);
set.add(syllable, syllable+Hangul::JAMO_VT_COUNT-1);
} else {
addComposites(getCompositionsList(norm16), set);
@ -2728,7 +2756,7 @@ unorm2_swap(const UDataSwapper *ds,
pInfo->dataFormat[1]==0x72 &&
pInfo->dataFormat[2]==0x6d &&
pInfo->dataFormat[3]==0x32 &&
(1<=formatVersion0 && formatVersion0<=4)
(1<=formatVersion0 && formatVersion0<=5)
)) {
udata_printError(ds, "unorm2_swap(): data format %02x.%02x.%02x.%02x (format version %02x) is not recognized as Normalizer2 data\n",
pInfo->dataFormat[0], pInfo->dataFormat[1],
@ -2747,8 +2775,10 @@ unorm2_swap(const UDataSwapper *ds,
minIndexesLength=Normalizer2Impl::IX_MIN_MAYBE_YES+1;
} else if(formatVersion0==2) {
minIndexesLength=Normalizer2Impl::IX_MIN_YES_NO_MAPPINGS_ONLY+1;
} else {
} else if(formatVersion0<=4) {
minIndexesLength=Normalizer2Impl::IX_MIN_LCCC_CP+1;
} else {
minIndexesLength=Normalizer2Impl::IX_MIN_MAYBE_NO_COMBINES_FWD+1;
}
if(length>=0) {

View file

@ -81,10 +81,10 @@ public:
return 0<=c && c<HANGUL_COUNT && c%JAMO_T_COUNT==0;
}
static inline UBool isJamoL(UChar32 c) {
return (uint32_t)(c-JAMO_L_BASE)<JAMO_L_COUNT;
return static_cast<uint32_t>(c - JAMO_L_BASE) < JAMO_L_COUNT;
}
static inline UBool isJamoV(UChar32 c) {
return (uint32_t)(c-JAMO_V_BASE)<JAMO_V_COUNT;
return static_cast<uint32_t>(c - JAMO_V_BASE) < JAMO_V_COUNT;
}
static inline UBool isJamoT(UChar32 c) {
int32_t t=c-JAMO_T_BASE;
@ -103,12 +103,12 @@ public:
c-=HANGUL_BASE;
UChar32 c2=c%JAMO_T_COUNT;
c/=JAMO_T_COUNT;
buffer[0]=(char16_t)(JAMO_L_BASE+c/JAMO_V_COUNT);
buffer[1]=(char16_t)(JAMO_V_BASE+c%JAMO_V_COUNT);
buffer[0] = static_cast<char16_t>(JAMO_L_BASE + c / JAMO_V_COUNT);
buffer[1] = static_cast<char16_t>(JAMO_V_BASE + c % JAMO_V_COUNT);
if(c2==0) {
return 2;
} else {
buffer[2]=(char16_t)(JAMO_T_BASE+c2);
buffer[2] = static_cast<char16_t>(JAMO_T_BASE + c2);
return 3;
}
}
@ -123,11 +123,11 @@ public:
UChar32 c2=c%JAMO_T_COUNT;
if(c2==0) {
c/=JAMO_T_COUNT;
buffer[0]=(char16_t)(JAMO_L_BASE+c/JAMO_V_COUNT);
buffer[1]=(char16_t)(JAMO_V_BASE+c%JAMO_V_COUNT);
buffer[0] = static_cast<char16_t>(JAMO_L_BASE + c / JAMO_V_COUNT);
buffer[1] = static_cast<char16_t>(JAMO_V_BASE + c % JAMO_V_COUNT);
} else {
buffer[0]=(char16_t)(orig-c2); // LV syllable
buffer[1]=(char16_t)(JAMO_T_BASE+c2);
buffer[0] = static_cast<char16_t>(orig - c2); // LV syllable
buffer[1] = static_cast<char16_t>(JAMO_T_BASE + c2);
}
}
private:
@ -147,13 +147,13 @@ public:
ReorderingBuffer(const Normalizer2Impl &ni, UnicodeString &dest, UErrorCode &errorCode);
~ReorderingBuffer() {
if (start != nullptr) {
str.releaseBuffer((int32_t)(limit-start));
str.releaseBuffer(static_cast<int32_t>(limit - start));
}
}
UBool init(int32_t destCapacity, UErrorCode &errorCode);
UBool isEmpty() const { return start==limit; }
int32_t length() const { return (int32_t)(limit-start); }
int32_t length() const { return static_cast<int32_t>(limit - start); }
char16_t *getStart() { return start; }
char16_t *getLimit() { return limit; }
uint8_t getLastCC() const { return lastCC; }
@ -163,7 +163,7 @@ public:
UBool append(UChar32 c, uint8_t cc, UErrorCode &errorCode) {
return (c<=0xffff) ?
appendBMP((char16_t)c, cc, errorCode) :
appendBMP(static_cast<char16_t>(c), cc, errorCode) :
appendSupplementary(c, cc, errorCode);
}
UBool append(const char16_t *s, int32_t length, UBool isNFD,
@ -190,12 +190,12 @@ public:
void remove();
void removeSuffix(int32_t suffixLength);
void setReorderingLimit(char16_t *newLimit) {
remainingCapacity+=(int32_t)(limit-newLimit);
remainingCapacity += static_cast<int32_t>(limit - newLimit);
reorderStart=limit=newLimit;
lastCC=0;
}
void copyReorderableSuffixTo(UnicodeString &s) const {
s.setTo(ConstChar16Ptr(reorderStart), (int32_t)(limit-reorderStart));
s.setTo(ConstChar16Ptr(reorderStart), static_cast<int32_t>(limit - reorderStart));
}
private:
/*
@ -215,7 +215,7 @@ private:
void insert(UChar32 c, uint8_t cc);
static void writeCodePoint(char16_t *p, UChar32 c) {
if(c<=0xffff) {
*p=(char16_t)c;
*p = static_cast<char16_t>(c);
} else {
p[0]=U16_LEAD(c);
p[1]=U16_TRAIL(c);
@ -241,7 +241,7 @@ private:
* Low-level implementation of the Unicode Normalization Algorithm.
* For the data structure and details see the documentation at the end of
* this normalizer2impl.h and in the design doc at
* https://icu.unicode.org/design/normalization/custom
* https://unicode-org.github.io/icu/design/normalization/custom.html
*/
class U_COMMON_API Normalizer2Impl : public UObject {
public:
@ -271,14 +271,14 @@ public:
UNormalizationCheckResult getCompQuickCheck(uint16_t norm16) const {
if(norm16<minNoNo || MIN_YES_YES_WITH_CC<=norm16) {
return UNORM_YES;
} else if(minMaybeYes<=norm16) {
} else if(minMaybeNo<=norm16) {
return UNORM_MAYBE;
} else {
return UNORM_NO;
}
}
UBool isAlgorithmicNoNo(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeYes; }
UBool isCompNo(uint16_t norm16) const { return minNoNo<=norm16 && norm16<minMaybeYes; }
UBool isAlgorithmicNoNo(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeNo; }
UBool isCompNo(uint16_t norm16) const { return minNoNo<=norm16 && norm16<minMaybeNo; }
UBool isDecompYes(uint16_t norm16) const { return norm16<minYesNo || minMaybeYes<=norm16; }
uint8_t getCC(uint16_t norm16) const {
@ -291,14 +291,14 @@ public:
return getCCFromNoNo(norm16);
}
static uint8_t getCCFromNormalYesOrMaybe(uint16_t norm16) {
return (uint8_t)(norm16 >> OFFSET_SHIFT);
return static_cast<uint8_t>(norm16 >> OFFSET_SHIFT);
}
static uint8_t getCCFromYesOrMaybe(uint16_t norm16) {
static uint8_t getCCFromYesOrMaybeYes(uint16_t norm16) {
return norm16>=MIN_NORMAL_MAYBE_YES ? getCCFromNormalYesOrMaybe(norm16) : 0;
}
uint8_t getCCFromYesOrMaybeCP(UChar32 c) const {
uint8_t getCCFromYesOrMaybeYesCP(UChar32 c) const {
if (c < minCompNoMaybeCP) { return 0; }
return getCCFromYesOrMaybe(getNorm16(c));
return getCCFromYesOrMaybeYes(getNorm16(c));
}
/**
@ -364,11 +364,13 @@ public:
// 0<=lead<=0xffff
uint8_t bits=smallFCD[lead>>8];
if(bits==0) { return false; }
return (UBool)((bits>>((lead>>5)&7))&1);
return (bits >> ((lead >> 5) & 7)) & 1;
}
/** Returns the FCD value from the regular normalization data. */
uint16_t getFCD16FromNormData(UChar32 c) const;
uint16_t getFCD16FromMaybeOrNonZeroCC(uint16_t norm16) const;
/**
* Gets the decomposition for one code point.
* @param c code point
@ -450,7 +452,13 @@ public:
IX_MIN_LCCC_CP,
IX_RESERVED19,
IX_COUNT
/** Two-way mappings; each starts with a character that combines backward. */
IX_MIN_MAYBE_NO, // 20
/** Two-way mappings & compositions. */
IX_MIN_MAYBE_NO_COMBINES_FWD,
IX_COUNT // 22
};
enum {
@ -541,7 +549,8 @@ public:
uint16_t norm16=getNorm16(c);
return isCompYesAndZeroCC(norm16) &&
(norm16 & HAS_COMP_BOUNDARY_AFTER) != 0 &&
(!onlyContiguous || isInert(norm16) || *getMapping(norm16) <= 0x1ff);
(!onlyContiguous || isInert(norm16) || *getDataForYesOrNo(norm16) <= 0x1ff);
// The last check fetches the mapping's first unit and checks tccc<=1.
}
UBool hasFCDBoundaryBefore(UChar32 c) const { return hasDecompBoundaryBefore(c); }
@ -551,8 +560,8 @@ private:
friend class InitCanonIterData;
friend class LcccContext;
UBool isMaybe(uint16_t norm16) const { return minMaybeYes<=norm16 && norm16<=JAMO_VT; }
UBool isMaybeOrNonZeroCC(uint16_t norm16) const { return norm16>=minMaybeYes; }
UBool isMaybe(uint16_t norm16) const { return minMaybeNo<=norm16 && norm16<=JAMO_VT; }
UBool isMaybeYesOrNonZeroCC(uint16_t norm16) const { return norm16>=minMaybeYes; }
static UBool isInert(uint16_t norm16) { return norm16==INERT; }
static UBool isJamoL(uint16_t norm16) { return norm16==JAMO_L; }
static UBool isJamoVT(uint16_t norm16) { return norm16==JAMO_VT; }
@ -566,7 +575,7 @@ private:
// return norm16>=MIN_YES_YES_WITH_CC || norm16<minNoNo;
// }
// UBool isCompYesOrMaybe(uint16_t norm16) const {
// return norm16<minNoNo || minMaybeYes<=norm16;
// return norm16<minNoNo || minMaybeNo<=norm16;
// }
// UBool hasZeroCCFromDecompYes(uint16_t norm16) const {
// return norm16<=MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
@ -579,12 +588,12 @@ private:
/**
* A little faster and simpler than isDecompYesAndZeroCC() but does not include
* the MaybeYes which combine-forward and have ccc=0.
* (Standard Unicode 10 normalization does not have such characters.)
*/
UBool isMostDecompYesAndZeroCC(uint16_t norm16) const {
return norm16<minYesNo || norm16==MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
}
UBool isDecompNoAlgorithmic(uint16_t norm16) const { return norm16>=limitNoNo; }
/** Since formatVersion 5: same as isAlgorithmicNoNo() */
UBool isDecompNoAlgorithmic(uint16_t norm16) const { return limitNoNo<=norm16 && norm16<minMaybeNo; }
// For use with isCompYes().
// Perhaps the compiler can combine the two tests for MIN_YES_YES_WITH_CC.
@ -592,9 +601,9 @@ private:
// return norm16>=MIN_YES_YES_WITH_CC ? getCCFromNormalYesOrMaybe(norm16) : 0;
// }
uint8_t getCCFromNoNo(uint16_t norm16) const {
const uint16_t *mapping=getMapping(norm16);
const uint16_t *mapping=getDataForYesOrNo(norm16);
if(*mapping&MAPPING_HAS_CCC_LCCC_WORD) {
return (uint8_t)*(mapping-1);
return static_cast<uint8_t>(*(mapping - 1));
} else {
return 0;
}
@ -605,7 +614,7 @@ private:
return 0; // yesYes and Hangul LV have ccc=tccc=0
} else {
// For Hangul LVT we harmlessly fetch a firstUnit with tccc=0 here.
return (uint8_t)(*getMapping(norm16)>>8); // tccc from yesNo
return static_cast<uint8_t>(*getDataForYesOrNo(norm16) >> 8); // tccc from yesNo
}
}
uint8_t getPreviousTrailCC(const char16_t *start, const char16_t *p) const;
@ -619,28 +628,33 @@ private:
return (norm16>>DELTA_SHIFT)-centerNoNoDelta;
}
// Requires minYesNo<norm16<limitNoNo.
const uint16_t *getMapping(uint16_t norm16) const { return extraData+(norm16>>OFFSET_SHIFT); }
const uint16_t *getDataForYesOrNo(uint16_t norm16) const {
return extraData+(norm16>>OFFSET_SHIFT);
}
const uint16_t *getDataForMaybe(uint16_t norm16) const {
return extraData+((norm16-minMaybeNo+limitNoNo)>>OFFSET_SHIFT);
}
const uint16_t *getData(uint16_t norm16) const {
if(norm16>=minMaybeNo) {
norm16=norm16-minMaybeNo+limitNoNo;
}
return extraData+(norm16>>OFFSET_SHIFT);
}
const uint16_t *getCompositionsListForDecompYes(uint16_t norm16) const {
if(norm16<JAMO_L || MIN_NORMAL_MAYBE_YES<=norm16) {
return nullptr;
} else if(norm16<minMaybeYes) {
return getMapping(norm16); // for yesYes; if Jamo L: harmless empty list
} else {
return maybeYesCompositions+norm16-minMaybeYes;
// if yesYes: if Jamo L: harmless empty list
return getData(norm16);
}
}
const uint16_t *getCompositionsListForComposite(uint16_t norm16) const {
// A composite has both mapping & compositions list.
const uint16_t *list=getMapping(norm16);
const uint16_t *list=getData(norm16);
return list+ // mapping pointer
1+ // +1 to skip the first unit with the mapping length
(*list&MAPPING_LENGTH_MASK); // + mapping length
}
const uint16_t *getCompositionsListForMaybe(uint16_t norm16) const {
// minMaybeYes<=norm16<MIN_NORMAL_MAYBE_YES
return maybeYesCompositions+((norm16-minMaybeYes)>>OFFSET_SHIFT);
}
/**
* @param c code point must have compositions
* @return compositions list pointer
@ -692,11 +706,13 @@ private:
/** For FCC: Given norm16 HAS_COMP_BOUNDARY_AFTER, does it have tccc<=1? */
UBool isTrailCC01ForCompBoundaryAfter(uint16_t norm16) const {
return isInert(norm16) || (isDecompNoAlgorithmic(norm16) ?
(norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1 : *getMapping(norm16) <= 0x1ff);
(norm16 & DELTA_TCCC_MASK) <= DELTA_TCCC_1 : *getDataForYesOrNo(norm16) <= 0x1ff);
}
const char16_t *findPreviousCompBoundary(const char16_t *start, const char16_t *p, UBool onlyContiguous) const;
const char16_t *findNextCompBoundary(const char16_t *p, const char16_t *limit, UBool onlyContiguous) const;
const char16_t *findPreviousCompBoundary(const char16_t *start, const char16_t *p,
UBool onlyContiguous) const;
const char16_t *findNextCompBoundary(const char16_t *p, const char16_t *limit,
UBool onlyContiguous) const;
const char16_t *findPreviousFCDBoundary(const char16_t *start, const char16_t *p) const;
const char16_t *findNextFCDBoundary(const char16_t *p, const char16_t *limit) const;
@ -723,11 +739,12 @@ private:
uint16_t minNoNoEmpty;
uint16_t limitNoNo;
uint16_t centerNoNoDelta;
uint16_t minMaybeNo;
uint16_t minMaybeNoCombinesFwd;
uint16_t minMaybeYes;
const UCPTrie *normTrie;
const uint16_t *maybeYesCompositions;
const uint16_t *extraData; // mappings and/or compositions for yesYes, yesNo & noNo characters
const uint16_t *extraData; // mappings and/or compositions
const uint8_t *smallFCD; // [0x100] one bit per 32 BMP code points, set if any FCD!=0
UInitOnce fCanonIterDataInitOnce {};
@ -785,7 +802,7 @@ unorm_getFCD16(UChar32 c);
/**
* Format of Normalizer2 .nrm data files.
* Format version 4.0.
* Format version 5.0.
*
* Normalizer2 .nrm data files provide data for the Unicode Normalization algorithms.
* ICU ships with data files for standard Unicode Normalization Forms
@ -807,7 +824,7 @@ unorm_getFCD16(UChar32 c);
* Constants are defined as enum values of the Normalizer2Impl class.
*
* Many details of the data structures are described in the design doc
* which is at https://icu.unicode.org/design/normalization/custom
* which is at https://unicode-org.github.io/icu/design/normalization/custom.html
*
* int32_t indexes[indexesLength]; -- indexesLength=indexes[IX_NORM_TRIE_OFFSET]/4;
*
@ -829,7 +846,9 @@ unorm_getFCD16(UChar32 c);
*
* The next eight indexes are thresholds of 16-bit trie values for ranges of
* values indicating multiple normalization properties.
* They are listed here in threshold order, not in the order they are stored in the indexes.
* Format version 5 adds the two minMaybeNo* threshold indexes.
* The thresholds are listed here in threshold order,
* not in the order they are stored in the indexes.
* minYesNo=indexes[IX_MIN_YES_NO];
* minYesNoMappingsOnly=indexes[IX_MIN_YES_NO_MAPPINGS_ONLY];
* minNoNo=indexes[IX_MIN_NO_NO];
@ -837,6 +856,8 @@ unorm_getFCD16(UChar32 c);
* minNoNoCompNoMaybeCC=indexes[IX_MIN_NO_NO_COMP_NO_MAYBE_CC];
* minNoNoEmpty=indexes[IX_MIN_NO_NO_EMPTY];
* limitNoNo=indexes[IX_LIMIT_NO_NO];
* minMaybeNo=indexes[IX_MIN_MAYBE_NO];
* minMaybeNoCombinesFwd=indexes[IX_MIN_MAYBE_NO_COMBINES_FWD];
* minMaybeYes=indexes[IX_MIN_MAYBE_YES];
* See the normTrie description below and the design doc for details.
*
@ -845,13 +866,14 @@ unorm_getFCD16(UChar32 c);
* The trie holds the main normalization data. Each code point is mapped to a 16-bit value.
* Rather than using independent bits in the value (which would require more than 16 bits),
* information is extracted primarily via range checks.
* Except, format version 3 uses bit 0 for hasCompBoundaryAfter().
* Except, format version 3+ uses bit 0 for hasCompBoundaryAfter().
* For example, a 16-bit value norm16 in the range minYesNo<=norm16<minNoNo
* means that the character has NF*C_QC=Yes and NF*D_QC=No properties,
* which means it has a two-way (round-trip) decomposition mapping.
* Values in the range 2<=norm16<limitNoNo are also directly indexes into the extraData
* Values in the ranges 2<=norm16<limitNoNo and minMaybeNo<=norm16<minMaybeYes
* are also directly indexes into the extraData
* pointing to mappings, compositions lists, or both.
* Value norm16==INERT (0 in versions 1 & 2, 1 in version 3)
* Value norm16==INERT (0 in versions 1 & 2, 1 in version 3+)
* means that the character is normalization-inert, that is,
* it does not have a mapping, does not participate in composition, has a zero
* canonical combining class, and forms a boundary where text before it and after it
@ -870,33 +892,38 @@ unorm_getFCD16(UChar32 c);
* When the lead surrogate unit's value exceeds the quick check minimum during processing,
* the properties for the full supplementary code point need to be looked up.
*
* uint16_t maybeYesCompositions[MIN_NORMAL_MAYBE_YES-minMaybeYes];
* uint16_t extraData[];
*
* There is only one byte offset for the end of these two arrays.
* The split between them is given by the constant and variable mentioned above.
* In version 3, the difference must be shifted right by OFFSET_SHIFT.
* The extraData array contains many per-character data sections.
* Each section contains mappings and/or composition lists.
* The norm16 value of each character that has such data is directly an index to
* a section of the extraData array.
*
* The maybeYesCompositions array contains compositions lists for characters that
* combine both forward (as starters in composition pairs)
* and backward (as trailing characters in composition pairs).
* Such characters do not occur in Unicode 5.2 but are allowed by
* the Unicode Normalization algorithms.
* If there are no such characters, then minMaybeYes==MIN_NORMAL_MAYBE_YES
* and the maybeYesCompositions array is empty.
* If there are such characters, then minMaybeYes is subtracted from their norm16 values
* to get the index into this array.
*
* The extraData array contains compositions lists for "YesYes" characters,
* followed by mappings and optional compositions lists for "YesNo" characters,
* followed by only mappings for "NoNo" characters.
* (Referring to pairs of NFC/NFD quick check values.)
* The norm16 values of those characters are directly indexes into the extraData array.
* In version 3, the norm16 values must be shifted right by OFFSET_SHIFT
* In version 3+, the norm16 values must be shifted right by OFFSET_SHIFT
* for accessing extraData.
*
* The data structures for compositions lists and mappings are described in the design doc.
*
* In version 4 and below, the composition lists for MaybeYes characters were stored before
* the data for other characters.
* This sub-array had a length of MIN_NORMAL_MAYBE_YES-minMaybeYes.
* In version 3 & 4, the difference must be shifted right by OFFSET_SHIFT.
*
* In version 5, the data for MaybeNo and MaybeYes characters is stored after
* the data for other characters.
*
* If there are no MaybeNo and no MaybeYes characters,
* then minMaybeYes==minMaybeNo==MIN_NORMAL_MAYBE_YES.
* If there are such characters, then minMaybeNo is subtracted from their norm16 values
* to get the index into the extraData.
* In version 4 and below, the data index for Yes* and No* characters needs to be
* offset by the length of the MaybeYes data.
* In version 5, the data index for Maybe* characters needs to be offset by limitNoNo.
*
* Version 5 is the first to support MaybeNo characters, and
* adds the minMaybeNo and minMaybeNoCombinesFwd thresholds and
* the corresponding sections of the extraData.
*
* uint8_t smallFCD[0x100]; -- new in format version 2
*
* This is a bit set to help speed up FCD value lookups in the absence of a full
@ -936,7 +963,7 @@ unorm_getFCD16(UChar32 c);
* to make room for two bits (three values) indicating whether the tccc is 0, 1, or greater.
* See DELTA_TCCC_MASK etc.
* This helps with fetching tccc/FCD values and FCC hasCompBoundaryAfter().
* minMaybeYes is 8-aligned so that the DELTA_TCCC_MASK bits can be tested directly.
* minMaybeNo is 8-aligned so that the DELTA_TCCC_MASK bits can be tested directly.
*
* - Algorithmic mappings are only used for mapping to "comp yes and ccc=0" characters,
* and ASCII characters are mapped algorithmically only to other ASCII characters.
@ -982,6 +1009,23 @@ unorm_getFCD16(UChar32 c);
* gennorm2 now has to reject mappings for surrogate code points.
* UTS #46 maps unpaired surrogates to U+FFFD in code rather than via its
* custom normalization data file.
*
* Changes from format version 4 to format version 5 (ICU 76) ------------------
*
* Unicode 16 adds the first MaybeYes characters which combine both backward and forward,
* taking this formerly theoretical data structure into reality.
*
* Unicode 16 also adds the first characters that have two-way mappings whose first characters
* combine backward. In order for normalization and the quick check to work properly,
* these composite characters also must be marked as NFC_QC=Maybe,
* corresponding to "combines back", although the composites themselves do not combine backward.
* Format version 5 adds two new ranges between "algorithmic NoNo" and MaybeYes,
* with thresholds minMaybeNo and minMaybeNoCombinesFwd,
* and indexes[IX_MIN_MAYBE_NO] and indexes[IX_MIN_MAYBE_NO_COMBINES_FWD],
* and corresponding mappings and composition lists in the extraData.
*
* Format version 5 moves the data for Maybe* characters from the start of the extraData array
* to its end.
*/
#endif /* !UCONFIG_NO_NORMALIZATION */

View file

@ -120,12 +120,12 @@ PatternProps::isSyntax(UChar32 c) {
if(c<0) {
return false;
} else if(c<=0xff) {
return (UBool)(latin1[c]>>1)&1;
return (latin1[c] >> 1) & 1;
} else if(c<0x2010) {
return false;
} else if(c<=0x3030) {
uint32_t bits=syntax2000[index2000[(c-0x2000)>>5]];
return (UBool)((bits>>(c&0x1f))&1);
return (bits >> (c & 0x1f)) & 1;
} else if(0xfd3e<=c && c<=0xfe46) {
return c<=0xfd3f || 0xfe45<=c;
} else {
@ -138,12 +138,12 @@ PatternProps::isSyntaxOrWhiteSpace(UChar32 c) {
if(c<0) {
return false;
} else if(c<=0xff) {
return (UBool)(latin1[c]&1);
return latin1[c] & 1;
} else if(c<0x200e) {
return false;
} else if(c<=0x3030) {
uint32_t bits=syntaxOrWhiteSpace2000[index2000[(c-0x2000)>>5]];
return (UBool)((bits>>(c&0x1f))&1);
return (bits >> (c & 0x1f)) & 1;
} else if(0xfd3e<=c && c<=0xfe46) {
return c<=0xfd3f || 0xfe45<=c;
} else {
@ -156,7 +156,7 @@ PatternProps::isWhiteSpace(UChar32 c) {
if(c<0) {
return false;
} else if(c<=0xff) {
return (UBool)(latin1[c]>>2)&1;
return (latin1[c] >> 2) & 1;
} else if(0x200e<=c && c<=0x2029) {
return c<=0x200f || 0x2028<=c;
} else {

View file

@ -43,7 +43,7 @@ getASCIIPropertyNameChar(const char *name) {
) {}
if(c!=0) {
return (i<<8)|(uint8_t)uprv_asciitolower((char)c);
return (i << 8) | static_cast<uint8_t>(uprv_asciitolower(c));
} else {
return i<<8;
}
@ -66,7 +66,7 @@ getEBCDICPropertyNameChar(const char *name) {
) {}
if(c!=0) {
return (i<<8)|(uint8_t)uprv_ebcdictolower((char)c);
return (i << 8) | static_cast<uint8_t>(uprv_ebcdictolower(c));
} else {
return i<<8;
}
@ -231,7 +231,7 @@ UBool PropNameData::containsName(BytesTrie &trie, const char *name) {
if(!USTRINGTRIE_HAS_NEXT(result)) {
return false;
}
result=trie.next((uint8_t)c);
result = trie.next(static_cast<uint8_t>(c));
}
return USTRINGTRIE_HAS_VALUE(result);
}

File diff suppressed because it is too large Load diff

View file

@ -102,29 +102,29 @@ _findRow(UPropsVectors *pv, UChar32 rangeStart) {
/* check the vicinity of the last-seen row (start searching with an unrolled loop) */
row=pv->v+prevRow*columns;
if(rangeStart>=(UChar32)row[0]) {
if(rangeStart<(UChar32)row[1]) {
if (rangeStart >= static_cast<UChar32>(row[0])) {
if (rangeStart < static_cast<UChar32>(row[1])) {
/* same row as last seen */
return row;
} else if(rangeStart<(UChar32)(row+=columns)[1]) {
} else if (rangeStart < static_cast<UChar32>((row += columns)[1])) {
/* next row after the last one */
pv->prevRow=prevRow+1;
return row;
} else if(rangeStart<(UChar32)(row+=columns)[1]) {
} else if (rangeStart < static_cast<UChar32>((row += columns)[1])) {
/* second row after the last one */
pv->prevRow=prevRow+2;
return row;
} else if((rangeStart-(UChar32)row[1])<10) {
} else if ((rangeStart - static_cast<UChar32>(row[1])) < 10) {
/* we are close, continue looping */
prevRow+=2;
do {
++prevRow;
row+=columns;
} while(rangeStart>=(UChar32)row[1]);
} while (rangeStart >= static_cast<UChar32>(row[1]));
pv->prevRow=prevRow;
return row;
}
} else if(rangeStart<(UChar32)pv->v[1]) {
} else if (rangeStart < static_cast<UChar32>(pv->v[1])) {
/* the very first row */
pv->prevRow=0;
return pv->v;
@ -135,9 +135,9 @@ _findRow(UPropsVectors *pv, UChar32 rangeStart) {
while(start<limit-1) {
i=(start+limit)/2;
row=pv->v+i*columns;
if(rangeStart<(UChar32)row[0]) {
if (rangeStart < static_cast<UChar32>(row[0])) {
limit=i;
} else if(rangeStart<(UChar32)row[1]) {
} else if (rangeStart < static_cast<UChar32>(row[1])) {
pv->prevRow=i;
return row;
} else {
@ -194,8 +194,8 @@ upvec_setValue(UPropsVectors *pv,
* input range (only possible for the first and last rows)
* and if their value differs from the input value.
*/
splitFirstRow= (UBool)(start!=(UChar32)firstRow[0] && value!=(firstRow[column]&mask));
splitLastRow= (UBool)(limit!=(UChar32)lastRow[1] && value!=(lastRow[column]&mask));
splitFirstRow = start != static_cast<UChar32>(firstRow[0]) && value != (firstRow[column] & mask);
splitLastRow = limit != static_cast<UChar32>(lastRow[1]) && value != (lastRow[column] & mask);
/* split first/last rows if necessary */
if(splitFirstRow || splitLastRow) {
@ -312,8 +312,8 @@ upvec_getRow(const UPropsVectors *pv, int32_t rowIndex,
static int32_t U_CALLCONV
upvec_compareRows(const void *context, const void *l, const void *r) {
const uint32_t *left=(const uint32_t *)l, *right=(const uint32_t *)r;
const UPropsVectors *pv=(const UPropsVectors *)context;
const uint32_t* left = static_cast<const uint32_t*>(l), *right = static_cast<const uint32_t*>(r);
const UPropsVectors* pv = static_cast<const UPropsVectors*>(context);
int32_t i, count, columns;
count=columns=pv->columns; /* includes start/limit columns */

View file

@ -97,12 +97,12 @@ digitToBasic(int32_t digit, UBool uppercase) {
/* 26..35 map to ASCII 0..9 */
if(digit<26) {
if(uppercase) {
return (char)(_CAPITAL_A+digit);
return static_cast<char>(_CAPITAL_A + digit);
} else {
return (char)(_SMALL_A+digit);
return static_cast<char>(_SMALL_A + digit);
}
} else {
return (char)((_ZERO_-26)+digit);
return static_cast<char>((_ZERO_ - 26) + digit);
}
}
@ -353,10 +353,10 @@ u_strToPunycode(const char16_t *src, int32_t srcLength,
}
if(destLength<destCapacity) {
dest[destLength]=digitToBasic(q, (UBool)(cpBuffer[j]<0));
dest[destLength] = digitToBasic(q, cpBuffer[j] < 0);
}
++destLength;
bias=adaptBias(delta, handledCPCount+1, (UBool)(handledCPCount==basicLength));
bias = adaptBias(delta, handledCPCount + 1, handledCPCount == basicLength);
delta=0;
++handledCPCount;
}
@ -421,7 +421,7 @@ u_strFromPunycode(const char16_t *src, int32_t srcLength,
}
if(j<destCapacity) {
dest[j]=(char16_t)b;
dest[j] = b;
if(caseFlags!=nullptr) {
caseFlags[j]=IS_BASIC_UPPERCASE(b);
@ -500,7 +500,7 @@ u_strFromPunycode(const char16_t *src, int32_t srcLength,
* where needed instead of in for() loop tail.
*/
++destCPCount;
bias=adaptBias(i-oldi, destCPCount, (UBool)(oldi==0));
bias = adaptBias(i - oldi, destCPCount, oldi == 0);
/*
* i was supposed to wrap around from (incremented) destCPCount to 0,

View file

@ -46,11 +46,6 @@
// First, the platform type. Need this for U_PLATFORM.
#include "unicode/platform.h"
#if U_PLATFORM == U_PF_MINGW && defined __STRICT_ANSI__
/* tzset isn't defined in strict ANSI on MinGW. */
#undef __STRICT_ANSI__
#endif
/*
* Cygwin with GCC requires inclusion of time.h after the above disabling strict asci mode statement.
*/
@ -180,8 +175,8 @@ typedef union {
int64_t i64; /* This must be defined first in order to allow the initialization to work. This is a C89 feature. */
double d64;
} BitPatternConversion;
static const BitPatternConversion gNan = { (int64_t) INT64_C(0x7FF8000000000000) };
static const BitPatternConversion gInf = { (int64_t) INT64_C(0x7FF0000000000000) };
static const BitPatternConversion gNan = {static_cast<int64_t>(INT64_C(0x7FF8000000000000))};
static const BitPatternConversion gInf = {static_cast<int64_t>(INT64_C(0x7FF0000000000000))};
/*---------------------------------------------------------------------------
Platform utilities
@ -230,7 +225,7 @@ u_signBit(double d) {
#if U_IS_BIG_ENDIAN
hiByte = *(uint8_t *)&d;
#else
hiByte = *(((uint8_t *)&d) + sizeof(double) - 1);
hiByte = *(reinterpret_cast<uint8_t*>(&d) + sizeof(double) - 1);
#endif
return (hiByte & 0x80) != 0;
}
@ -347,7 +342,7 @@ uprv_isNaN(double number)
BitPatternConversion convertedNumber;
convertedNumber.d64 = number;
/* Infinity is 0x7FF0000000000000U. Anything greater than that is a NaN */
return (UBool)((convertedNumber.i64 & U_INT64_MAX) > gInf.i64);
return (convertedNumber.i64 & U_INT64_MAX) > gInf.i64;
#elif U_PLATFORM == U_PF_OS390
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
@ -373,7 +368,7 @@ uprv_isInfinite(double number)
BitPatternConversion convertedNumber;
convertedNumber.d64 = number;
/* Infinity is exactly 0x7FF0000000000000U. */
return (UBool)((convertedNumber.i64 & U_INT64_MAX) == gInf.i64);
return (convertedNumber.i64 & U_INT64_MAX) == gInf.i64;
#elif U_PLATFORM == U_PF_OS390
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
sizeof(uint32_t));
@ -394,7 +389,7 @@ U_CAPI UBool U_EXPORT2
uprv_isPositiveInfinity(double number)
{
#if IEEE_754 || U_PLATFORM == U_PF_OS390
return (UBool)(number > 0 && uprv_isInfinite(number));
return number > 0 && uprv_isInfinite(number);
#else
return uprv_isInfinite(number);
#endif
@ -404,7 +399,7 @@ U_CAPI UBool U_EXPORT2
uprv_isNegativeInfinity(double number)
{
#if IEEE_754 || U_PLATFORM == U_PF_OS390
return (UBool)(number < 0 && uprv_isInfinite(number));
return number < 0 && uprv_isInfinite(number);
#else
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
@ -749,11 +744,11 @@ static UBool isValidOlsonID(const char *id) {
The timezone is sometimes set to "CST-7CDT", "CST6CDT5,J129,J131/19:30",
"GRNLNDST3GRNLNDDT" or similar, so we cannot use it.
The rest of the time it could be an Olson ID. George */
return (UBool)(id[idx] == 0
return id[idx] == 0
|| uprv_strcmp(id, "PST8PDT") == 0
|| uprv_strcmp(id, "MST7MDT") == 0
|| uprv_strcmp(id, "CST6CDT") == 0
|| uprv_strcmp(id, "EST5EDT") == 0);
|| uprv_strcmp(id, "EST5EDT") == 0;
}
/* On some Unix-like OS, 'posix' subdirectory in
@ -932,7 +927,7 @@ static UBool compareBinaryFiles(const char* defaultTZFileName, const char* TZFil
*/
if (tzInfo->defaultTZBuffer == nullptr) {
rewind(tzInfo->defaultTZFilePtr);
tzInfo->defaultTZBuffer = (char*)uprv_malloc(sizeof(char) * tzInfo->defaultTZFileSize);
tzInfo->defaultTZBuffer = static_cast<char*>(uprv_malloc(sizeof(char) * tzInfo->defaultTZFileSize));
sizeFileRead = fread(tzInfo->defaultTZBuffer, 1, tzInfo->defaultTZFileSize, tzInfo->defaultTZFilePtr);
}
rewind(file);

View file

@ -90,6 +90,8 @@ typedef size_t uintptr_t;
# define U_NL_LANGINFO_CODESET -1
#elif U_PLATFORM == U_PF_OS400
/* not defined */
#elif U_PLATFORM == U_PF_HAIKU
/* not defined */
#else
# define U_NL_LANGINFO_CODESET CODESET
#endif
@ -103,6 +105,8 @@ typedef size_t uintptr_t;
#endif
#elif U_PLATFORM == U_PF_OS400
/* not defined */
#elif U_PLATFORM == U_PF_HAIKU
/* not defined */
#else
# define U_TZSET tzset
#endif
@ -141,6 +145,8 @@ typedef size_t uintptr_t;
#endif
#elif U_PLATFORM == U_PF_OS400
/* not defined */
#elif U_PLATFORM == U_PF_HAIKU
/* not defined, (well it is but a loop back to icu) */
#else
# define U_TZNAME tzname
#endif
@ -553,7 +559,7 @@ inline int32_t pinCapacity(T *dest, int32_t capacity) {
if (maxInt < destInt) {
// Less than 2GB to the end of the address space.
// Pin to that to prevent address overflow.
maxInt = (uintptr_t)-1;
maxInt = static_cast<uintptr_t>(-1);
}
# endif

View file

@ -110,7 +110,7 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(const uint8_t *compiledRules,
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
const RBBIDataHeader *data = (const RBBIDataHeader *)compiledRules;
const RBBIDataHeader* data = reinterpret_cast<const RBBIDataHeader*>(compiledRules);
if (data->fLength > ruleLength) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
@ -553,7 +553,7 @@ int32_t RuleBasedBreakIterator::first() {
* @return The text's past-the-end offset.
*/
int32_t RuleBasedBreakIterator::last() {
int32_t endPos = (int32_t)utext_nativeLength(&fText);
int32_t endPos = static_cast<int32_t>(utext_nativeLength(&fText));
UBool endShouldBeBoundary = isBoundary(endPos); // Has side effect of setting iterator position.
(void)endShouldBeBoundary;
U_ASSERT(endShouldBeBoundary);
@ -625,7 +625,7 @@ int32_t RuleBasedBreakIterator::following(int32_t startPos) {
// Move requested offset to a code point start. It might be on a trail surrogate,
// or on a trail byte if the input is UTF-8. Or it may be beyond the end of the text.
utext_setNativeIndex(&fText, startPos);
startPos = (int32_t)utext_getNativeIndex(&fText);
startPos = static_cast<int32_t>(utext_getNativeIndex(&fText));
UErrorCode status = U_ZERO_ERROR;
fBreakCache->following(startPos, status);
@ -881,7 +881,7 @@ int32_t RuleBasedBreakIterator::handleNext() {
if (accepting == ACCEPTING_UNCONDITIONAL) {
// Match found, common case.
if (mode != RBBI_START) {
result = (int32_t)UTEXT_GETNATIVEINDEX(&fText);
result = static_cast<int32_t>(UTEXT_GETNATIVEINDEX(&fText));
}
fRuleStatusIndex = row->fTagsIdx; // Remember the break status (tag) values.
} else if (accepting > ACCEPTING_UNCONDITIONAL) {
@ -905,7 +905,7 @@ int32_t RuleBasedBreakIterator::handleNext() {
U_ASSERT(rule == 0 || rule > ACCEPTING_UNCONDITIONAL);
U_ASSERT(rule == 0 || rule < fData->fForwardTable->fLookAheadResultsSize);
if (rule > ACCEPTING_UNCONDITIONAL) {
int32_t pos = (int32_t)UTEXT_GETNATIVEINDEX(&fText);
int32_t pos = static_cast<int32_t>(UTEXT_GETNATIVEINDEX(&fText));
fLookAheadMatches[rule] = pos;
}
@ -937,7 +937,7 @@ int32_t RuleBasedBreakIterator::handleNext() {
if (result == initialPosition) {
utext_setNativeIndex(&fText, initialPosition);
utext_next32(&fText);
result = (int32_t)utext_getNativeIndex(&fText);
result = static_cast<int32_t>(utext_getNativeIndex(&fText));
fRuleStatusIndex = 0;
}
@ -1027,7 +1027,7 @@ int32_t RuleBasedBreakIterator::handleSafePrevious(int32_t fromPosition) {
}
// The state machine is done. Check whether it found a match...
result = (int32_t)UTEXT_GETNATIVEINDEX(&fText);
result = static_cast<int32_t>(UTEXT_GETNATIVEINDEX(&fText));
#ifdef RBBI_DEBUG
if (gTrace) {
RBBIDebugPrintf("result = %d\n\n", result);
@ -1091,7 +1091,7 @@ const uint8_t *RuleBasedBreakIterator::getBinaryRules(uint32_t &length) {
length = 0;
if (fData != nullptr) {
retPtr = (const uint8_t *)fData->fHeader;
retPtr = reinterpret_cast<const uint8_t*>(fData->fHeader);
length = fData->fHeader->fLength;
}
return retPtr;
@ -1187,7 +1187,7 @@ getLanguageBreakEngineFromFactory(UChar32 c, const char* locale)
int32_t i = gLanguageBreakFactories->size();
const LanguageBreakEngine *lbe = nullptr;
while (--i >= 0) {
LanguageBreakFactory *factory = (LanguageBreakFactory *)(gLanguageBreakFactories->elementAt(i));
LanguageBreakFactory* factory = static_cast<LanguageBreakFactory*>(gLanguageBreakFactories->elementAt(i));
lbe = factory->getEngineFor(c, locale);
if (lbe != nullptr) {
break;
@ -1219,7 +1219,7 @@ RuleBasedBreakIterator::getLanguageBreakEngine(UChar32 c, const char* locale) {
int32_t i = fLanguageBreakEngines->size();
while (--i >= 0) {
lbe = (const LanguageBreakEngine *)(fLanguageBreakEngines->elementAt(i));
lbe = static_cast<const LanguageBreakEngine*>(fLanguageBreakEngines->elementAt(i));
if (lbe->handles(c, locale)) {
return lbe;
}

View file

@ -146,7 +146,7 @@ void RuleBasedBreakIterator::DictionaryCache::populateDictionary(int32_t startPo
uint32_t dictStart = fBI->fData->fForwardTable->fDictCategoriesStart;
while(U_SUCCESS(status)) {
while((current = (int32_t)UTEXT_GETNATIVEINDEX(text)) < rangeEnd
while ((current = static_cast<int32_t>(UTEXT_GETNATIVEINDEX(text))) < rangeEnd
&& (category < dictStart)) {
utext_next32(text); // TODO: cleaner loop structure.
c = utext_current32(text);
@ -221,7 +221,7 @@ void RuleBasedBreakIterator::BreakCache::reset(int32_t pos, int32_t ruleStatus)
fTextIdx = pos;
fBufIdx = 0;
fBoundaries[0] = pos;
fStatuses[0] = (uint16_t)ruleStatus;
fStatuses[0] = static_cast<uint16_t>(ruleStatus);
}

View file

@ -104,10 +104,10 @@ void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) {
fDontFreeData = false;
if (data->fFTableLen != 0) {
fForwardTable = (RBBIStateTable *)((char *)data + fHeader->fFTable);
fForwardTable = reinterpret_cast<const RBBIStateTable*>(reinterpret_cast<const char*>(data) + fHeader->fFTable);
}
if (data->fRTableLen != 0) {
fReverseTable = (RBBIStateTable *)((char *)data + fHeader->fRTable);
fReverseTable = reinterpret_cast<const RBBIStateTable*>(reinterpret_cast<const char*>(data) + fHeader->fRTable);
}
fTrie = ucptrie_openFromBinary(UCPTRIE_TYPE_FAST,
@ -130,7 +130,7 @@ void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) {
fRuleString = UnicodeString::fromUTF8(StringPiece(fRuleSource, fHeader->fRuleSourceLen));
U_ASSERT(data->fRuleSourceLen > 0);
fRuleStatusTable = (int32_t *)((char *)data + fHeader->fStatusTable);
fRuleStatusTable = reinterpret_cast<const int32_t*>(reinterpret_cast<const char*>(data) + fHeader->fStatusTable);
fStatusMaxIdx = data->fStatusTableLen / sizeof(int32_t);
fRefCount = 1;

View file

@ -103,7 +103,7 @@ RBBIRuleBuilder::~RBBIRuleBuilder() {
int i;
for (i=0; ; i++) {
RBBINode *n = (RBBINode *)fUSetNodes->elementAt(i);
RBBINode* n = static_cast<RBBINode*>(fUSetNodes->elementAt(i));
if (n==nullptr) {
break;
}
@ -182,12 +182,12 @@ RBBIDataHeader *RBBIRuleBuilder::flattenData() {
}
#endif
RBBIDataHeader *data = (RBBIDataHeader *)uprv_malloc(totalSize);
if (data == nullptr) {
LocalMemory<RBBIDataHeader> data(static_cast<RBBIDataHeader*>(uprv_malloc(totalSize)));
if (data.isNull()) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
}
uprv_memset(data, 0, totalSize);
uprv_memset(data.getAlias(), 0, totalSize);
data->fMagic = 0xb1a0;
@ -213,23 +213,23 @@ RBBIDataHeader *RBBIRuleBuilder::flattenData() {
uprv_memset(data->fReserved, 0, sizeof(data->fReserved));
fForwardTable->exportTable((uint8_t *)data + data->fFTable);
fForwardTable->exportSafeTable((uint8_t *)data + data->fRTable);
fSetBuilder->serializeTrie ((uint8_t *)data + data->fTrie);
fForwardTable->exportTable(reinterpret_cast<uint8_t*>(data.getAlias()) + data->fFTable);
fForwardTable->exportSafeTable(reinterpret_cast<uint8_t*>(data.getAlias()) + data->fRTable);
fSetBuilder->serializeTrie(reinterpret_cast<uint8_t*>(data.getAlias()) + data->fTrie);
int32_t *ruleStatusTable = (int32_t *)((uint8_t *)data + data->fStatusTable);
int32_t* ruleStatusTable = reinterpret_cast<int32_t*>(reinterpret_cast<uint8_t*>(data.getAlias()) + data->fStatusTable);
for (i=0; i<fRuleStatusVals->size(); i++) {
ruleStatusTable[i] = fRuleStatusVals->elementAti(i);
}
u_strToUTF8WithSub((char *)data+data->fRuleSource, rulesSize, &rulesLengthInUTF8,
u_strToUTF8WithSub(reinterpret_cast<char*>(data.getAlias()) + data->fRuleSource, rulesSize, &rulesLengthInUTF8,
fStrippedRules.getBuffer(), fStrippedRules.length(),
0xfffd, nullptr, fStatus);
if (U_FAILURE(*fStatus)) {
return nullptr;
}
return data;
return data.orphan();
}

View file

@ -748,7 +748,7 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
// First check whether we've already cached a set for this string.
// If so, just use the cached set in the new node.
// delete any set provided by the caller, since we own it.
el = (RBBISetTableEl *)uhash_get(fSetTable, &s);
el = static_cast<RBBISetTableEl*>(uhash_get(fSetTable, &s));
if (el != nullptr) {
delete setToAdopt;
node->fLeftChild = el->val;
@ -794,7 +794,7 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
//
// Add the new set to the set hash table.
//
el = (RBBISetTableEl *)uprv_malloc(sizeof(RBBISetTableEl));
el = static_cast<RBBISetTableEl*>(uprv_malloc(sizeof(RBBISetTableEl)));
UnicodeString *tkey = new UnicodeString(s);
if (tkey == nullptr || el == nullptr || setToAdopt == nullptr) {
// Delete to avoid memory leak
@ -864,7 +864,7 @@ UChar32 RBBIRuleScanner::nextCharLL() {
UChar32 ch;
if (fNextIndex >= fRB->fRules.length()) {
return (UChar32)-1;
return static_cast<UChar32>(-1);
}
ch = fRB->fRules.char32At(fNextIndex);
if (U_IS_SURROGATE(ch)) {
@ -939,7 +939,7 @@ void RBBIRuleScanner::nextChar(RBBIRuleChar &c) {
}
}
if (c.fChar == (UChar32)-1) {
if (c.fChar == static_cast<UChar32>(-1)) {
return;
}
if (fQuoteMode) {
@ -958,7 +958,7 @@ void RBBIRuleScanner::nextChar(RBBIRuleChar &c) {
int32_t commentStart = fScanIndex;
for (;;) {
c.fChar = nextCharLL();
if (c.fChar == (UChar32)-1 || // EOF
if (c.fChar == static_cast<UChar32>(-1) || // EOF
c.fChar == chCR ||
c.fChar == chLF ||
c.fChar == chNEL ||
@ -968,7 +968,7 @@ void RBBIRuleScanner::nextChar(RBBIRuleChar &c) {
fRB->fStrippedRules.setCharAt(i, u' ');
}
}
if (c.fChar == (UChar32)-1) {
if (c.fChar == static_cast<UChar32>(-1)) {
return;
}
@ -1065,14 +1065,14 @@ void RBBIRuleScanner::parse() {
// Table row specified "escaped P" and the char is either 'p' or 'P'.
break;
}
if (tableEl->fCharClass == 252 && fC.fChar == (UChar32)-1) {
if (tableEl->fCharClass == 252 && fC.fChar == static_cast<UChar32>(-1)) {
// Table row specified eof and we hit eof on the input.
break;
}
if (tableEl->fCharClass >= 128 && tableEl->fCharClass < 240 && // Table specs a char class &&
fC.fEscaped == false && // char is not escaped &&
fC.fChar != (UChar32)-1) { // char is not EOF
fC.fChar != static_cast<UChar32>(-1)) { // char is not EOF
U_ASSERT((tableEl->fCharClass-128) < UPRV_LENGTHOF(fRuleSets));
if (fRuleSets[tableEl->fCharClass-128].contains(fC.fChar)) {
// Table row specified a character class, or set of characters,
@ -1090,7 +1090,7 @@ void RBBIRuleScanner::parse() {
// We've found the row of the state table that matches the current input
// character from the rules string.
// Perform any action specified by this row in the state table.
if (doParseActions((int32_t)tableEl->fAction) == false) {
if (doParseActions(static_cast<int32_t>(tableEl->fAction)) == false) {
// Break out of the state machine loop if the
// the action signalled some kind of error, or
// the action was to exit, occurs on normal end-of-rules-input.

View file

@ -120,7 +120,7 @@ void RBBISetBuilder::buildRanges() {
//
int ni;
for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
usetNode = static_cast<RBBINode*>(this->fRB->fUSetNodes->elementAt(ni));
if (usetNode==nullptr) {
break;
}
@ -251,7 +251,7 @@ void RBBISetBuilder::buildRanges() {
UnicodeString eofString(u"eof");
UnicodeString bofString(u"bof");
for (ni=0; ; ni++) { // Loop over each of the UnicodeSets encountered in the input rules
usetNode = (RBBINode *)this->fRB->fUSetNodes->elementAt(ni);
usetNode = static_cast<RBBINode*>(this->fRB->fUSetNodes->elementAt(ni));
if (usetNode==nullptr) {
break;
}
@ -369,7 +369,7 @@ void RBBISetBuilder::addValToSets(UVector *sets, uint32_t val) {
int32_t ix;
for (ix=0; ix<sets->size(); ix++) {
RBBINode *usetNode = (RBBINode *)sets->elementAt(ix);
RBBINode* usetNode = static_cast<RBBINode*>(sets->elementAt(ix));
addValToSet(usetNode, val);
}
}
@ -380,7 +380,7 @@ void RBBISetBuilder::addValToSet(RBBINode *usetNode, uint32_t val) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;
}
leafNode->fVal = (unsigned short)val;
leafNode->fVal = static_cast<unsigned short>(val);
if (usetNode->fLeftChild == nullptr) {
usetNode->fLeftChild = leafNode;
leafNode->fParent = usetNode;
@ -441,7 +441,7 @@ UBool RBBISetBuilder::sawBOF() const {
//------------------------------------------------------------------------
UChar32 RBBISetBuilder::getFirstChar(int32_t category) const {
RangeDescriptor *rlRange;
UChar32 retVal = (UChar32)-1;
UChar32 retVal = static_cast<UChar32>(-1);
for (rlRange = fRangeList; rlRange!=nullptr; rlRange=rlRange->fNext) {
if (rlRange->fNum == category) {
retVal = rlRange->fStartChar;
@ -674,7 +674,7 @@ void RangeDescriptor::split(UChar32 where, UErrorCode &status) {
bool RangeDescriptor::isDictionaryRange() {
static const char16_t *dictionary = u"dictionary";
for (int32_t i=0; i<fIncludesSets->size(); i++) {
RBBINode *usetNode = (RBBINode *)fIncludesSets->elementAt(i);
RBBINode* usetNode = static_cast<RBBINode*>(fIncludesSets->elementAt(i));
RBBINode *setRef = usetNode->fParent;
if (setRef != nullptr) {
RBBINode *varRef = setRef->fParent;

View file

@ -41,7 +41,7 @@ U_CDECL_END
U_NAMESPACE_BEGIN
RBBISymbolTable::RBBISymbolTable(RBBIRuleScanner *rs, const UnicodeString &rules, UErrorCode &status)
:fRules(rules), fRuleScanner(rs), ffffString(char16_t(0xffff))
: fRules(rules), fRuleScanner(rs), ffffString(static_cast<char16_t>(0xffff))
{
fHashTable = nullptr;
fCachedSetLookup = nullptr;
@ -76,9 +76,9 @@ const UnicodeString *RBBISymbolTable::lookup(const UnicodeString& s) const
RBBINode *exprNode;
RBBINode *usetNode;
const UnicodeString *retString;
RBBISymbolTable *This = (RBBISymbolTable *)this; // cast off const
RBBISymbolTable *This = const_cast<RBBISymbolTable*>(this); // cast off const
el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &s);
el = static_cast<RBBISymbolTableEntry*>(uhash_get(fHashTable, &s));
if (el == nullptr) {
return nullptr;
}
@ -119,7 +119,7 @@ const UnicodeString *RBBISymbolTable::lookup(const UnicodeString& s) const
const UnicodeFunctor *RBBISymbolTable::lookupMatcher(UChar32 ch) const
{
UnicodeSet *retVal = nullptr;
RBBISymbolTable *This = (RBBISymbolTable *)this; // cast off const
RBBISymbolTable *This = const_cast<RBBISymbolTable*>(this); // cast off const
if (ch == 0xffff) {
retVal = fCachedSetLookup;
This->fCachedSetLookup = nullptr;
@ -170,7 +170,7 @@ RBBINode *RBBISymbolTable::lookupNode(const UnicodeString &key) const{
RBBINode *retNode = nullptr;
RBBISymbolTableEntry *el;
el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key);
el = static_cast<RBBISymbolTableEntry*>(uhash_get(fHashTable, &key));
if (el != nullptr) {
retNode = el->val;
}
@ -190,7 +190,7 @@ void RBBISymbolTable::addEntry (const UnicodeString &key, RBBINode *
if (U_FAILURE(err)) {
return;
}
e = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key);
e = static_cast<RBBISymbolTableEntry*>(uhash_get(fHashTable, &key));
if (e != nullptr) {
err = U_BRK_VARIABLE_REDFINITION;
return;

View file

@ -51,7 +51,7 @@ RBBITableBuilder::RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode, UEr
RBBITableBuilder::~RBBITableBuilder() {
int i;
for (i=0; i<fDStates->size(); i++) {
delete (RBBIStateDescriptor *)fDStates->elementAt(i);
delete static_cast<RBBIStateDescriptor*>(fDStates->elementAt(i));
}
delete fDStates;
delete fSafeTable;
@ -361,8 +361,8 @@ void RBBITableBuilder::calcFollowPos(RBBINode *n) {
UVector *LastPosOfLeftChild = n->fLeftChild->fLastPosSet;
for (ix=0; ix<(uint32_t)LastPosOfLeftChild->size(); ix++) {
i = (RBBINode *)LastPosOfLeftChild->elementAt(ix);
for (ix = 0; ix < static_cast<uint32_t>(LastPosOfLeftChild->size()); ix++) {
i = static_cast<RBBINode*>(LastPosOfLeftChild->elementAt(ix));
setAdd(i->fFollowPos, n->fRightChild->fFirstPosSet);
}
}
@ -373,8 +373,8 @@ void RBBITableBuilder::calcFollowPos(RBBINode *n) {
RBBINode *i; // again, n and i are the names from Aho's description.
uint32_t ix;
for (ix=0; ix<(uint32_t)n->fLastPosSet->size(); ix++) {
i = (RBBINode *)n->fLastPosSet->elementAt(ix);
for (ix = 0; ix < static_cast<uint32_t>(n->fLastPosSet->size()); ix++) {
i = static_cast<RBBINode*>(n->fLastPosSet->elementAt(ix));
setAdd(i->fFollowPos, n->fFirstPosSet);
}
}
@ -445,7 +445,7 @@ void RBBITableBuilder::calcChainedFollowPos(RBBINode *tree, RBBINode *endMarkNod
int32_t startNodeIx;
for (endNodeIx=0; endNodeIx<leafNodes.size(); endNodeIx++) {
RBBINode *endNode = (RBBINode *)leafNodes.elementAt(endNodeIx);
RBBINode* endNode = static_cast<RBBINode*>(leafNodes.elementAt(endNodeIx));
// Identify leaf nodes that correspond to overall rule match positions.
// These include the endMarkNode in their followPos sets.
@ -465,7 +465,7 @@ void RBBITableBuilder::calcChainedFollowPos(RBBINode *tree, RBBINode *endMarkNod
// with the same char class as our ending node.
RBBINode *startNode;
for (startNodeIx = 0; startNodeIx<matchStartNodes.size(); startNodeIx++) {
startNode = (RBBINode *)matchStartNodes.elementAt(startNodeIx);
startNode = static_cast<RBBINode*>(matchStartNodes.elementAt(startNodeIx));
if (startNode->fType != RBBINode::leafChar) {
continue;
}
@ -525,7 +525,7 @@ void RBBITableBuilder::bofFixup() {
RBBINode *startNode;
int startNodeIx;
for (startNodeIx = 0; startNodeIx<matchStartNodes->size(); startNodeIx++) {
startNode = (RBBINode *)matchStartNodes->elementAt(startNodeIx);
startNode = static_cast<RBBINode*>(matchStartNodes->elementAt(startNodeIx));
if (startNode->fType != RBBINode::leafChar) {
continue;
}
@ -605,7 +605,7 @@ void RBBITableBuilder::buildStateTable() {
int32_t tx;
for (tx=1; tx<fDStates->size(); tx++) {
RBBIStateDescriptor *temp;
temp = (RBBIStateDescriptor *)fDStates->elementAt(tx);
temp = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(tx));
if (temp->fMarked == false) {
T = temp;
break;
@ -628,7 +628,7 @@ void RBBITableBuilder::buildStateTable() {
RBBINode *p;
int32_t px;
for (px=0; px<T->fPositions->size(); px++) {
p = (RBBINode *)T->fPositions->elementAt(px);
p = static_cast<RBBINode*>(T->fPositions->elementAt(px));
if ((p->fType == RBBINode::leafChar) && (p->fVal == a)) {
if (U == nullptr) {
U = new UVector(*fStatus);
@ -649,7 +649,7 @@ void RBBITableBuilder::buildStateTable() {
int ix;
for (ix=0; ix<fDStates->size(); ix++) {
RBBIStateDescriptor *temp2;
temp2 = (RBBIStateDescriptor *)fDStates->elementAt(ix);
temp2 = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(ix));
if (setEquals(U, temp2->fPositions)) {
delete U;
U = temp2->fPositions;
@ -705,7 +705,7 @@ void RBBITableBuilder::mapLookAheadRules() {
fLookAheadRuleMap->setSize(fRB->fScanner->numRules() + 1);
for (int32_t n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
int32_t laSlotForState = 0;
// Establish the look-ahead slot for this state, if the state covers
@ -789,9 +789,9 @@ void RBBITableBuilder::flagAcceptingStates() {
}
for (i=0; i<endMarkerNodes.size(); i++) {
endMarker = (RBBINode *)endMarkerNodes.elementAt(i);
endMarker = static_cast<RBBINode*>(endMarkerNodes.elementAt(i));
for (n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
if (sd->fPositions->indexOf(endMarker) >= 0) {
// Any non-zero value for fAccepting means this is an accepting node.
// The value is what will be returned to the user as the break status.
@ -837,11 +837,11 @@ void RBBITableBuilder::flagLookAheadStates() {
return;
}
for (i=0; i<lookAheadNodes.size(); i++) {
lookAheadNode = (RBBINode *)lookAheadNodes.elementAt(i);
lookAheadNode = static_cast<RBBINode*>(lookAheadNodes.elementAt(i));
U_ASSERT(lookAheadNode->fType == RBBINode::NodeType::lookAhead);
for (n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
int32_t positionsIdx = sd->fPositions->indexOf(lookAheadNode);
if (positionsIdx >= 0) {
U_ASSERT(lookAheadNode == sd->fPositions->elementAt(positionsIdx));
@ -882,10 +882,10 @@ void RBBITableBuilder::flagTaggedStates() {
return;
}
for (i=0; i<tagNodes.size(); i++) { // For each tag node t (all of 'em)
tagNode = (RBBINode *)tagNodes.elementAt(i);
tagNode = static_cast<RBBINode*>(tagNodes.elementAt(i));
for (n=0; n<fDStates->size(); n++) { // For each state s (row in the state table)
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
if (sd->fPositions->indexOf(tagNode) >= 0) { // if s include the tag node t
sortedAdd(&sd->fTagVals, tagNode->fVal);
}
@ -923,12 +923,12 @@ void RBBITableBuilder::mergeRuleStatusVals() {
// We will need this as a default, for rule sets with no explicit tagging.
if (fRB->fRuleStatusVals->size() == 0) {
fRB->fRuleStatusVals->addElement(1, *fStatus); // Num of statuses in group
fRB->fRuleStatusVals->addElement((int32_t)0, *fStatus); // and our single status of zero
fRB->fRuleStatusVals->addElement(static_cast<int32_t>(0), *fStatus); // and our single status of zero
}
// For each state
for (n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(n));
UVector *thisStatesTagValues = sd->fTagVals;
if (thisStatesTagValues == nullptr) {
// No tag values are explicitly associated with this state.
@ -1154,9 +1154,9 @@ bool RBBITableBuilder::findDuplCharClassFrom(IntPair *categories) {
uint16_t table_base = 0;
uint16_t table_dupl = 1;
for (int32_t state=0; state<numStates; state++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state);
table_base = (uint16_t)sd->fDtran->elementAti(categories->first);
table_dupl = (uint16_t)sd->fDtran->elementAti(categories->second);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(state));
table_base = static_cast<uint16_t>(sd->fDtran->elementAti(categories->first));
table_dupl = static_cast<uint16_t>(sd->fDtran->elementAti(categories->second));
if (table_base != table_dupl) {
break;
}
@ -1176,7 +1176,7 @@ bool RBBITableBuilder::findDuplCharClassFrom(IntPair *categories) {
void RBBITableBuilder::removeColumn(int32_t column) {
int32_t numStates = fDStates->size();
for (int32_t state=0; state<numStates; state++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(state));
U_ASSERT(column < sd->fDtran->size());
sd->fDtran->removeElementAt(column);
}
@ -1190,9 +1190,9 @@ bool RBBITableBuilder::findDuplicateState(IntPair *states) {
int32_t numCols = fRB->fSetBuilder->getNumCharCategories();
for (; states->first<numStates-1; states->first++) {
RBBIStateDescriptor *firstSD = (RBBIStateDescriptor *)fDStates->elementAt(states->first);
RBBIStateDescriptor* firstSD = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(states->first));
for (states->second=states->first+1; states->second<numStates; states->second++) {
RBBIStateDescriptor *duplSD = (RBBIStateDescriptor *)fDStates->elementAt(states->second);
RBBIStateDescriptor* duplSD = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(states->second));
if (firstSD->fAccepting != duplSD->fAccepting ||
firstSD->fLookAhead != duplSD->fLookAhead ||
firstSD->fTagsIdx != duplSD->fTagsIdx) {
@ -1252,14 +1252,14 @@ void RBBITableBuilder::removeState(IntPair duplStates) {
U_ASSERT(keepState < duplState);
U_ASSERT(duplState < fDStates->size());
RBBIStateDescriptor *duplSD = (RBBIStateDescriptor *)fDStates->elementAt(duplState);
RBBIStateDescriptor* duplSD = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(duplState));
fDStates->removeElementAt(duplState);
delete duplSD;
int32_t numStates = fDStates->size();
int32_t numCols = fRB->fSetBuilder->getNumCharCategories();
for (int32_t state=0; state<numStates; ++state) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(state));
for (int32_t col=0; col<numCols; col++) {
int32_t existingVal = sd->fDtran->elementAti(col);
int32_t newVal = existingVal;
@ -1283,7 +1283,7 @@ void RBBITableBuilder::removeSafeState(IntPair duplStates) {
// and will auto-delete the removed element.
int32_t numStates = fSafeTable->size();
for (int32_t state=0; state<numStates; ++state) {
UnicodeString *sd = (UnicodeString *)fSafeTable->elementAt(state);
UnicodeString* sd = static_cast<UnicodeString*>(fSafeTable->elementAt(state));
int32_t numCols = sd->length();
for (int32_t col=0; col<numCols; col++) {
int32_t existingVal = sd->charAt(col);
@ -1357,7 +1357,7 @@ bool RBBITableBuilder::use8BitsForTable() const {
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::exportTable(void *where) {
RBBIStateTable *table = (RBBIStateTable *)where;
RBBIStateTable* table = static_cast<RBBIStateTable*>(where);
uint32_t state;
int col;
@ -1390,13 +1390,13 @@ void RBBITableBuilder::exportTable(void *where) {
}
for (state=0; state<table->fNumStates; state++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(state);
RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen);
RBBIStateDescriptor* sd = static_cast<RBBIStateDescriptor*>(fDStates->elementAt(state));
RBBIStateTableRow* row = reinterpret_cast<RBBIStateTableRow*>(table->fTableData + state * table->fRowLen);
if (use8BitsForTable()) {
U_ASSERT (sd->fAccepting <= 255);
U_ASSERT (sd->fLookAhead <= 255);
U_ASSERT (0 <= sd->fTagsIdx && sd->fTagsIdx <= 255);
RBBIStateTableRow8 *r8 = (RBBIStateTableRow8*)row;
RBBIStateTableRow8* r8 = reinterpret_cast<RBBIStateTableRow8*>(row);
r8->fAccepting = sd->fAccepting;
r8->fLookAhead = sd->fLookAhead;
r8->fTagsIdx = sd->fTagsIdx;
@ -1472,8 +1472,8 @@ void RBBITableBuilder::buildSafeReverseTable(UErrorCode &status) {
}
}
if (wantedEndState == endState) {
safePairs.append((char16_t)c1);
safePairs.append((char16_t)c2);
safePairs.append(static_cast<char16_t>(c1));
safePairs.append(static_cast<char16_t>(c2));
// printf("(%d, %d) ", c1, c2);
}
}
@ -1579,7 +1579,7 @@ bool RBBITableBuilder::use8BitsForSafeTable() const {
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::exportSafeTable(void *where) {
RBBIStateTable *table = (RBBIStateTable *)where;
RBBIStateTable* table = static_cast<RBBIStateTable*>(where);
uint32_t state;
int col;
@ -1604,10 +1604,10 @@ void RBBITableBuilder::exportSafeTable(void *where) {
}
for (state=0; state<table->fNumStates; state++) {
UnicodeString *rowString = (UnicodeString *)fSafeTable->elementAt(state);
RBBIStateTableRow *row = (RBBIStateTableRow *)(table->fTableData + state*table->fRowLen);
UnicodeString* rowString = static_cast<UnicodeString*>(fSafeTable->elementAt(state));
RBBIStateTableRow* row = reinterpret_cast<RBBIStateTableRow*>(table->fTableData + state * table->fRowLen);
if (use8BitsForSafeTable()) {
RBBIStateTableRow8 *r8 = (RBBIStateTableRow8*)row;
RBBIStateTableRow8* r8 = reinterpret_cast<RBBIStateTableRow8*>(row);
r8->fAccepting = 0;
r8->fLookAhead = 0;
r8->fTagsIdx = 0;

View file

@ -49,7 +49,7 @@ ResourceBundle::constructForLocale(const UnicodeString& path,
}
else {
UnicodeString nullTerminatedPath(path);
nullTerminatedPath.append((char16_t)0);
nullTerminatedPath.append(static_cast<char16_t>(0));
fResource = ures_openU(nullTerminatedPath.getBuffer(), locale.getName(), &error);
}
}

View file

@ -139,7 +139,7 @@ UChar32 RuleCharacterIterator::_current() const {
return buf->char32At(bufPos);
} else {
int i = pos.getIndex();
return (i < text.length()) ? text.char32At(i) : (UChar32)DONE;
return (i < text.length()) ? text.char32At(i) : static_cast<UChar32>(DONE);
}
}

View file

@ -424,7 +424,7 @@ ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUSer
return handleDefault(key, actualReturn, status);
}
ICUService* ncthis = (ICUService*)this; // cast away semantic const
ICUService* ncthis = const_cast<ICUService*>(this); // cast away semantic const
CacheEntry* result = nullptr;
{
@ -462,7 +462,7 @@ ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUSer
if (factory != nullptr) {
for (int32_t i = 0; i < limit; ++i) {
if (factory == (const ICUServiceFactory*)factories->elementAt(i)) {
if (factory == static_cast<const ICUServiceFactory*>(factories->elementAt(i))) {
startIndex = i + 1;
break;
}
@ -478,7 +478,7 @@ ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUSer
do {
currentDescriptor.remove();
key.currentDescriptor(currentDescriptor);
result = (CacheEntry*)serviceCache->get(currentDescriptor);
result = static_cast<CacheEntry*>(serviceCache->get(currentDescriptor));
if (result != nullptr) {
break;
}
@ -490,7 +490,7 @@ ICUService::getKey(ICUServiceKey& key, UnicodeString* actualReturn, const ICUSer
int32_t index = startIndex;
while (index < limit) {
ICUServiceFactory* f = (ICUServiceFactory*)factories->elementAt(index++);
ICUServiceFactory* f = static_cast<ICUServiceFactory*>(factories->elementAt(index++));
LocalPointer<UObject> service(f->create(key, this, status));
if (U_FAILURE(status)) {
return nullptr;
@ -543,7 +543,7 @@ outerEnd:
if (cacheDescriptorList.isValid()) {
for (int32_t i = cacheDescriptorList->size(); --i >= 0;) {
UnicodeString* desc = (UnicodeString*)cacheDescriptorList->elementAt(i);
UnicodeString* desc = static_cast<UnicodeString*>(cacheDescriptorList->elementAt(i));
serviceCache->put(*desc, result, status);
if (U_FAILURE(status)) {
@ -558,7 +558,7 @@ outerEnd:
if (actualReturn != nullptr) {
// strip null prefix
if (result->actualDescriptor.indexOf((char16_t)0x2f) == 0) { // U+002f=slash (/)
if (result->actualDescriptor.indexOf(static_cast<char16_t>(0x2f)) == 0) { // U+002f=slash (/)
actualReturn->remove();
actualReturn->append(result->actualDescriptor,
1,
@ -618,7 +618,7 @@ ICUService::getVisibleIDs(UVector& result, const UnicodeString* matchID, UErrorC
break;
}
const UnicodeString* id = (const UnicodeString*)e->key.pointer;
const UnicodeString* id = static_cast<const UnicodeString*>(e->key.pointer);
if (fallbackKey != nullptr) {
if (!fallbackKey->isFallbackOf(*id)) {
continue;
@ -644,14 +644,14 @@ ICUService::getVisibleIDMap(UErrorCode& status) const {
// must only be called when lock is already held
ICUService* ncthis = (ICUService*)this; // cast away semantic const
ICUService* ncthis = const_cast<ICUService*>(this); // cast away semantic const
if (idCache == nullptr) {
ncthis->idCache = new Hashtable(status);
if (idCache == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
} else if (factories != nullptr) {
for (int32_t pos = factories->size(); --pos >= 0;) {
ICUServiceFactory* f = (ICUServiceFactory*)factories->elementAt(pos);
ICUServiceFactory* f = static_cast<ICUServiceFactory*>(factories->elementAt(pos));
f->updateVisibleIDs(*idCache, status);
}
if (U_FAILURE(status)) {
@ -679,7 +679,7 @@ ICUService::getDisplayName(const UnicodeString& id, UnicodeString& result, const
Mutex mutex(&lock);
const Hashtable* map = getVisibleIDMap(status);
if (map != nullptr) {
ICUServiceFactory* f = (ICUServiceFactory*)map->get(id);
ICUServiceFactory* f = static_cast<ICUServiceFactory*>(map->get(id));
if (f != nullptr) {
f->getDisplayName(id, locale, result);
return result;
@ -691,7 +691,7 @@ ICUService::getDisplayName(const UnicodeString& id, UnicodeString& result, const
while (fallbackKey != nullptr && fallbackKey->fallback()) {
UnicodeString us;
fallbackKey->currentID(us);
f = (ICUServiceFactory*)map->get(us);
f = static_cast<ICUServiceFactory*>(map->get(us));
if (f != nullptr) {
f->getDisplayName(id, locale, result);
delete fallbackKey;
@ -727,7 +727,7 @@ ICUService::getDisplayNames(UVector& result,
result.removeAllElements();
result.setDeleter(userv_deleteStringPair);
if (U_SUCCESS(status)) {
ICUService* ncthis = (ICUService*)this; // cast away semantic const
ICUService* ncthis = const_cast<ICUService*>(this); // cast away semantic const
Mutex mutex(&lock);
if (dnCache != nullptr && dnCache->locale != locale) {
@ -749,8 +749,8 @@ ICUService::getDisplayNames(UVector& result,
int32_t pos = UHASH_FIRST;
const UHashElement* entry = nullptr;
while ((entry = m->nextElement(pos)) != nullptr) {
const UnicodeString* id = (const UnicodeString*)entry->key.pointer;
ICUServiceFactory* f = (ICUServiceFactory*)entry->value.pointer;
const UnicodeString* id = static_cast<const UnicodeString*>(entry->key.pointer);
ICUServiceFactory* f = static_cast<ICUServiceFactory*>(entry->value.pointer);
UnicodeString dname;
f->getDisplayName(*id, locale, dname);
if (dname.isBogus()) {
@ -776,11 +776,11 @@ ICUService::getDisplayNames(UVector& result,
int32_t pos = UHASH_FIRST;
const UHashElement *entry = nullptr;
while ((entry = dnCache->cache.nextElement(pos)) != nullptr) {
const UnicodeString* id = (const UnicodeString*)entry->value.pointer;
const UnicodeString* id = static_cast<const UnicodeString*>(entry->value.pointer);
if (matchKey != nullptr && !matchKey->isFallbackOf(*id)) {
continue;
}
const UnicodeString* dn = (const UnicodeString*)entry->key.pointer;
const UnicodeString* dn = static_cast<const UnicodeString*>(entry->key.pointer);
StringPair* sp = StringPair::create(*id, *dn, status);
result.adoptElement(sp, status);
if (U_FAILURE(status)) {

View file

@ -76,7 +76,7 @@ LocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
const UHashElement* elem = nullptr;
int32_t pos = UHASH_FIRST;
while ((elem = supported->nextElement(pos)) != nullptr) {
const UnicodeString& id = *((const UnicodeString*)elem->key.pointer);
const UnicodeString& id = *static_cast<const UnicodeString*>(elem->key.pointer);
if (!visible) {
result.remove(id);
} else {

View file

@ -179,7 +179,7 @@ private:
length = other._ids.size();
for(i = 0; i < length; ++i) {
LocalPointer<UnicodeString> clonedId(((UnicodeString *)other._ids.elementAt(i))->clone(), status);
LocalPointer<UnicodeString> clonedId(static_cast<UnicodeString*>(other._ids.elementAt(i))->clone(), status);
_ids.adoptElement(clonedId.orphan(), status);
}
@ -228,7 +228,7 @@ public:
virtual const UnicodeString* snext(UErrorCode& status) override {
if (upToDate(status) && (_pos < _ids.size())) {
return (const UnicodeString*)_ids[_pos++];
return static_cast<const UnicodeString*>(_ids[_pos++]);
}
return nullptr;
}
@ -263,7 +263,7 @@ const UnicodeString&
ICULocaleService::validateFallbackLocale() const
{
const Locale& loc = Locale::getDefault();
ICULocaleService* ncThis = (ICULocaleService*)this;
ICULocaleService* ncThis = const_cast<ICULocaleService*>(this);
static UMutex llock;
{
Mutex mutex(&llock);

View file

@ -56,7 +56,7 @@ ICUNotifier::addListener(const EventListener* l, UErrorCode& status)
listeners = lpListeners.orphan();
} else {
for (int i = 0, e = listeners->size(); i < e; ++i) {
const EventListener* el = (const EventListener*)(listeners->elementAt(i));
const EventListener* el = static_cast<const EventListener*>(listeners->elementAt(i));
if (l == el) {
return;
}
@ -88,7 +88,7 @@ ICUNotifier::removeListener(const EventListener *l, UErrorCode& status)
if (listeners != nullptr) {
// identity equality check
for (int i = 0, e = listeners->size(); i < e; ++i) {
const EventListener* el = (const EventListener*)listeners->elementAt(i);
const EventListener* el = static_cast<const EventListener*>(listeners->elementAt(i));
if (l == el) {
listeners->removeElementAt(i);
if (listeners->size() == 0) {
@ -109,7 +109,7 @@ ICUNotifier::notifyChanged()
Mutex lmx(&notifyLock);
if (listeners != nullptr) {
for (int i = 0, e = listeners->size(); i < e; ++i) {
EventListener* el = (EventListener*)listeners->elementAt(i);
EventListener* el = static_cast<EventListener*>(listeners->elementAt(i));
notifyListener(*el);
}
}

View file

@ -61,8 +61,8 @@ ICUResourceBundleFactory::handleCreate(const Locale& loc, int32_t /* kind */, co
// who made this change? -- dlf
char pkg[20];
int32_t length;
length=_bundleName.extract(0, INT32_MAX, pkg, (int32_t)sizeof(pkg), US_INV);
if(length>=(int32_t)sizeof(pkg)) {
length = _bundleName.extract(0, INT32_MAX, pkg, static_cast<int32_t>(sizeof(pkg)), US_INV);
if (length >= static_cast<int32_t>(sizeof(pkg))) {
return nullptr;
}
return new ResourceBundle(pkg, loc, status);

View file

@ -73,7 +73,7 @@ UBool SimpleFormatter::applyPatternMinMaxArguments(
const char16_t *patternBuffer = pattern.getBuffer();
int32_t patternLength = pattern.length();
// Reserve the first char for the number of arguments.
compiledPattern.setTo((char16_t)0);
compiledPattern.setTo(static_cast<char16_t>(0));
int32_t textLength = 0;
int32_t maxArg = -1;
UBool inQuote = false;
@ -98,7 +98,7 @@ UBool SimpleFormatter::applyPatternMinMaxArguments(
} else if (!inQuote && c == OPEN_BRACE) {
if (textLength > 0) {
compiledPattern.setCharAt(compiledPattern.length() - textLength - 1,
(char16_t)(ARG_NUM_LIMIT + textLength));
static_cast<char16_t>(ARG_NUM_LIMIT + textLength));
textLength = 0;
}
int32_t argNumber;
@ -129,7 +129,7 @@ UBool SimpleFormatter::applyPatternMinMaxArguments(
if (argNumber > maxArg) {
maxArg = argNumber;
}
compiledPattern.append((char16_t)argNumber);
compiledPattern.append(static_cast<char16_t>(argNumber));
continue;
} // else: c is part of literal text
// Append c and track the literal-text segment length.
@ -144,14 +144,14 @@ UBool SimpleFormatter::applyPatternMinMaxArguments(
}
if (textLength > 0) {
compiledPattern.setCharAt(compiledPattern.length() - textLength - 1,
(char16_t)(ARG_NUM_LIMIT + textLength));
static_cast<char16_t>(ARG_NUM_LIMIT + textLength));
}
int32_t argCount = maxArg + 1;
if (argCount < min || max < argCount) {
errorCode = U_ILLEGAL_ARGUMENT_ERROR;
return false;
}
compiledPattern.setCharAt(0, (char16_t)argCount);
compiledPattern.setCharAt(0, static_cast<char16_t>(argCount));
return true;
}

View file

@ -328,7 +328,7 @@ StringTrieBuilder::registerNode(Node *newNode, UErrorCode &errorCode) {
const UHashElement *old=uhash_find(nodes, newNode);
if(old!=nullptr) {
delete newNode;
return (Node *)old->key.pointer;
return static_cast<Node*>(old->key.pointer);
}
// If uhash_puti() returns a non-zero value from an equivalent, previously
// registered node, then uhash_find() failed to find that and we will leak newNode.
@ -352,7 +352,7 @@ StringTrieBuilder::registerFinalValue(int32_t value, UErrorCode &errorCode) {
FinalValueNode key(value);
const UHashElement *old=uhash_find(nodes, &key);
if(old!=nullptr) {
return (Node *)old->key.pointer;
return static_cast<Node*>(old->key.pointer);
}
Node *newNode=new FinalValueNode(value);
if(newNode==nullptr) {
@ -375,12 +375,12 @@ StringTrieBuilder::registerFinalValue(int32_t value, UErrorCode &errorCode) {
int32_t
StringTrieBuilder::hashNode(const void *node) {
return ((const Node *)node)->hashCode();
return static_cast<const Node*>(node)->hashCode();
}
UBool
StringTrieBuilder::equalNodes(const void *left, const void *right) {
return *(const Node *)left==*(const Node *)right;
return *static_cast<const Node*>(left) == *static_cast<const Node*>(right);
}
bool

View file

@ -304,7 +304,7 @@ ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode) UPRV_N
if ((pBiDi!=nullptr) && (reorderingMode >= UBIDI_REORDER_DEFAULT)
&& (reorderingMode < UBIDI_REORDER_COUNT)) {
pBiDi->reorderingMode = reorderingMode;
pBiDi->isInverse = (UBool)(reorderingMode == UBIDI_REORDER_INVERSE_NUMBERS_AS_L);
pBiDi->isInverse = reorderingMode == UBIDI_REORDER_INVERSE_NUMBERS_AS_L;
}
}
@ -381,7 +381,7 @@ firstL_R_AL(UBiDi *pBiDi) {
for(i=0; i<length; ) {
/* i is incremented by U16_NEXT */
U16_NEXT(text, i, length, uchar);
dirProp=(DirProp)ubidi_getCustomizedClass(pBiDi, uchar);
dirProp = static_cast<DirProp>(ubidi_getCustomizedClass(pBiDi, uchar));
if(result==ON) {
if(dirProp==L || dirProp==R || dirProp==AL) {
result=dirProp;
@ -436,13 +436,13 @@ getDirProps(UBiDi *pBiDi) {
UBool isDefaultLevel=IS_DEFAULT_LEVEL(pBiDi->paraLevel);
/* for inverse BiDi, the default para level is set to RTL if there is a
strong R or AL character at either end of the text */
UBool isDefaultLevelInverse=isDefaultLevel && (UBool)
(pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_LIKE_DIRECT ||
pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL);
UBool isDefaultLevelInverse = isDefaultLevel && static_cast<UBool>(
pBiDi->reorderingMode == UBIDI_REORDER_INVERSE_LIKE_DIRECT ||
pBiDi->reorderingMode == UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL);
int32_t lastArabicPos=-1;
int32_t controlCount=0;
UBool removeBiDiControls = (UBool)(pBiDi->reorderingOptions &
UBIDI_OPTION_REMOVE_CONTROLS);
UBool removeBiDiControls =
static_cast<UBool>(pBiDi->reorderingOptions & UBIDI_OPTION_REMOVE_CONTROLS);
enum State {
NOT_SEEKING_STRONG, /* 0: not contextual paraLevel, not after FSI */
@ -676,7 +676,7 @@ bracketInit(UBiDi *pBiDi, BracketData *bd) {
bd->isoRuns[0].level=GET_PARALEVEL(pBiDi, 0);
UBiDiLevel t = GET_PARALEVEL(pBiDi, 0) & 1;
bd->isoRuns[0].lastStrong = bd->isoRuns[0].lastBase = t;
bd->isoRuns[0].contextDir = (UBiDiDirection)t;
bd->isoRuns[0].contextDir = static_cast<UBiDiDirection>(t);
bd->isoRuns[0].contextPos=0;
if(pBiDi->openingsMemory) {
bd->openings=pBiDi->openingsMemory;
@ -696,7 +696,7 @@ bracketProcessB(BracketData *bd, UBiDiLevel level) {
bd->isoRuns[0].limit=0;
bd->isoRuns[0].level=level;
bd->isoRuns[0].lastStrong=bd->isoRuns[0].lastBase=level&1;
bd->isoRuns[0].contextDir=(UBiDiDirection)(level&1);
bd->isoRuns[0].contextDir = static_cast<UBiDiDirection>(level & 1);
bd->isoRuns[0].contextPos=0;
}
@ -713,8 +713,8 @@ bracketProcessBoundary(BracketData *bd, int32_t lastCcPos,
pLastIsoRun->limit=pLastIsoRun->start;
pLastIsoRun->level=embeddingLevel;
pLastIsoRun->lastStrong=pLastIsoRun->lastBase=contextLevel&1;
pLastIsoRun->contextDir=(UBiDiDirection)(contextLevel&1);
pLastIsoRun->contextPos=(UBiDiDirection)lastCcPos;
pLastIsoRun->contextDir = static_cast<UBiDiDirection>(contextLevel & 1);
pLastIsoRun->contextPos = static_cast<UBiDiDirection>(lastCcPos);
}
/* LRI or RLI */
@ -729,7 +729,7 @@ bracketProcessLRI_RLI(BracketData *bd, UBiDiLevel level) {
pLastIsoRun->start=pLastIsoRun->limit=lastLimit;
pLastIsoRun->level=level;
pLastIsoRun->lastStrong=pLastIsoRun->lastBase=level&1;
pLastIsoRun->contextDir=(UBiDiDirection)(level&1);
pLastIsoRun->contextDir = static_cast<UBiDiDirection>(level & 1);
pLastIsoRun->contextPos=0;
}
@ -803,7 +803,7 @@ bracketProcessClosing(BracketData *bd, int32_t openIdx, int32_t position) {
UBool stable;
DirProp newProp;
pOpening=&bd->openings[openIdx];
direction=(UBiDiDirection)(pLastIsoRun->level&1);
direction = static_cast<UBiDiDirection>(pLastIsoRun->level & 1);
stable=true; /* assume stable until proved otherwise */
/* The stable flag is set when brackets are paired and their
@ -896,7 +896,7 @@ bracketProcessChar(BracketData *bd, int32_t position) {
break;
}
pLastIsoRun->lastBase=ON;
pLastIsoRun->contextDir=(UBiDiDirection)newProp;
pLastIsoRun->contextDir = static_cast<UBiDiDirection>(newProp);
pLastIsoRun->contextPos=position;
level=bd->pBiDi->levels[position];
if(level&UBIDI_LEVEL_OVERRIDE) { /* X4, X5 */
@ -944,14 +944,14 @@ bracketProcessChar(BracketData *bd, int32_t position) {
dirProps[position]=newProp;
pLastIsoRun->lastBase=newProp;
pLastIsoRun->lastStrong=newProp;
pLastIsoRun->contextDir=(UBiDiDirection)newProp;
pLastIsoRun->contextDir = static_cast<UBiDiDirection>(newProp);
pLastIsoRun->contextPos=position;
}
else if(dirProp<=R || dirProp==AL) {
newProp= static_cast<DirProp>(DIR_FROM_STRONG(dirProp));
pLastIsoRun->lastBase=dirProp;
pLastIsoRun->lastStrong=dirProp;
pLastIsoRun->contextDir=(UBiDiDirection)newProp;
pLastIsoRun->contextDir = static_cast<UBiDiDirection>(newProp);
pLastIsoRun->contextPos=position;
}
else if(dirProp==EN) {
@ -960,7 +960,7 @@ bracketProcessChar(BracketData *bd, int32_t position) {
newProp=L; /* W7 */
if(!bd->isNumbersSpecial)
dirProps[position]=ENL;
pLastIsoRun->contextDir=(UBiDiDirection)L;
pLastIsoRun->contextDir = static_cast<UBiDiDirection>(L);
pLastIsoRun->contextPos=position;
}
else {
@ -969,14 +969,14 @@ bracketProcessChar(BracketData *bd, int32_t position) {
dirProps[position]=AN; /* W2 */
else
dirProps[position]=ENR;
pLastIsoRun->contextDir=(UBiDiDirection)R;
pLastIsoRun->contextDir = static_cast<UBiDiDirection>(R);
pLastIsoRun->contextPos=position;
}
}
else if(dirProp==AN) {
newProp=R; /* N0 */
pLastIsoRun->lastBase=AN;
pLastIsoRun->contextDir=(UBiDiDirection)R;
pLastIsoRun->contextDir = static_cast<UBiDiDirection>(R);
pLastIsoRun->contextPos=position;
}
else if(dirProp==NSM) {
@ -1177,10 +1177,10 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
levels[i]=previousLevel;
if (dirProp==LRE || dirProp==LRO)
/* least greater even level */
newLevel=(UBiDiLevel)((embeddingLevel+2)&~(UBIDI_LEVEL_OVERRIDE|1));
newLevel = static_cast<UBiDiLevel>((embeddingLevel + 2) & ~(UBIDI_LEVEL_OVERRIDE | 1));
else
/* least greater odd level */
newLevel=(UBiDiLevel)((NO_OVERRIDE(embeddingLevel)+1)|1);
newLevel = static_cast<UBiDiLevel>((NO_OVERRIDE(embeddingLevel) + 1) | 1);
if(newLevel<=UBIDI_MAX_EXPLICIT_LEVEL && overflowIsolateCount==0 &&
overflowEmbeddingCount==0) {
lastCcPos=i;
@ -1213,7 +1213,7 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
if(stackLast>0 && stack[stackLast]<ISOLATE) { /* not an isolate entry */
lastCcPos=i;
stackLast--;
embeddingLevel=(UBiDiLevel)stack[stackLast];
embeddingLevel = static_cast<UBiDiLevel>(stack[stackLast]);
}
break;
case LRI:
@ -1229,10 +1229,10 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
/* (X5a, X5b) */
if(dirProp==LRI)
/* least greater even level */
newLevel=(UBiDiLevel)((embeddingLevel+2)&~(UBIDI_LEVEL_OVERRIDE|1));
newLevel = static_cast<UBiDiLevel>((embeddingLevel + 2) & ~(UBIDI_LEVEL_OVERRIDE | 1));
else
/* least greater odd level */
newLevel=(UBiDiLevel)((NO_OVERRIDE(embeddingLevel)+1)|1);
newLevel = static_cast<UBiDiLevel>((NO_OVERRIDE(embeddingLevel) + 1) | 1);
if(newLevel<=UBIDI_MAX_EXPLICIT_LEVEL && overflowIsolateCount==0 &&
overflowEmbeddingCount==0) {
flags|=DIRPROP_FLAG(dirProp);
@ -1276,7 +1276,7 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
} else
/* make it WS so that it is handled by adjustWSLevels() */
dirProps[i]=WS;
embeddingLevel=(UBiDiLevel)stack[stackLast]&~ISOLATE;
embeddingLevel = static_cast<UBiDiLevel>(stack[stackLast]) & ~ISOLATE;
flags|=(DIRPROP_FLAG(ON)|DIRPROP_FLAG_LR(embeddingLevel));
previousLevel=embeddingLevel;
levels[i]=NO_OVERRIDE(embeddingLevel);
@ -1315,7 +1315,7 @@ resolveExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
previousLevel=embeddingLevel;
levels[i]=embeddingLevel;
if(!bracketProcessChar(&bracketData, i))
return (UBiDiDirection)-1;
return static_cast<UBiDiDirection>(-1);
/* the dirProp may have been changed in bracketProcessChar() */
flags|=DIRPROP_FLAG(dirProps[i]);
break;
@ -1386,7 +1386,7 @@ checkExplicitLevels(UBiDi *pBiDi, UErrorCode *pErrorCode) {
} else {
// Treat explicit level 0 as a wildcard for the paragraph level.
// Avoid making the caller guess what the paragraph level would be.
level = (UBiDiLevel)currentParaLevel;
level = static_cast<UBiDiLevel>(currentParaLevel);
levels[i] = level | overrideFlag;
}
} else {
@ -1868,7 +1868,7 @@ processPropertySeq(UBiDi *pBiDi, LevState *pLevState, uint8_t _prop,
int32_t start0, k;
start0=start; /* save original start position */
oldStateSeq=(uint8_t)pLevState->state;
oldStateSeq = static_cast<uint8_t>(pLevState->state);
cell=(*pImpTab)[oldStateSeq][_prop];
pLevState->state=GET_STATE(cell); /* isolate the new state */
actionSeq=(*pImpAct)[GET_ACTION(cell)]; /* isolate the action */
@ -2076,7 +2076,7 @@ lastL_R_AL(UBiDi *pBiDi) {
for(i=length; i>0; ) {
/* i is decremented by U16_PREV */
U16_PREV(text, 0, i, uchar);
dirProp=(DirProp)ubidi_getCustomizedClass(pBiDi, uchar);
dirProp = static_cast<DirProp>(ubidi_getCustomizedClass(pBiDi, uchar));
if(dirProp==L) {
return DirProp_L;
}
@ -2104,7 +2104,7 @@ firstL_R_AL_EN_AN(UBiDi *pBiDi) {
for(i=0; i<length; ) {
/* i is incremented by U16_NEXT */
U16_NEXT(text, i, length, uchar);
dirProp=(DirProp)ubidi_getCustomizedClass(pBiDi, uchar);
dirProp = static_cast<DirProp>(ubidi_getCustomizedClass(pBiDi, uchar));
if(dirProp==L) {
return DirProp_L;
}
@ -2142,18 +2142,18 @@ resolveImplicitLevels(UBiDi *pBiDi,
* actions) and different levels state tables (maybe very similar to the
* LTR corresponding ones.
*/
inverseRTL=(UBool)
((start<pBiDi->lastArabicPos) && (GET_PARALEVEL(pBiDi, start) & 1) &&
(pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_LIKE_DIRECT ||
pBiDi->reorderingMode==UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL));
inverseRTL =
static_cast<UBool>((start < pBiDi->lastArabicPos) && (GET_PARALEVEL(pBiDi, start) & 1) &&
(pBiDi->reorderingMode == UBIDI_REORDER_INVERSE_LIKE_DIRECT ||
pBiDi->reorderingMode == UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL));
/* initialize for property and levels state tables */
levState.startL2EN=-1; /* used for INVERSE_LIKE_DIRECT_WITH_MARKS */
levState.lastStrongRTL=-1; /* used for INVERSE_LIKE_DIRECT_WITH_MARKS */
levState.runStart=start;
levState.runLevel=pBiDi->levels[start];
levState.pImpTab=(const ImpTab*)((pBiDi->pImpTabPair)->pImpTab)[levState.runLevel&1];
levState.pImpAct=(const ImpAct*)((pBiDi->pImpTabPair)->pImpAct)[levState.runLevel&1];
levState.pImpTab = static_cast<const ImpTab*>(((pBiDi->pImpTabPair)->pImpTab)[levState.runLevel & 1]);
levState.pImpAct = static_cast<const ImpAct*>(((pBiDi->pImpTabPair)->pImpAct)[levState.runLevel & 1]);
if(start==0 && pBiDi->proLength>0) {
DirProp lastStrong=lastL_R_AL(pBiDi);
if(lastStrong!=DirProp_ON) {
@ -2391,8 +2391,8 @@ setParaRunsOnly(UBiDi *pBiDi, const char16_t *text, int32_t length,
goto cleanup3;
}
visualMap=runsOnlyMemory;
visualText=(char16_t *)&visualMap[length];
saveLevels=(UBiDiLevel *)&visualText[length];
visualText = reinterpret_cast<char16_t*>(&visualMap[length]);
saveLevels = reinterpret_cast<UBiDiLevel*>(&visualText[length]);
saveOptions=pBiDi->reorderingOptions;
if(saveOptions & UBIDI_OPTION_INSERT_MARKS) {
pBiDi->reorderingOptions&=~UBIDI_OPTION_INSERT_MARKS;

View file

@ -51,7 +51,7 @@ _enumPropertyStartsRange(const void *context, UChar32 start, UChar32 end, uint32
(void)end;
(void)value;
/* add the start code point to the USet */
const USetAdder *sa=(const USetAdder *)context;
const USetAdder* sa = static_cast<const USetAdder*>(context);
sa->add(sa->set, start);
return true;
}
@ -139,7 +139,7 @@ ubidi_getClass(UChar32 c) {
U_CFUNC UBool
ubidi_isMirrored(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_IS_MIRRORED_SHIFT);
return UBIDI_GET_FLAG(props, UBIDI_IS_MIRRORED_SHIFT);
}
static UChar32
@ -183,13 +183,13 @@ ubidi_getMirror(UChar32 c) {
U_CFUNC UBool
ubidi_isBidiControl(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_BIDI_CONTROL_SHIFT);
return UBIDI_GET_FLAG(props, UBIDI_BIDI_CONTROL_SHIFT);
}
U_CFUNC UBool
ubidi_isJoinControl(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_JOIN_CONTROL_SHIFT);
return UBIDI_GET_FLAG(props, UBIDI_JOIN_CONTROL_SHIFT);
}
U_CFUNC UJoiningType

File diff suppressed because it is too large Load diff

View file

@ -233,7 +233,7 @@ updateSrc(UBiDiTransform *pTransform, const char16_t *newSrc, uint32_t newLength
uprv_free(pTransform->src);
pTransform->src = nullptr;
}
pTransform->src = (char16_t *)uprv_malloc(newSize * sizeof(char16_t));
pTransform->src = static_cast<char16_t*>(uprv_malloc(newSize * sizeof(char16_t)));
if (pTransform->src == nullptr) {
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
//pTransform->srcLength = pTransform->srcSize = 0;
@ -499,7 +499,7 @@ ubiditransform_transform(UBiDiTransform *pBiDiTransform,
/* Checking for U_SUCCESS() within the loop to bail out on first failure. */
for (action = pBiDiTransform->pActiveScheme->actions; *action && U_SUCCESS(*pErrorCode); action++) {
if ((*action)(pBiDiTransform, pErrorCode)) {
if (action + 1) {
if (action[1] != nullptr) {
updateSrc(pBiDiTransform, pBiDiTransform->dest, *pBiDiTransform->pDestLength,
*pBiDiTransform->pDestLength, pErrorCode);
}

View file

@ -501,7 +501,10 @@ ubidi_writeReordered(UBiDi *pBiDi,
destSize-=runLength;
if((pBiDi->isInverse) &&
(/*run<runCount-1 &&*/ dirProps[logicalStart+runLength-1]!=L)) {
(/*run<runCount-1 &&*/
runLength > 0 && // doWriteForward may return 0 if src
// only include bidi control chars
dirProps[logicalStart+runLength-1]!=L)) {
markFlag |= LRM_AFTER;
}
if (markFlag & LRM_AFTER) {
@ -632,7 +635,10 @@ ubidi_writeReordered(UBiDi *pBiDi,
}
destSize-=runLength;
if(/*run>0 &&*/ !(MASK_R_AL&DIRPROP_FLAG(dirProps[logicalStart+runLength-1]))) {
if(/*run>0 &&*/
runLength > 0 && // doWriteForward may return 0 if src
// only include bidi control chars
!(MASK_R_AL&DIRPROP_FLAG(dirProps[logicalStart+runLength-1]))) {
if(destSize>0) {
*dest++=RLM_CHAR;
}

View file

@ -38,7 +38,7 @@
static UBool U_CALLCONV
_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 /*end*/, uint32_t /*value*/) {
/* add the start code point to the USet */
const USetAdder *sa=(const USetAdder *)context;
const USetAdder* sa = static_cast<const USetAdder*>(context);
sa->add(sa->set, start);
return true;
}
@ -696,17 +696,17 @@ getDotType(UChar32 c) {
U_CAPI UBool U_EXPORT2
ucase_isSoftDotted(UChar32 c) {
return (UBool)(getDotType(c)==UCASE_SOFT_DOTTED);
return getDotType(c)==UCASE_SOFT_DOTTED;
}
U_CAPI UBool U_EXPORT2
ucase_isCaseSensitive(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
if(!UCASE_HAS_EXCEPTION(props)) {
return (UBool)((props&UCASE_SENSITIVE)!=0);
return (props&UCASE_SENSITIVE)!=0;
} else {
const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
return (UBool)((*pe&UCASE_EXC_SENSITIVE)!=0);
return (*pe&UCASE_EXC_SENSITIVE)!=0;
}
}
@ -1623,12 +1623,12 @@ ucase_toFullFolding(UChar32 c,
U_CAPI UBool U_EXPORT2
u_isULowercase(UChar32 c) {
return (UBool)(UCASE_LOWER==ucase_getType(c));
return UCASE_LOWER==ucase_getType(c);
}
U_CAPI UBool U_EXPORT2
u_isUUppercase(UChar32 c) {
return (UBool)(UCASE_UPPER==ucase_getType(c));
return UCASE_UPPER==ucase_getType(c);
}
/* Transforms the Unicode character to its lower case equivalent.*/

File diff suppressed because it is too large Load diff

View file

@ -160,12 +160,12 @@ appendResult(int32_t cpLength, int32_t result, const char16_t *s,
}
// See unicode/utf8.h U8_APPEND_UNSAFE().
inline uint8_t getTwoByteLead(UChar32 c) { return (uint8_t)((c >> 6) | 0xc0); }
inline uint8_t getTwoByteTrail(UChar32 c) { return (uint8_t)((c & 0x3f) | 0x80); }
inline uint8_t getTwoByteLead(UChar32 c) { return static_cast<uint8_t>((c >> 6) | 0xc0); }
inline uint8_t getTwoByteTrail(UChar32 c) { return static_cast<uint8_t>((c & 0x3f) | 0x80); }
UChar32 U_CALLCONV
utf8_caseContextIterator(void *context, int8_t dir) {
UCaseContext *csc=(UCaseContext *)context;
UCaseContext* csc = static_cast<UCaseContext*>(context);
UChar32 c;
if(dir<0) {
@ -234,7 +234,7 @@ void toLower(int32_t caseLocale, uint32_t options,
if (d == 0) { continue; }
ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev,
sink, options, edits, errorCode);
char ascii = (char)(lead + d);
char ascii = static_cast<char>(lead + d);
sink.Append(&ascii, 1);
if (edits != nullptr) {
edits->addReplace(1, 1);
@ -342,7 +342,7 @@ void toUpper(int32_t caseLocale, uint32_t options,
if (d == 0) { continue; }
ByteSinkUtil::appendUnchanged(src + prev, srcIndex - 1 - prev,
sink, options, edits, errorCode);
char ascii = (char)(lead + d);
char ascii = static_cast<char>(lead + d);
sink.Append(&ascii, 1);
if (edits != nullptr) {
edits->addReplace(1, 1);
@ -747,14 +747,14 @@ void toUpper(uint32_t options,
int32_t i2 = i + 2;
if ((data & HAS_EITHER_DIALYTIKA) != 0) {
change |= (i2 + 2) > nextIndex ||
src[i2] != (uint8_t)u8"\u0308"[0] ||
src[i2 + 1] != (uint8_t)u8"\u0308"[1];
src[i2] != static_cast<uint8_t>(u8"\u0308"[0]) ||
src[i2 + 1] != static_cast<uint8_t>(u8"\u0308"[1]);
i2 += 2;
}
if (addTonos) {
change |= (i2 + 2) > nextIndex ||
src[i2] != (uint8_t)u8"\u0301"[0] ||
src[i2 + 1] != (uint8_t)u8"\u0301"[1];
src[i2] != static_cast<uint8_t>(u8"\u0301"[0]) ||
src[i2 + 1] != static_cast<uint8_t>(u8"\u0301"[1]);
i2 += 2;
}
int32_t oldLength = nextIndex - i;
@ -867,14 +867,14 @@ ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_P
// Get the string length.
if (srcLength == -1) {
srcLength = (int32_t)uprv_strlen((const char *)src);
srcLength = static_cast<int32_t>(uprv_strlen(src));
}
if (edits != nullptr && (options & U_EDITS_NO_RESET) == 0) {
edits->reset();
}
stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
(const uint8_t *)src, srcLength, sink, edits, errorCode);
reinterpret_cast<const uint8_t*>(src), srcLength, sink, edits, errorCode);
sink.Flush();
if (U_SUCCESS(errorCode)) {
if (edits != nullptr) {
@ -904,7 +904,7 @@ ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_P
/* get the string length */
if(srcLength==-1) {
srcLength=(int32_t)uprv_strlen((const char *)src);
srcLength = static_cast<int32_t>(uprv_strlen(src));
}
/* check for overlapping source and destination */
@ -923,7 +923,7 @@ ucasemap_mapUTF8(int32_t caseLocale, uint32_t options, UCASEMAP_BREAK_ITERATOR_P
dest, destCapacity,
[&](ByteSink& sink, UErrorCode& status) {
stringCaseMapper(caseLocale, options, UCASEMAP_BREAK_ITERATOR
(const uint8_t *)src, srcLength, sink, edits, status);
reinterpret_cast<const uint8_t*>(src), srcLength, sink, edits, status);
},
errorCode);
if (U_SUCCESS(errorCode) && edits != nullptr) {

View file

@ -107,7 +107,7 @@ ucasemap_utf8ToTitle(UCaseMap *csm,
return 0;
}
UText utext=UTEXT_INITIALIZER;
utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode);
utext_openUTF8(&utext, src, srcLength, pErrorCode);
if (U_FAILURE(*pErrorCode)) {
return 0;
}

View file

@ -23,6 +23,7 @@
#include "unicode/utypes.h"
#include "unicode/uchar.h"
#include "unicode/ucptrie.h"
#include "unicode/uscript.h"
#include "unicode/udata.h"
#include "uassert.h"
@ -67,9 +68,9 @@ _enumTypeValue(const void *context, uint32_t value) {
static UBool U_CALLCONV
_enumTypeRange(const void *context, UChar32 start, UChar32 end, uint32_t value) {
/* just cast the value to UCharCategory */
return ((struct _EnumTypeCallback *)context)->
enumRange(((struct _EnumTypeCallback *)context)->context,
start, end+1, (UCharCategory)value);
return static_cast<const _EnumTypeCallback*>(context)->
enumRange(static_cast<const _EnumTypeCallback*>(context)->context,
start, end + 1, static_cast<UCharCategory>(value));
}
U_CAPI void U_EXPORT2
@ -90,7 +91,7 @@ U_CAPI UBool U_EXPORT2
u_islower(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_LOWERCASE_LETTER);
return GET_CATEGORY(props)==U_LOWERCASE_LETTER;
}
/* Checks if ch is an upper case letter.*/
@ -98,7 +99,7 @@ U_CAPI UBool U_EXPORT2
u_isupper(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_UPPERCASE_LETTER);
return GET_CATEGORY(props)==U_UPPERCASE_LETTER;
}
/* Checks if ch is a title case letter; usually upper case letters.*/
@ -106,7 +107,7 @@ U_CAPI UBool U_EXPORT2
u_istitle(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_TITLECASE_LETTER);
return GET_CATEGORY(props)==U_TITLECASE_LETTER;
}
/* Checks if ch is a decimal digit. */
@ -114,7 +115,7 @@ U_CAPI UBool U_EXPORT2
u_isdigit(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER);
return GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER;
}
U_CAPI UBool U_EXPORT2
@ -130,7 +131,7 @@ u_isxdigit(UChar32 c) {
}
GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER);
return GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER;
}
/* Checks if the Unicode character is a letter.*/
@ -138,7 +139,7 @@ U_CAPI UBool U_EXPORT2
u_isalpha(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&U_GC_L_MASK)!=0);
return (CAT_MASK(props)&U_GC_L_MASK)!=0;
}
U_CAPI UBool U_EXPORT2
@ -151,7 +152,7 @@ U_CAPI UBool U_EXPORT2
u_isalnum(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0);
return (CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0;
}
/**
@ -160,7 +161,7 @@ u_isalnum(UChar32 c) {
*/
U_CFUNC UBool
u_isalnumPOSIX(UChar32 c) {
return (UBool)(u_isUAlphabetic(c) || u_isdigit(c));
return u_isUAlphabetic(c) || u_isdigit(c);
}
/* Checks if ch is a unicode character with assigned character type.*/
@ -168,7 +169,7 @@ U_CAPI UBool U_EXPORT2
u_isdefined(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)!=0);
return GET_CATEGORY(props)!=0;
}
/* Checks if the Unicode character is a base form character that can take a diacritic.*/
@ -176,7 +177,7 @@ U_CAPI UBool U_EXPORT2
u_isbase(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_N_MASK|U_GC_MC_MASK|U_GC_ME_MASK))!=0);
return (CAT_MASK(props)&(U_GC_L_MASK|U_GC_N_MASK|U_GC_MC_MASK|U_GC_ME_MASK))!=0;
}
/* Checks if the Unicode character is a control character.*/
@ -184,7 +185,7 @@ U_CAPI UBool U_EXPORT2
u_iscntrl(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_ZL_MASK|U_GC_ZP_MASK))!=0);
return (CAT_MASK(props)&(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_ZL_MASK|U_GC_ZP_MASK))!=0;
}
U_CAPI UBool U_EXPORT2
@ -205,14 +206,14 @@ U_CAPI UBool U_EXPORT2
u_isspace(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0 || IS_THAT_CONTROL_SPACE(c));
return (CAT_MASK(props)&U_GC_Z_MASK)!=0 || IS_THAT_CONTROL_SPACE(c);
}
U_CAPI UBool U_EXPORT2
u_isJavaSpaceChar(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0);
return (CAT_MASK(props)&U_GC_Z_MASK)!=0;
}
/* Checks if the Unicode character is a whitespace character.*/
@ -220,11 +221,9 @@ U_CAPI UBool U_EXPORT2
u_isWhitespace(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)(
((CAT_MASK(props)&U_GC_Z_MASK)!=0 &&
c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */
IS_THAT_ASCII_CONTROL_SPACE(c)
);
return ((CAT_MASK(props)&U_GC_Z_MASK)!=0 &&
c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */
IS_THAT_ASCII_CONTROL_SPACE(c);
}
U_CAPI UBool U_EXPORT2
@ -235,7 +234,7 @@ u_isblank(UChar32 c) {
/* Zs */
uint32_t props;
GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_SPACE_SEPARATOR);
return GET_CATEGORY(props)==U_SPACE_SEPARATOR;
}
}
@ -250,7 +249,7 @@ u_isprint(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
/* comparing ==0 returns false for the categories mentioned */
return (UBool)((CAT_MASK(props)&U_GC_C_MASK)==0);
return (CAT_MASK(props)&U_GC_C_MASK)==0;
}
/**
@ -266,7 +265,7 @@ u_isprintPOSIX(UChar32 c) {
* The only cntrl character in graph+blank is TAB (in blank).
* Here we implement (blank-TAB)=Zs instead of calling u_isblank().
*/
return (UBool)((GET_CATEGORY(props)==U_SPACE_SEPARATOR) || u_isgraphPOSIX(c));
return (GET_CATEGORY(props)==U_SPACE_SEPARATOR) || u_isgraphPOSIX(c);
}
U_CAPI UBool U_EXPORT2
@ -274,9 +273,9 @@ u_isgraph(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
/* comparing ==0 returns false for the categories mentioned */
return (UBool)((CAT_MASK(props)&
(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
==0);
return (CAT_MASK(props)&
(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
==0;
}
/**
@ -292,16 +291,16 @@ u_isgraphPOSIX(UChar32 c) {
GET_PROPS(c, props);
/* \p{space}\p{gc=Control} == \p{gc=Z}\p{Control} */
/* comparing ==0 returns false for the categories mentioned */
return (UBool)((CAT_MASK(props)&
(U_GC_CC_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
==0);
return (CAT_MASK(props)&
(U_GC_CC_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
==0;
}
U_CAPI UBool U_EXPORT2
u_ispunct(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&U_GC_P_MASK)!=0);
return (CAT_MASK(props)&U_GC_P_MASK)!=0;
}
/*Checks if the Unicode character can be ignorable in a Java or Unicode identifier.*/
@ -312,7 +311,7 @@ u_isIDIgnorable(UChar32 c) {
} else {
uint32_t props;
GET_PROPS(c, props);
return (UBool)(GET_CATEGORY(props)==U_FORMAT_CHAR);
return GET_CATEGORY(props)==U_FORMAT_CHAR;
}
}
@ -321,7 +320,7 @@ U_CAPI UBool U_EXPORT2
u_isJavaIDStart(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_SC_MASK|U_GC_PC_MASK))!=0);
return (CAT_MASK(props)&(U_GC_L_MASK|U_GC_SC_MASK|U_GC_PC_MASK))!=0;
}
/*Checks if the Unicode character can be a Java identifier part other than starting the
@ -331,14 +330,13 @@ U_CAPI UBool U_EXPORT2
u_isJavaIDPart(UChar32 c) {
uint32_t props;
GET_PROPS(c, props);
return (UBool)(
(CAT_MASK(props)&
return (CAT_MASK(props)&
(U_GC_ND_MASK|U_GC_NL_MASK|
U_GC_L_MASK|
U_GC_SC_MASK|U_GC_PC_MASK|
U_GC_MC_MASK|U_GC_MN_MASK)
)!=0 ||
u_isIDIgnorable(c));
u_isIDIgnorable(c);
}
U_CAPI int32_t U_EXPORT2
@ -515,6 +513,8 @@ uprv_getMaxValues(int32_t column) {
return indexes[UPROPS_MAX_VALUES_INDEX];
case 2:
return indexes[UPROPS_MAX_VALUES_2_INDEX];
case UPROPS_MAX_VALUES_OTHER_INDEX:
return indexes[column];
default:
return 0;
}
@ -524,8 +524,8 @@ U_CAPI void U_EXPORT2
u_charAge(UChar32 c, UVersionInfo versionArray) {
if(versionArray!=nullptr) {
uint32_t version=u_getUnicodeProperties(c, 0)>>UPROPS_AGE_SHIFT;
versionArray[0]=(uint8_t)(version>>4);
versionArray[1]=(uint8_t)(version&0xf);
versionArray[0]=(uint8_t)(version>>2);
versionArray[1]=(uint8_t)(version&3);
versionArray[2]=versionArray[3]=0;
}
}
@ -540,7 +540,7 @@ uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
return USCRIPT_INVALID_CODE;
}
uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
uint32_t codeOrIndex=uprops_mergeScriptCodeOrIndex(scriptX);
uint32_t codeOrIndex=scriptX&UPROPS_MAX_SCRIPT;
if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
return (UScriptCode)codeOrIndex;
} else if(scriptX<UPROPS_SCRIPT_X_WITH_INHERITED) {
@ -555,7 +555,7 @@ uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
U_CAPI UBool U_EXPORT2
uscript_hasScript(UChar32 c, UScriptCode sc) UPRV_NO_SANITIZE_UNDEFINED {
uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
uint32_t codeOrIndex=uprops_mergeScriptCodeOrIndex(scriptX);
uint32_t codeOrIndex=scriptX&UPROPS_MAX_SCRIPT;
if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
return sc==(UScriptCode)codeOrIndex;
}
@ -587,7 +587,7 @@ uscript_getScriptExtensions(UChar32 c,
return 0;
}
uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
uint32_t codeOrIndex=uprops_mergeScriptCodeOrIndex(scriptX);
uint32_t codeOrIndex=scriptX&UPROPS_MAX_SCRIPT;
if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
if(capacity==0) {
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
@ -618,7 +618,15 @@ uscript_getScriptExtensions(UChar32 c,
U_CAPI UBlockCode U_EXPORT2
ublock_getCode(UChar32 c) {
return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT);
// We store Block values indexed by the code point shifted right 4 bits
// and use a "small" UCPTrie=CodePointTrie for minimal data size.
// This works because blocks have xxx0..xxxF ranges.
uint32_t c4 = c; // unsigned so that shifting right does not worry the compiler
// Shift unless out of range, in which case we fetch the trie's error value.
if (c4 <= 0x10ffff) {
c4 >>= 4;
}
return (UBlockCode)ucptrie_get(&block_trie, c4);
}
/* property starts for UnicodeSet ------------------------------------------- */
@ -626,7 +634,7 @@ ublock_getCode(UChar32 c) {
static UBool U_CALLCONV
_enumPropertyStartsRange(const void *context, UChar32 start, UChar32 end, uint32_t value) {
/* add the start code point to the USet */
const USetAdder *sa=(const USetAdder *)context;
const USetAdder* sa = static_cast<const USetAdder*>(context);
sa->add(sa->set, start);
(void)end;
(void)value;
@ -706,3 +714,18 @@ upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
/* add the start code point of each same-value range of the properties vectors trie */
utrie2_enum(&propsVectorsTrie, nullptr, _enumPropertyStartsRange, sa);
}
U_CFUNC void U_EXPORT2
ublock_addPropertyStarts(const USetAdder *sa, UErrorCode & /*errorCode*/) {
// Add the start code point of each same-value range of the trie.
// We store Block values indexed by the code point shifted right 4 bits;
// see ublock_getCode().
UChar32 start = 0, end;
uint32_t value;
while (start < 0x11000 && // limit: (max code point + 1) >> 4
(end = ucptrie_getRange(&block_trie, start, UCPMAP_RANGE_NORMAL, 0,
nullptr, nullptr, &value)) >= 0) {
sa->add(sa->set, start << 4);
start = end + 1;
}
}

File diff suppressed because it is too large Load diff

View file

@ -297,7 +297,7 @@ UCharsTrie::findUniqueValueFromBranch(const char16_t *pos, int32_t length,
++pos; // ignore a comparison unit
// handle its value
int32_t node=*pos++;
UBool isFinal=(UBool)(node>>15);
UBool isFinal = static_cast<UBool>(node >> 15);
node&=0x7fff;
int32_t value=readValue(pos, node);
pos=skipValue(pos, node);
@ -339,7 +339,7 @@ UCharsTrie::findUniqueValue(const char16_t *pos, UBool haveUniqueValue, int32_t
pos+=node-kMinLinearMatch+1; // Ignore the match units.
node=*pos++;
} else {
UBool isFinal=(UBool)(node>>15);
UBool isFinal = static_cast<UBool>(node >> 15);
int32_t value;
if(isFinal) {
value=readValue(pos, node&0x7fff);

View file

@ -75,7 +75,7 @@ UCharsTrieElement::setTo(const UnicodeString &s, int32_t val,
return;
}
stringOffset=strings.length();
strings.append((char16_t)length);
strings.append(static_cast<char16_t>(length));
value=val;
strings.append(s);
}
@ -186,7 +186,7 @@ UCharsTrieBuilder::buildUChars(UStringTrieBuildOption buildOption, UErrorCode &e
errorCode=U_MEMORY_ALLOCATION_ERROR;
return;
}
uprv_sortArray(elements, elementsLength, (int32_t)sizeof(UCharsTrieElement),
uprv_sortArray(elements, elementsLength, static_cast<int32_t>(sizeof(UCharsTrieElement)),
compareElementStrings, &strings,
false, // need not be a stable sort
&errorCode);
@ -351,7 +351,7 @@ UCharsTrieBuilder::write(int32_t unit) {
int32_t newLength=ucharsLength+1;
if(ensureCapacity(newLength)) {
ucharsLength=newLength;
uchars[ucharsCapacity-ucharsLength]=(char16_t)unit;
uchars[ucharsCapacity - ucharsLength] = static_cast<char16_t>(unit);
}
return ucharsLength;
}
@ -379,19 +379,19 @@ UCharsTrieBuilder::writeValueAndFinal(int32_t i, UBool isFinal) {
char16_t intUnits[3];
int32_t length;
if(i<0 || i>UCharsTrie::kMaxTwoUnitValue) {
intUnits[0]=(char16_t)(UCharsTrie::kThreeUnitValueLead);
intUnits[1]=(char16_t)((uint32_t)i>>16);
intUnits[2]=(char16_t)i;
intUnits[0] = static_cast<char16_t>(UCharsTrie::kThreeUnitValueLead);
intUnits[1] = static_cast<char16_t>(static_cast<uint32_t>(i) >> 16);
intUnits[2] = static_cast<char16_t>(i);
length=3;
// } else if(i<=UCharsTrie::kMaxOneUnitValue) {
// intUnits[0]=(char16_t)(i);
// length=1;
} else {
intUnits[0]=(char16_t)(UCharsTrie::kMinTwoUnitValueLead+(i>>16));
intUnits[1]=(char16_t)i;
intUnits[0] = static_cast<char16_t>(UCharsTrie::kMinTwoUnitValueLead + (i >> 16));
intUnits[1] = static_cast<char16_t>(i);
length=2;
}
intUnits[0]=(char16_t)(intUnits[0]|(isFinal<<15));
intUnits[0] = static_cast<char16_t>(intUnits[0] | (isFinal << 15));
return write(intUnits, length);
}
@ -403,19 +403,19 @@ UCharsTrieBuilder::writeValueAndType(UBool hasValue, int32_t value, int32_t node
char16_t intUnits[3];
int32_t length;
if(value<0 || value>UCharsTrie::kMaxTwoUnitNodeValue) {
intUnits[0]=(char16_t)(UCharsTrie::kThreeUnitNodeValueLead);
intUnits[1]=(char16_t)((uint32_t)value>>16);
intUnits[2]=(char16_t)value;
intUnits[0] = static_cast<char16_t>(UCharsTrie::kThreeUnitNodeValueLead);
intUnits[1] = static_cast<char16_t>(static_cast<uint32_t>(value) >> 16);
intUnits[2] = static_cast<char16_t>(value);
length=3;
} else if(value<=UCharsTrie::kMaxOneUnitNodeValue) {
intUnits[0]=(char16_t)((value+1)<<6);
intUnits[0] = static_cast<char16_t>((value + 1) << 6);
length=1;
} else {
intUnits[0]=(char16_t)(UCharsTrie::kMinTwoUnitNodeValueLead+((value>>10)&0x7fc0));
intUnits[1]=(char16_t)value;
intUnits[0] = static_cast<char16_t>(UCharsTrie::kMinTwoUnitNodeValueLead + ((value >> 10) & 0x7fc0));
intUnits[1] = static_cast<char16_t>(value);
length=2;
}
intUnits[0]|=(char16_t)node;
intUnits[0] |= static_cast<char16_t>(node);
return write(intUnits, length);
}
@ -429,14 +429,14 @@ UCharsTrieBuilder::writeDeltaTo(int32_t jumpTarget) {
char16_t intUnits[3];
int32_t length;
if(i<=UCharsTrie::kMaxTwoUnitDelta) {
intUnits[0]=(char16_t)(UCharsTrie::kMinTwoUnitDeltaLead+(i>>16));
intUnits[0] = static_cast<char16_t>(UCharsTrie::kMinTwoUnitDeltaLead + (i >> 16));
length=1;
} else {
intUnits[0]=(char16_t)(UCharsTrie::kThreeUnitDeltaLead);
intUnits[1]=(char16_t)(i>>16);
intUnits[0] = static_cast<char16_t>(UCharsTrie::kThreeUnitDeltaLead);
intUnits[1] = static_cast<char16_t>(i >> 16);
length=2;
}
intUnits[length++]=(char16_t)i;
intUnits[length++] = static_cast<char16_t>(i);
return write(intUnits, length);
}

View file

@ -114,7 +114,7 @@ UCharsTrie::Iterator::next(UErrorCode &errorCode) {
pos=uchars_+stack_->elementAti(stackSize-2);
stack_->setSize(stackSize-2);
str_.truncate(length&0xffff);
length=(int32_t)((uint32_t)length>>16);
length = static_cast<int32_t>(static_cast<uint32_t>(length) >> 16);
if(length>1) {
pos=branchNext(pos, length, errorCode);
if(pos==nullptr) {
@ -138,7 +138,7 @@ UCharsTrie::Iterator::next(UErrorCode &errorCode) {
skipValue_=false;
} else {
// Deliver value for the string so far.
UBool isFinal=(UBool)(node>>15);
UBool isFinal = static_cast<UBool>(node >> 15);
if(isFinal) {
value_=readValue(pos, node&0x7fff);
} else {
@ -187,7 +187,7 @@ UCharsTrie::Iterator::branchNext(const char16_t *pos, int32_t length, UErrorCode
while(length>kMaxBranchLinearSubNodeLength) {
++pos; // ignore the comparison unit
// Push state for the greater-or-equal edge.
stack_->addElement((int32_t)(skipDelta(pos)-uchars_), errorCode);
stack_->addElement(static_cast<int32_t>(skipDelta(pos) - uchars_), errorCode);
stack_->addElement(((length-(length>>1))<<16)|str_.length(), errorCode);
// Follow the less-than edge.
length>>=1;
@ -197,10 +197,10 @@ UCharsTrie::Iterator::branchNext(const char16_t *pos, int32_t length, UErrorCode
// Read the first (key, value) pair.
char16_t trieUnit=*pos++;
int32_t node=*pos++;
UBool isFinal=(UBool)(node>>15);
UBool isFinal = static_cast<UBool>(node >> 15);
int32_t value=readValue(pos, node&=0x7fff);
pos=skipValue(pos, node);
stack_->addElement((int32_t)(pos-uchars_), errorCode);
stack_->addElement(static_cast<int32_t>(pos - uchars_), errorCode);
stack_->addElement(((length-1)<<16)|str_.length(), errorCode);
str_.append(trieUnit);
if(isFinal) {

View file

@ -172,7 +172,7 @@ UCharCharacterIterator::nextPostInc() {
UBool
UCharCharacterIterator::hasNext() {
return (UBool)(pos < end ? true : false);
return pos < end;
}
char16_t
@ -186,7 +186,7 @@ UCharCharacterIterator::previous() {
UBool
UCharCharacterIterator::hasPrevious() {
return (UBool)(pos > begin ? true : false);
return pos > begin;
}
UChar32

View file

@ -108,8 +108,8 @@ strcmpAfterPrefix(const char *s1, const char *s2, int32_t *pPrefixLength) {
s1+=pl;
s2+=pl;
for(;;) {
int32_t c1=(uint8_t)*s1++;
int32_t c2=(uint8_t)*s2++;
int32_t c1 = static_cast<uint8_t>(*s1++);
int32_t c2 = static_cast<uint8_t>(*s2++);
cmp=c1-c2;
if(cmp!=0 || c1==0) { /* different or done */
break;
@ -271,7 +271,7 @@ offsetTOCLookupFn(const UDataMemory *pData,
static uint32_t U_CALLCONV pointerTOCEntryCount(const UDataMemory *pData) {
const PointerTOC *toc = (PointerTOC *)pData->toc;
return (uint32_t)((toc != nullptr) ? (toc->count) : 0);
return toc != nullptr ? toc->count : 0;
}
static const DataHeader * U_CALLCONV pointerTOCLookupFn(const UDataMemory *pData,

View file

@ -916,7 +916,7 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
* s<sourceLimit before converterSawEndOfInput is checked
*/
converterSawEndOfInput=
(UBool)(U_SUCCESS(*err) &&
static_cast<UBool>(U_SUCCESS(*err) &&
pArgs->flush && pArgs->source==pArgs->sourceLimit &&
cnv->fromUChar32==0);
} else {
@ -941,7 +941,7 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
for(;;) {
/* update offsets if we write any */
if(offsets!=nullptr) {
int32_t length=(int32_t)(pArgs->target-t);
int32_t length = static_cast<int32_t>(pArgs->target - t);
if(length>0) {
_updateOffsets(offsets, length, sourceIndex, errorInputLength);
@ -956,7 +956,7 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
}
if(sourceIndex>=0) {
sourceIndex+=(int32_t)(pArgs->source-s);
sourceIndex += static_cast<int32_t>(pArgs->source - s);
}
}
@ -1066,10 +1066,10 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
U_ASSERT(cnv->preFromULength==0);
length=(int32_t)(pArgs->sourceLimit-pArgs->source);
length = static_cast<int32_t>(pArgs->sourceLimit - pArgs->source);
if(length>0) {
u_memcpy(cnv->preFromU, pArgs->source, length);
cnv->preFromULength=(int8_t)-length;
cnv->preFromULength = static_cast<int8_t>(-length);
}
pArgs->source=realSource;
@ -1089,7 +1089,7 @@ _fromUnicodeWithCallback(UConverterFromUnicodeArgs *pArgs, UErrorCode *err) {
codePoint=cnv->fromUChar32;
errorInputLength=0;
U16_APPEND_UNSAFE(cnv->invalidUCharBuffer, errorInputLength, codePoint);
cnv->invalidUCharLength=(int8_t)errorInputLength;
cnv->invalidUCharLength = static_cast<int8_t>(errorInputLength);
/* set the converter state to deal with the next character */
cnv->fromUChar32=0;
@ -1134,7 +1134,7 @@ ucnv_outputOverflowFromUnicode(UConverter *cnv,
offsets=nullptr;
}
overflow=(char *)cnv->charErrorBuffer;
overflow = reinterpret_cast<char*>(cnv->charErrorBuffer);
length=cnv->charErrorBufferLength;
i=0;
while(i<length) {
@ -1146,7 +1146,7 @@ ucnv_outputOverflowFromUnicode(UConverter *cnv,
overflow[j++]=overflow[i++];
} while(i<length);
cnv->charErrorBufferLength=(int8_t)j;
cnv->charErrorBufferLength = static_cast<int8_t>(j);
*target=t;
if(offsets!=nullptr) {
*pOffsets=offsets;
@ -1361,7 +1361,7 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
* s<sourceLimit before converterSawEndOfInput is checked
*/
converterSawEndOfInput=
(UBool)(U_SUCCESS(*err) &&
static_cast<UBool>(U_SUCCESS(*err) &&
pArgs->flush && pArgs->source==pArgs->sourceLimit &&
cnv->toULength==0);
} else {
@ -1386,7 +1386,7 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
for(;;) {
/* update offsets if we write any */
if(offsets!=nullptr) {
int32_t length=(int32_t)(pArgs->target-t);
int32_t length = static_cast<int32_t>(pArgs->target - t);
if(length>0) {
_updateOffsets(offsets, length, sourceIndex, errorInputLength);
@ -1401,7 +1401,7 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
}
if(sourceIndex>=0) {
sourceIndex+=(int32_t)(pArgs->source-s);
sourceIndex += static_cast<int32_t>(pArgs->source - s);
}
}
@ -1513,10 +1513,10 @@ _toUnicodeWithCallback(UConverterToUnicodeArgs *pArgs, UErrorCode *err) {
U_ASSERT(cnv->preToULength==0);
length=(int32_t)(pArgs->sourceLimit-pArgs->source);
length = static_cast<int32_t>(pArgs->sourceLimit - pArgs->source);
if(length>0) {
uprv_memcpy(cnv->preToU, pArgs->source, length);
cnv->preToULength=(int8_t)-length;
cnv->preToULength = static_cast<int8_t>(-length);
}
pArgs->source=realSource;
@ -1592,7 +1592,7 @@ ucnv_outputOverflowToUnicode(UConverter *cnv,
overflow[j++]=overflow[i++];
} while(i<length);
cnv->UCharErrorBufferLength=(int8_t)j;
cnv->UCharErrorBufferLength = static_cast<int8_t>(j);
*target=t;
if(offsets!=nullptr) {
*pOffsets=offsets;
@ -2437,7 +2437,7 @@ ucnv_internalConvert(UConverter *outConverter, UConverter *inConverter,
false,
true,
pErrorCode);
targetLength=(int32_t)(myTarget-target);
targetLength = static_cast<int32_t>(myTarget - target);
}
/*
@ -2460,7 +2460,7 @@ ucnv_internalConvert(UConverter *outConverter, UConverter *inConverter,
false,
true,
pErrorCode);
targetLength+=(int32_t)(myTarget-targetBuffer);
targetLength += static_cast<int32_t>(myTarget - targetBuffer);
} while(*pErrorCode==U_BUFFER_OVERFLOW_ERROR);
/* done with preflighting, set warnings and errors as appropriate */
@ -2684,7 +2684,7 @@ ucnv_fixFileSeparator(const UConverter *cnv,
U_CAPI UBool U_EXPORT2
ucnv_isAmbiguous(const UConverter *cnv) {
return (UBool)(ucnv_getAmbiguous(cnv)!=nullptr);
return ucnv_getAmbiguous(cnv)!=nullptr;
}
U_CAPI void U_EXPORT2

File diff suppressed because it is too large Load diff

View file

@ -231,7 +231,7 @@ static void
ucnv_flushAvailableConverterCache() {
gAvailableConverterCount = 0;
if (gAvailableConverters) {
uprv_free((char **)gAvailableConverters);
uprv_free(const_cast<char**>(gAvailableConverters));
gAvailableConverters = nullptr;
}
gAvailableConvertersInitOnce.reset();
@ -270,7 +270,7 @@ static UBool U_CALLCONV
isCnvAcceptable(void * /*context*/,
const char * /*type*/, const char * /*name*/,
const UDataInfo *pInfo) {
return (UBool)(
return
pInfo->size>=20 &&
pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
pInfo->charsetFamily==U_CHARSET_FAMILY &&
@ -279,7 +279,7 @@ isCnvAcceptable(void * /*context*/,
pInfo->dataFormat[1]==0x6e &&
pInfo->dataFormat[2]==0x76 &&
pInfo->dataFormat[3]==0x74 &&
pInfo->formatVersion[0]==6); /* Everything will be version 6 */
pInfo->formatVersion[0]==6; /* Everything will be version 6 */
}
/**
@ -289,15 +289,15 @@ static UConverterSharedData*
ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCode *status)
{
/* UDataInfo info; -- necessary only if some converters have different formatVersion */
const uint8_t *raw = (const uint8_t *)udata_getMemory(pData);
const UConverterStaticData *source = (const UConverterStaticData *) raw;
const uint8_t* raw = static_cast<const uint8_t*>(udata_getMemory(pData));
const UConverterStaticData* source = reinterpret_cast<const UConverterStaticData*>(raw);
UConverterSharedData *data;
UConverterType type = (UConverterType)source->conversionType;
UConverterType type = static_cast<UConverterType>(source->conversionType);
if(U_FAILURE(*status))
return nullptr;
if( (uint16_t)type >= UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES ||
if (static_cast<uint16_t>(type) >= UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES ||
converterData[type] == nullptr ||
!converterData[type]->isReferenceCounted ||
converterData[type]->referenceCounter != 1 ||
@ -307,7 +307,7 @@ ucnv_data_unFlattenClone(UConverterLoadArgs *pArgs, UDataMemory *pData, UErrorCo
return nullptr;
}
data = (UConverterSharedData *)uprv_malloc(sizeof(UConverterSharedData));
data = static_cast<UConverterSharedData*>(uprv_malloc(sizeof(UConverterSharedData)));
if(data == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
@ -397,7 +397,7 @@ getAlgorithmicTypeFromName(const char *realName)
lastMid = UINT32_MAX;
for (;;) {
mid = (uint32_t)((start + limit) / 2);
mid = (start + limit) / 2;
if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */
}
@ -491,7 +491,7 @@ ucnv_getSharedConverterData(const char *name)
{
UConverterSharedData *rc;
rc = (UConverterSharedData*)uhash_get(SHARED_DATA_HASHTABLE, name);
rc = static_cast<UConverterSharedData*>(uhash_get(SHARED_DATA_HASHTABLE, name));
UCNV_DEBUG_LOG("get",name,rc);
return rc;
}
@ -682,8 +682,8 @@ parseConverterOptions(const char *inName,
if(c==0) {
pArgs->options=(pPieces->options&=~UCNV_OPTION_VERSION);
return;
} else if((uint8_t)(c-'0')<10) {
pArgs->options=pPieces->options=(pPieces->options&~UCNV_OPTION_VERSION)|(uint32_t)(c-'0');
} else if (static_cast<uint8_t>(c - '0') < 10) {
pArgs->options = pPieces->options = (pPieces->options & ~UCNV_OPTION_VERSION) | static_cast<uint32_t>(c - '0');
++inName;
}
} else if(uprv_strncmp(inName, "swaplfnl", 8)==0) {
@ -909,7 +909,7 @@ ucnv_createAlgorithmicConverter(UConverter *myUConverter,
stackArgs.options = options;
stackArgs.locale=locale;
cnv = ucnv_createConverterFromSharedData(
myUConverter, (UConverterSharedData *)sharedData,
myUConverter, const_cast<UConverterSharedData*>(sharedData),
&stackArgs, err);
UTRACE_EXIT_PTR_STATUS(cnv, *err);
@ -1112,7 +1112,7 @@ static void U_CALLCONV initAvailableConvertersList(UErrorCode &errCode) {
}
/* We can't have more than "*converterTable" converters to open */
gAvailableConverters = (const char **) uprv_malloc(allConverterCount * sizeof(char*));
gAvailableConverters = static_cast<const char**>(uprv_malloc(allConverterCount * sizeof(char*)));
if (!gAvailableConverters) {
errCode = U_MEMORY_ALLOCATION_ERROR;
return;
@ -1440,7 +1440,7 @@ ucnv_swap(const UDataSwapper *ds,
MBCS_OPT_UNKNOWN_INCOMPATIBLE_MASK)==0
) {
mbcsHeaderLength=mbcsHeader.options&MBCS_OPT_LENGTH_MASK;
noFromU=(UBool)((mbcsHeader.options&MBCS_OPT_NO_FROM_U)!=0);
noFromU = (mbcsHeader.options & MBCS_OPT_NO_FROM_U) != 0;
} else {
udata_printError(ds, "ucnv_swap(): unsupported _MBCSHeader.version %d.%d\n",
inMBCSHeader->version[0], inMBCSHeader->version[1]);

View file

@ -368,7 +368,7 @@ getTrail:
/*look ahead to find the trail surrogate*/
if(source < sourceLimit) {
/* test the following code unit */
char16_t trail=(char16_t) *source;
char16_t trail = *source;
if(U16_IS_TRAIL(trail)) {
source++;
sourceChar=U16_GET_SUPPLEMENTARY(sourceChar, trail);

View file

@ -41,8 +41,8 @@ ucnv_extFindToU(const uint32_t *toUSection, int32_t length, uint8_t byte) {
int32_t i, start, limit;
/* check the input byte against the lowest and highest section bytes */
start=(int32_t)UCNV_EXT_TO_U_GET_BYTE(toUSection[0]);
limit=(int32_t)UCNV_EXT_TO_U_GET_BYTE(toUSection[length-1]);
start = static_cast<int32_t>(UCNV_EXT_TO_U_GET_BYTE(toUSection[0]));
limit = static_cast<int32_t>(UCNV_EXT_TO_U_GET_BYTE(toUSection[length - 1]));
if(byte<start || limit<byte) {
return 0; /* the byte is out of range */
}
@ -180,9 +180,9 @@ ucnv_extMatchToU(const int32_t *cx, int8_t sisoState,
/* match pre[] then src[] */
if(i<preLength) {
b=(uint8_t)pre[i++];
b = static_cast<uint8_t>(pre[i++]);
} else if(j<srcLength) {
b=(uint8_t)src[j++];
b = static_cast<uint8_t>(src[j++]);
} else {
/* all input consumed, partial match */
if(flush || (length=(i+j))>UCNV_EXT_MAX_BYTES) {
@ -206,7 +206,7 @@ ucnv_extMatchToU(const int32_t *cx, int8_t sisoState,
} else {
if(UCNV_EXT_TO_U_IS_PARTIAL(value)) {
/* partial match, continue */
idx=(int32_t)UCNV_EXT_TO_U_GET_PARTIAL_INDEX(value);
idx = static_cast<int32_t>(UCNV_EXT_TO_U_GET_PARTIAL_INDEX(value));
} else {
if( (UCNV_EXT_TO_U_IS_ROUNDTRIP(value) ||
TO_U_USE_FALLBACK(useFallback)) &&
@ -572,7 +572,7 @@ ucnv_extMatchFromU(const int32_t *cx,
if(UCNV_EXT_TO_U_IS_PARTIAL(value)) {
/* partial match, enter the loop below */
idx=(int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value);
idx = static_cast<int32_t>(UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value));
/* initialize */
fromUTableUChars=UCNV_EXT_ARRAY(cx, UCNV_EXT_FROM_U_UCHARS_INDEX, char16_t);
@ -627,7 +627,7 @@ ucnv_extMatchFromU(const int32_t *cx,
value=fromUSectionValues[idx];
if(UCNV_EXT_FROM_U_IS_PARTIAL(value)) {
/* partial match, continue */
idx=(int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value);
idx = static_cast<int32_t>(UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value));
} else {
if(extFromUUseMapping(useFallback, value, firstCP)) {
/* full match, stop with result */
@ -679,7 +679,7 @@ ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
int32_t length, prevLength;
length=UCNV_EXT_FROM_U_GET_LENGTH(value);
value=(uint32_t)UCNV_EXT_FROM_U_GET_DATA(value);
value = UCNV_EXT_FROM_U_GET_DATA(value);
/* output the result */
if(length<=UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH) {
@ -692,13 +692,13 @@ ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
uint8_t *p=buffer+1; /* reserve buffer[0] for shiftByte below */
switch(length) {
case 3:
*p++=(uint8_t)(value>>16);
*p++ = static_cast<uint8_t>(value >> 16);
U_FALLTHROUGH;
case 2:
*p++=(uint8_t)(value>>8);
*p++ = static_cast<uint8_t>(value >> 8);
U_FALLTHROUGH;
case 1:
*p++=(uint8_t)value;
*p++ = static_cast<uint8_t>(value);
U_FALLTHROUGH;
default:
break; /* will never occur */
@ -716,11 +716,11 @@ ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
if(prevLength>1 && length==1) {
/* change from double-byte mode to single-byte */
shiftByte=(uint8_t)UCNV_SI;
shiftByte = static_cast<uint8_t>(UCNV_SI);
cnv->fromUnicodeStatus=1;
} else if(prevLength==1 && length>1) {
/* change from single-byte mode to double-byte */
shiftByte=(uint8_t)UCNV_SO;
shiftByte = static_cast<uint8_t>(UCNV_SO);
cnv->fromUnicodeStatus=2;
} else {
shiftByte=0;
@ -737,7 +737,7 @@ ucnv_extWriteFromU(UConverter *cnv, const int32_t *cx,
}
}
ucnv_fromUWriteBytes(cnv, (const char *)result, length,
ucnv_fromUWriteBytes(cnv, reinterpret_cast<const char*>(result), length,
target, targetLimit,
offsets, srcIndex,
pErrorCode);
@ -830,7 +830,7 @@ ucnv_extSimpleMatchFromU(const int32_t *cx,
isRoundtrip=UCNV_EXT_FROM_U_IS_ROUNDTRIP(value);
length=UCNV_EXT_FROM_U_GET_LENGTH(value);
value=(uint32_t)UCNV_EXT_FROM_U_GET_DATA(value);
value = UCNV_EXT_FROM_U_GET_DATA(value);
if(length<=UCNV_EXT_FROM_U_MAX_DIRECT_LENGTH) {
*pValue=value;
@ -1018,7 +1018,7 @@ ucnv_extGetUnicodeSetString(const UConverterSharedData *sharedData,
ucnv_extGetUnicodeSetString(
sharedData, cx, sa, which, minLength,
firstCP, s, length+1,
(int32_t)UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value),
static_cast<int32_t>(UCNV_EXT_FROM_U_GET_PARTIAL_INDEX(value)),
pErrorCode);
} else if(extSetUseMapping(which, minLength, value)) {
sa->addString(sa->set, s, length+1);

View file

@ -205,7 +205,7 @@ static UBool U_CALLCONV
isAcceptable(void * /*context*/,
const char * /*type*/, const char * /*name*/,
const UDataInfo *pInfo) {
return (UBool)(
return
pInfo->size>=20 &&
pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
pInfo->charsetFamily==U_CHARSET_FAMILY &&
@ -213,7 +213,7 @@ isAcceptable(void * /*context*/,
pInfo->dataFormat[1]==0x76 &&
pInfo->dataFormat[2]==0x41 &&
pInfo->dataFormat[3]==0x6c &&
pInfo->formatVersion[0]==3);
pInfo->formatVersion[0]==3;
}
static UBool U_CALLCONV ucnv_io_cleanup()
@ -244,8 +244,8 @@ static void U_CALLCONV initAliasData(UErrorCode &errCode) {
return;
}
sectionSizes = (const uint32_t *)udata_getMemory(data);
table = (const uint16_t *)sectionSizes;
sectionSizes = static_cast<const uint32_t*>(udata_getMemory(data));
table = reinterpret_cast<const uint16_t*>(sectionSizes);
tableStart = sectionSizes[0];
if (tableStart < minTocLength) {
@ -289,10 +289,10 @@ static void U_CALLCONV initAliasData(UErrorCode &errCode) {
currOffset += gMainTable.taggedAliasListsSize;
if (gMainTable.optionTableSize > 0
&& ((const UConverterAliasOptions *)(table + currOffset))->stringNormalizationType < UCNV_IO_NORM_TYPE_COUNT)
&& reinterpret_cast<const UConverterAliasOptions*>(table + currOffset)->stringNormalizationType < UCNV_IO_NORM_TYPE_COUNT)
{
/* Faster table */
gMainTable.optionTable = (const UConverterAliasOptions *)(table + currOffset);
gMainTable.optionTable = reinterpret_cast<const UConverterAliasOptions*>(table + currOffset);
}
else {
/* Smaller table, or I can't handle this normalization mode!
@ -321,7 +321,7 @@ isAlias(const char *alias, UErrorCode *pErrorCode) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return false;
}
return (UBool)(*alias!=0);
return *alias != 0;
}
static uint32_t getTagNumber(const char *tagname) {
@ -574,7 +574,7 @@ findConverter(const char *alias, UBool *containsOption, UErrorCode *pErrorCode)
lastMid = UINT32_MAX;
for (;;) {
mid = (uint32_t)((start + limit) / 2);
mid = (start + limit) / 2;
if (lastMid == mid) { /* Have we moved? */
break; /* We haven't moved, and it wasn't found. */
}
@ -601,8 +601,8 @@ findConverter(const char *alias, UBool *containsOption, UErrorCode *pErrorCode)
/* State whether the canonical converter name contains an option.
This information is contained in this list in order to maintain backward & forward compatibility. */
if (containsOption) {
UBool containsCnvOptionInfo = (UBool)gMainTable.optionTable->containsCnvOptionInfo;
*containsOption = (UBool)((containsCnvOptionInfo
UBool containsCnvOptionInfo = static_cast<UBool>(gMainTable.optionTable->containsCnvOptionInfo);
*containsOption = static_cast<UBool>((containsCnvOptionInfo
&& ((gMainTable.untaggedConvArray[mid] & UCNV_CONTAINS_OPTION_BIT) != 0))
|| !containsCnvOptionInfo);
}
@ -939,7 +939,7 @@ static uint16_t
ucnv_io_countStandards(UErrorCode *pErrorCode) {
if (haveAliasData(pErrorCode)) {
/* Don't include the empty list */
return (uint16_t)(gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS);
return static_cast<uint16_t>(gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS);
}
return 0;
@ -1130,8 +1130,9 @@ io_compareRows(const void *context, const void *left, const void *right) {
TempAliasTable *tempTable=(TempAliasTable *)context;
const char *chars=tempTable->chars;
return (int32_t)uprv_strcmp(tempTable->stripForCompare(strippedLeft, chars+2*((const TempRow *)left)->strIndex),
tempTable->stripForCompare(strippedRight, chars+2*((const TempRow *)right)->strIndex));
return static_cast<int32_t>(uprv_strcmp(
tempTable->stripForCompare(strippedLeft, chars + 2 * static_cast<const TempRow*>(left)->strIndex),
tempTable->stripForCompare(strippedRight, chars + 2 * static_cast<const TempRow*>(right)->strIndex)));
}
U_CAPI int32_t U_EXPORT2

View file

@ -633,7 +633,7 @@ _LMBCSOpenWorker(UConverter* _this,
UErrorCode* err,
ulmbcs_byte_t OptGroup)
{
UConverterDataLMBCS * extraInfo = (UConverterDataLMBCS*)uprv_malloc (sizeof (UConverterDataLMBCS));
UConverterDataLMBCS* extraInfo = static_cast<UConverterDataLMBCS*>(uprv_malloc(sizeof(UConverterDataLMBCS)));
_this->extraInfo = extraInfo;
if(extraInfo != nullptr)
{

View file

@ -236,10 +236,10 @@ _UTF16BEFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
/* output length bytes with overflow (length>targetCapacity>0) */
ucnv_fromUWriteBytes(cnv,
overflow, length,
(char **)&target, pArgs->targetLimit,
&target, pArgs->targetLimit,
&offsets, sourceIndex,
pErrorCode);
targetCapacity=(uint32_t)(pArgs->targetLimit-(char *)target);
targetCapacity = static_cast<uint32_t>(pArgs->targetLimit - target);
}
if(U_SUCCESS(*pErrorCode) && source<pArgs->sourceLimit && targetCapacity==0) {
@ -248,7 +248,7 @@ _UTF16BEFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
/* write back the updated pointers */
pArgs->source=source;
pArgs->target=(char *)target;
pArgs->target = target;
pArgs->offsets=offsets;
}
@ -840,7 +840,7 @@ _UTF16LEFromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
&target, pArgs->targetLimit,
&offsets, sourceIndex,
pErrorCode);
targetCapacity=(uint32_t)(pArgs->targetLimit-(char *)target);
targetCapacity = static_cast<uint32_t>(pArgs->targetLimit - target);
}
if(U_SUCCESS(*pErrorCode) && source<pArgs->sourceLimit && targetCapacity==0) {

View file

@ -49,8 +49,8 @@ U_CFUNC void ucnv_fromUnicode_UTF8_OFFSETS_LOGIC(UConverterFromUnicodeArgs *args
#define MAXIMUM_UCS2 0x0000FFFF
static const uint32_t offsetsFromUTF8[5] = {0,
(uint32_t) 0x00000000, (uint32_t) 0x00003080, (uint32_t) 0x000E2080,
(uint32_t) 0x03C82080
static_cast<uint32_t>(0x00000000), static_cast<uint32_t>(0x00003080),
static_cast<uint32_t>(0x000E2080), static_cast<uint32_t>(0x03C82080)
};
static UBool hasCESU8Data(const UConverter *cnv)
@ -58,7 +58,7 @@ static UBool hasCESU8Data(const UConverter *cnv)
#if UCONFIG_ONLY_HTML_CONVERSION
return false;
#else
return (UBool)(cnv->sharedData == &_CESU8Data);
return cnv->sharedData == &_CESU8Data;
#endif
}
U_CDECL_BEGIN
@ -571,7 +571,7 @@ static UChar32 U_CALLCONV ucnv_getNextUChar_UTF8(UConverterToUnicodeArgs *args,
return 0xffff;
}
myByte = (uint8_t)*(source++);
myByte = *(source++);
if (U8_IS_SINGLE(myByte))
{
args->source = (const char *)source;

View file

@ -338,7 +338,7 @@ packDiff(int32_t diff) {
*/
result|=BOCU1_TRAIL_TO_BYTE(diff)<<16;
result|=((uint32_t)BOCU1_START_POS_4)<<24;
result |= static_cast<uint32_t>(BOCU1_START_POS_4) << 24;
}
} else {
/* two- to four-byte negative differences */
@ -405,13 +405,13 @@ _Bocu1FromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
cnv=pArgs->converter;
source=pArgs->source;
sourceLimit=pArgs->sourceLimit;
target=(uint8_t *)pArgs->target;
targetCapacity=(int32_t)(pArgs->targetLimit-pArgs->target);
target = reinterpret_cast<uint8_t*>(pArgs->target);
targetCapacity = static_cast<int32_t>(pArgs->targetLimit - pArgs->target);
offsets=pArgs->offsets;
/* get the converter state from UConverter */
c=cnv->fromUChar32;
prev=(int32_t)cnv->fromUnicodeStatus;
prev = static_cast<int32_t>(cnv->fromUnicodeStatus);
if(prev==0) {
prev=BOCU1_ASCII_PREV;
}
@ -428,7 +428,7 @@ _Bocu1FromUnicodeWithOffsets(UConverterFromUnicodeArgs *pArgs,
fastSingle:
/* fast loop for single-byte differences */
/* use only one loop counter variable, targetCapacity, not also source */
diff=(int32_t)(sourceLimit-source);
diff = static_cast<int32_t>(sourceLimit - source);
if(targetCapacity>diff) {
targetCapacity=diff;
}
@ -437,7 +437,7 @@ fastSingle:
if(c!=0x20) {
prev=BOCU1_ASCII_PREV;
}
*target++=(uint8_t)c;
*target++ = static_cast<uint8_t>(c);
*offsets++=nextSourceIndex++;
++source;
--targetCapacity;
@ -445,7 +445,7 @@ fastSingle:
diff=c-prev;
if(DIFF_IS_SINGLE(diff)) {
prev=BOCU1_SIMPLE_PREV(c);
*target++=(uint8_t)PACK_SINGLE_DIFF(diff);
*target++ = static_cast<uint8_t>(PACK_SINGLE_DIFF(diff));
*offsets++=nextSourceIndex++;
++source;
--targetCapacity;
@ -455,7 +455,7 @@ fastSingle:
}
}
/* restore real values */
targetCapacity=(int32_t)((const uint8_t *)pArgs->targetLimit-target);
targetCapacity = static_cast<int32_t>(reinterpret_cast<const uint8_t*>(pArgs->targetLimit) - target);
sourceIndex=nextSourceIndex; /* wrong if offsets==nullptr but does not matter */
/* regular loop for all cases */
@ -473,7 +473,7 @@ fastSingle:
if(c!=0x20) {
prev=BOCU1_ASCII_PREV;
}
*target++=(uint8_t)c;
*target++ = static_cast<uint8_t>(c);
*offsets++=sourceIndex;
--targetCapacity;
@ -510,7 +510,7 @@ getTrail:
diff=c-prev;
prev=BOCU1_PREV(c);
if(DIFF_IS_SINGLE(diff)) {
*target++=(uint8_t)PACK_SINGLE_DIFF(diff);
*target++ = static_cast<uint8_t>(PACK_SINGLE_DIFF(diff));
*offsets++=sourceIndex;
--targetCapacity;
sourceIndex=nextSourceIndex;
@ -531,8 +531,8 @@ getTrail:
NEGDIVMOD(diff, BOCU1_TRAIL_COUNT, m);
diff+=BOCU1_START_NEG_2;
}
*target++=(uint8_t)diff;
*target++=(uint8_t)BOCU1_TRAIL_TO_BYTE(m);
*target++ = static_cast<uint8_t>(diff);
*target++ = static_cast<uint8_t>(BOCU1_TRAIL_TO_BYTE(m));
*offsets++=sourceIndex;
*offsets++=sourceIndex;
targetCapacity-=2;
@ -549,18 +549,18 @@ getTrail:
switch(length) {
/* each branch falls through to the next one */
case 4:
*target++=(uint8_t)(diff>>24);
*target++ = static_cast<uint8_t>(diff >> 24);
*offsets++=sourceIndex;
U_FALLTHROUGH;
case 3:
*target++=(uint8_t)(diff>>16);
*target++ = static_cast<uint8_t>(diff >> 16);
*offsets++=sourceIndex;
U_FALLTHROUGH;
case 2:
*target++=(uint8_t)(diff>>8);
*target++ = static_cast<uint8_t>(diff >> 8);
*offsets++=sourceIndex;
/* case 1: handled above */
*target++=(uint8_t)diff;
*target++ = static_cast<uint8_t>(diff);
*offsets++=sourceIndex;
U_FALLTHROUGH;
default:
@ -584,34 +584,34 @@ getTrail:
switch(length) {
/* each branch falls through to the next one */
case 3:
*charErrorBuffer++=(uint8_t)(diff>>16);
*charErrorBuffer++ = static_cast<uint8_t>(diff >> 16);
U_FALLTHROUGH;
case 2:
*charErrorBuffer++=(uint8_t)(diff>>8);
*charErrorBuffer++ = static_cast<uint8_t>(diff >> 8);
U_FALLTHROUGH;
case 1:
*charErrorBuffer=(uint8_t)diff;
*charErrorBuffer = static_cast<uint8_t>(diff);
U_FALLTHROUGH;
default:
/* will never occur */
break;
}
cnv->charErrorBufferLength=(int8_t)length;
cnv->charErrorBufferLength = static_cast<int8_t>(length);
/* now output what fits into the regular target */
diff>>=8*length; /* length was reduced by targetCapacity */
switch(targetCapacity) {
/* each branch falls through to the next one */
case 3:
*target++=(uint8_t)(diff>>16);
*target++ = static_cast<uint8_t>(diff >> 16);
*offsets++=sourceIndex;
U_FALLTHROUGH;
case 2:
*target++=(uint8_t)(diff>>8);
*target++ = static_cast<uint8_t>(diff >> 8);
*offsets++=sourceIndex;
U_FALLTHROUGH;
case 1:
*target++=(uint8_t)diff;
*target++ = static_cast<uint8_t>(diff);
*offsets++=sourceIndex;
U_FALLTHROUGH;
default:
@ -634,11 +634,11 @@ getTrail:
/* set the converter state back into UConverter */
cnv->fromUChar32= c<0 ? -c : 0;
cnv->fromUnicodeStatus=(uint32_t)prev;
cnv->fromUnicodeStatus = static_cast<uint32_t>(prev);
/* write back the updated pointers */
pArgs->source=source;
pArgs->target=(char *)target;
pArgs->target = reinterpret_cast<char*>(target);
pArgs->offsets=offsets;
}
@ -663,12 +663,12 @@ _Bocu1FromUnicode(UConverterFromUnicodeArgs *pArgs,
cnv=pArgs->converter;
source=pArgs->source;
sourceLimit=pArgs->sourceLimit;
target=(uint8_t *)pArgs->target;
targetCapacity=(int32_t)(pArgs->targetLimit-pArgs->target);
target = reinterpret_cast<uint8_t*>(pArgs->target);
targetCapacity = static_cast<int32_t>(pArgs->targetLimit - pArgs->target);
/* get the converter state from UConverter */
c=cnv->fromUChar32;
prev=(int32_t)cnv->fromUnicodeStatus;
prev = static_cast<int32_t>(cnv->fromUnicodeStatus);
if(prev==0) {
prev=BOCU1_ASCII_PREV;
}
@ -681,7 +681,7 @@ _Bocu1FromUnicode(UConverterFromUnicodeArgs *pArgs,
fastSingle:
/* fast loop for single-byte differences */
/* use only one loop counter variable, targetCapacity, not also source */
diff=(int32_t)(sourceLimit-source);
diff = static_cast<int32_t>(sourceLimit - source);
if(targetCapacity>diff) {
targetCapacity=diff;
}
@ -690,12 +690,12 @@ fastSingle:
if(c!=0x20) {
prev=BOCU1_ASCII_PREV;
}
*target++=(uint8_t)c;
*target++ = static_cast<uint8_t>(c);
} else {
diff=c-prev;
if(DIFF_IS_SINGLE(diff)) {
prev=BOCU1_SIMPLE_PREV(c);
*target++=(uint8_t)PACK_SINGLE_DIFF(diff);
*target++ = static_cast<uint8_t>(PACK_SINGLE_DIFF(diff));
} else {
break;
}
@ -704,7 +704,7 @@ fastSingle:
--targetCapacity;
}
/* restore real values */
targetCapacity=(int32_t)((const uint8_t *)pArgs->targetLimit-target);
targetCapacity = static_cast<int32_t>(reinterpret_cast<const uint8_t*>(pArgs->targetLimit) - target);
/* regular loop for all cases */
while(source<sourceLimit) {
@ -720,7 +720,7 @@ fastSingle:
if(c!=0x20) {
prev=BOCU1_ASCII_PREV;
}
*target++=(uint8_t)c;
*target++ = static_cast<uint8_t>(c);
--targetCapacity;
continue;
}
@ -753,7 +753,7 @@ getTrail:
diff=c-prev;
prev=BOCU1_PREV(c);
if(DIFF_IS_SINGLE(diff)) {
*target++=(uint8_t)PACK_SINGLE_DIFF(diff);
*target++ = static_cast<uint8_t>(PACK_SINGLE_DIFF(diff));
--targetCapacity;
if(c<0x3000) {
goto fastSingle;
@ -772,8 +772,8 @@ getTrail:
NEGDIVMOD(diff, BOCU1_TRAIL_COUNT, m);
diff+=BOCU1_START_NEG_2;
}
*target++=(uint8_t)diff;
*target++=(uint8_t)BOCU1_TRAIL_TO_BYTE(m);
*target++ = static_cast<uint8_t>(diff);
*target++ = static_cast<uint8_t>(BOCU1_TRAIL_TO_BYTE(m));
targetCapacity-=2;
} else {
int32_t length; /* will be 2..4 */
@ -787,14 +787,14 @@ getTrail:
switch(length) {
/* each branch falls through to the next one */
case 4:
*target++=(uint8_t)(diff>>24);
*target++ = static_cast<uint8_t>(diff >> 24);
U_FALLTHROUGH;
case 3:
*target++=(uint8_t)(diff>>16);
*target++ = static_cast<uint8_t>(diff >> 16);
/* case 2: handled above */
*target++=(uint8_t)(diff>>8);
*target++ = static_cast<uint8_t>(diff >> 8);
/* case 1: handled above */
*target++=(uint8_t)diff;
*target++ = static_cast<uint8_t>(diff);
U_FALLTHROUGH;
default:
/* will never occur */
@ -816,32 +816,32 @@ getTrail:
switch(length) {
/* each branch falls through to the next one */
case 3:
*charErrorBuffer++=(uint8_t)(diff>>16);
*charErrorBuffer++ = static_cast<uint8_t>(diff >> 16);
U_FALLTHROUGH;
case 2:
*charErrorBuffer++=(uint8_t)(diff>>8);
*charErrorBuffer++ = static_cast<uint8_t>(diff >> 8);
U_FALLTHROUGH;
case 1:
*charErrorBuffer=(uint8_t)diff;
*charErrorBuffer = static_cast<uint8_t>(diff);
U_FALLTHROUGH;
default:
/* will never occur */
break;
}
cnv->charErrorBufferLength=(int8_t)length;
cnv->charErrorBufferLength = static_cast<int8_t>(length);
/* now output what fits into the regular target */
diff>>=8*length; /* length was reduced by targetCapacity */
switch(targetCapacity) {
/* each branch falls through to the next one */
case 3:
*target++=(uint8_t)(diff>>16);
*target++ = static_cast<uint8_t>(diff >> 16);
U_FALLTHROUGH;
case 2:
*target++=(uint8_t)(diff>>8);
*target++ = static_cast<uint8_t>(diff >> 8);
U_FALLTHROUGH;
case 1:
*target++=(uint8_t)diff;
*target++ = static_cast<uint8_t>(diff);
U_FALLTHROUGH;
default:
/* will never occur */
@ -863,11 +863,11 @@ getTrail:
/* set the converter state back into UConverter */
cnv->fromUChar32= c<0 ? -c : 0;
cnv->fromUnicodeStatus=(uint32_t)prev;
cnv->fromUnicodeStatus = static_cast<uint32_t>(prev);
/* write back the updated pointers */
pArgs->source=source;
pArgs->target=(char *)target;
pArgs->target = reinterpret_cast<char*>(target);
}
/* BOCU-1-to-Unicode conversion functions ----------------------------------- */
@ -887,11 +887,11 @@ decodeBocu1LeadByte(int32_t b) {
/* positive difference */
if(b<BOCU1_START_POS_3) {
/* two bytes */
diff=((int32_t)b-BOCU1_START_POS_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_POS_1+1;
diff = (b - BOCU1_START_POS_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_POS_1 + 1;
count=1;
} else if(b<BOCU1_START_POS_4) {
/* three bytes */
diff=((int32_t)b-BOCU1_START_POS_3)*BOCU1_TRAIL_COUNT*BOCU1_TRAIL_COUNT+BOCU1_REACH_POS_2+1;
diff = (b - BOCU1_START_POS_3) * BOCU1_TRAIL_COUNT * BOCU1_TRAIL_COUNT + BOCU1_REACH_POS_2 + 1;
count=2;
} else {
/* four bytes */
@ -902,11 +902,11 @@ decodeBocu1LeadByte(int32_t b) {
/* negative difference */
if(b>=BOCU1_START_NEG_3) {
/* two bytes */
diff=((int32_t)b-BOCU1_START_NEG_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_NEG_1;
diff = (b - BOCU1_START_NEG_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_NEG_1;
count=1;
} else if(b>BOCU1_MIN) {
/* three bytes */
diff=((int32_t)b-BOCU1_START_NEG_3)*BOCU1_TRAIL_COUNT*BOCU1_TRAIL_COUNT+BOCU1_REACH_NEG_2;
diff = (b - BOCU1_START_NEG_3) * BOCU1_TRAIL_COUNT * BOCU1_TRAIL_COUNT + BOCU1_REACH_NEG_2;
count=2;
} else {
/* four bytes */
@ -916,7 +916,7 @@ decodeBocu1LeadByte(int32_t b) {
}
/* return the state for decoding the trail byte(s) */
return ((uint32_t)diff<<2)|count;
return (static_cast<uint32_t>(diff) << 2) | count;
}
/**
@ -970,14 +970,14 @@ _Bocu1ToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
/* set up the local pointers */
cnv=pArgs->converter;
source=(const uint8_t *)pArgs->source;
sourceLimit=(const uint8_t *)pArgs->sourceLimit;
source = reinterpret_cast<const uint8_t*>(pArgs->source);
sourceLimit = reinterpret_cast<const uint8_t*>(pArgs->sourceLimit);
target=pArgs->target;
targetLimit=pArgs->targetLimit;
offsets=pArgs->offsets;
/* get the converter state from UConverter */
prev=(int32_t)cnv->toUnicodeStatus;
prev = static_cast<int32_t>(cnv->toUnicodeStatus);
if(prev==0) {
prev=BOCU1_ASCII_PREV;
}
@ -1000,8 +1000,8 @@ _Bocu1ToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
fastSingle:
/* fast loop for single-byte differences */
/* use count as the only loop counter variable */
diff=(int32_t)(sourceLimit-source);
count=(int32_t)(pArgs->targetLimit-target);
diff = static_cast<int32_t>(sourceLimit - source);
count = static_cast<int32_t>(pArgs->targetLimit - target);
if(count>diff) {
count=diff;
}
@ -1009,7 +1009,7 @@ fastSingle:
if(BOCU1_START_NEG_2<=(c=*source) && c<BOCU1_START_POS_2) {
c=prev+(c-BOCU1_MIDDLE);
if(c<0x3000) {
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
*offsets++=nextSourceIndex++;
prev=BOCU1_SIMPLE_PREV(c);
} else {
@ -1019,7 +1019,7 @@ fastSingle:
if(c!=0x20) {
prev=BOCU1_ASCII_PREV;
}
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
*offsets++=nextSourceIndex++;
} else {
break;
@ -1043,7 +1043,7 @@ fastSingle:
/* Write a code point directly from a single-byte difference. */
c=prev+(c-BOCU1_MIDDLE);
if(c<0x3000) {
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
*offsets++=sourceIndex;
prev=BOCU1_SIMPLE_PREV(c);
sourceIndex=nextSourceIndex;
@ -1057,22 +1057,22 @@ fastSingle:
if(c!=0x20) {
prev=BOCU1_ASCII_PREV;
}
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
*offsets++=sourceIndex;
sourceIndex=nextSourceIndex;
continue;
} else if(BOCU1_START_NEG_3<=c && c<BOCU1_START_POS_3 && source<sourceLimit) {
/* Optimize two-byte case. */
if(c>=BOCU1_MIDDLE) {
diff=((int32_t)c-BOCU1_START_POS_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_POS_1+1;
diff = (c - BOCU1_START_POS_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_POS_1 + 1;
} else {
diff=((int32_t)c-BOCU1_START_NEG_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_NEG_1;
diff = (c - BOCU1_START_NEG_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_NEG_1;
}
/* trail byte */
++nextSourceIndex;
c=decodeBocu1TrailByte(1, *source++);
if(c<0 || (uint32_t)(c=prev+diff+c)>0x10ffff) {
if (c < 0 || static_cast<uint32_t>(c = prev + diff + c) > 0x10ffff) {
bytes[0]=source[-2];
bytes[1]=source[-1];
byteIndex=2;
@ -1090,7 +1090,7 @@ fastSingle:
* with the partial difference value from the lead byte and
* with the number of trail bytes.
*/
bytes[0]=(uint8_t)c;
bytes[0] = static_cast<uint8_t>(c);
byteIndex=1;
diff=decodeBocu1LeadByte(c);
@ -1116,7 +1116,7 @@ getTrail:
/* final trail byte, deliver a code point */
byteIndex=0;
c=prev+diff;
if((uint32_t)c>0x10ffff) {
if (static_cast<uint32_t>(c) > 0x10ffff) {
*pErrorCode=U_ILLEGAL_CHAR_FOUND;
goto endloop;
}
@ -1128,7 +1128,7 @@ getTrail:
/* calculate the next prev and output c */
prev=BOCU1_PREV(c);
if(c<=0xffff) {
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
*offsets++=sourceIndex;
} else {
/* output surrogate pair */
@ -1156,13 +1156,13 @@ endloop:
cnv->mode=0;
} else {
/* set the converter state back into UConverter */
cnv->toUnicodeStatus=(uint32_t)prev;
cnv->mode=(int32_t)((uint32_t)diff<<2)|count;
cnv->toUnicodeStatus = static_cast<uint32_t>(prev);
cnv->mode = static_cast<int32_t>(static_cast<uint32_t>(diff) << 2) | count;
}
cnv->toULength=byteIndex;
/* write back the updated pointers */
pArgs->source=(const char *)source;
pArgs->source = reinterpret_cast<const char*>(source);
pArgs->target=target;
pArgs->offsets=offsets;
}
@ -1189,13 +1189,13 @@ _Bocu1ToUnicode(UConverterToUnicodeArgs *pArgs,
/* set up the local pointers */
cnv=pArgs->converter;
source=(const uint8_t *)pArgs->source;
sourceLimit=(const uint8_t *)pArgs->sourceLimit;
source = reinterpret_cast<const uint8_t*>(pArgs->source);
sourceLimit = reinterpret_cast<const uint8_t*>(pArgs->sourceLimit);
target=pArgs->target;
targetLimit=pArgs->targetLimit;
/* get the converter state from UConverter */
prev=(int32_t)cnv->toUnicodeStatus;
prev = static_cast<int32_t>(cnv->toUnicodeStatus);
if(prev==0) {
prev=BOCU1_ASCII_PREV;
}
@ -1214,8 +1214,8 @@ _Bocu1ToUnicode(UConverterToUnicodeArgs *pArgs,
fastSingle:
/* fast loop for single-byte differences */
/* use count as the only loop counter variable */
diff=(int32_t)(sourceLimit-source);
count=(int32_t)(pArgs->targetLimit-target);
diff = static_cast<int32_t>(sourceLimit - source);
count = static_cast<int32_t>(pArgs->targetLimit - target);
if(count>diff) {
count=diff;
}
@ -1223,7 +1223,7 @@ fastSingle:
if(BOCU1_START_NEG_2<=(c=*source) && c<BOCU1_START_POS_2) {
c=prev+(c-BOCU1_MIDDLE);
if(c<0x3000) {
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
prev=BOCU1_SIMPLE_PREV(c);
} else {
break;
@ -1232,7 +1232,7 @@ fastSingle:
if(c!=0x20) {
prev=BOCU1_ASCII_PREV;
}
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
} else {
break;
}
@ -1253,7 +1253,7 @@ fastSingle:
/* Write a code point directly from a single-byte difference. */
c=prev+(c-BOCU1_MIDDLE);
if(c<0x3000) {
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
prev=BOCU1_SIMPLE_PREV(c);
goto fastSingle;
}
@ -1265,19 +1265,19 @@ fastSingle:
if(c!=0x20) {
prev=BOCU1_ASCII_PREV;
}
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
continue;
} else if(BOCU1_START_NEG_3<=c && c<BOCU1_START_POS_3 && source<sourceLimit) {
/* Optimize two-byte case. */
if(c>=BOCU1_MIDDLE) {
diff=((int32_t)c-BOCU1_START_POS_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_POS_1+1;
diff = (c - BOCU1_START_POS_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_POS_1 + 1;
} else {
diff=((int32_t)c-BOCU1_START_NEG_2)*BOCU1_TRAIL_COUNT+BOCU1_REACH_NEG_1;
diff = (c - BOCU1_START_NEG_2) * BOCU1_TRAIL_COUNT + BOCU1_REACH_NEG_1;
}
/* trail byte */
c=decodeBocu1TrailByte(1, *source++);
if(c<0 || (uint32_t)(c=prev+diff+c)>0x10ffff) {
if (c < 0 || static_cast<uint32_t>(c = prev + diff + c) > 0x10ffff) {
bytes[0]=source[-2];
bytes[1]=source[-1];
byteIndex=2;
@ -1294,7 +1294,7 @@ fastSingle:
* with the partial difference value from the lead byte and
* with the number of trail bytes.
*/
bytes[0]=(uint8_t)c;
bytes[0] = static_cast<uint8_t>(c);
byteIndex=1;
diff=decodeBocu1LeadByte(c);
@ -1319,7 +1319,7 @@ getTrail:
/* final trail byte, deliver a code point */
byteIndex=0;
c=prev+diff;
if((uint32_t)c>0x10ffff) {
if (static_cast<uint32_t>(c) > 0x10ffff) {
*pErrorCode=U_ILLEGAL_CHAR_FOUND;
goto endloop;
}
@ -1331,7 +1331,7 @@ getTrail:
/* calculate the next prev and output c */
prev=BOCU1_PREV(c);
if(c<=0xffff) {
*target++=(char16_t)c;
*target++ = static_cast<char16_t>(c);
} else {
/* output surrogate pair */
*target++=U16_LEAD(c);
@ -1354,13 +1354,13 @@ endloop:
cnv->mode=0;
} else {
/* set the converter state back into UConverter */
cnv->toUnicodeStatus=(uint32_t)prev;
cnv->mode=((uint32_t)diff<<2)|count;
cnv->toUnicodeStatus = static_cast<uint32_t>(prev);
cnv->mode = (static_cast<uint32_t>(diff) << 2) | count;
}
cnv->toULength=byteIndex;
/* write back the updated pointers */
pArgs->source=(const char *)source;
pArgs->source = reinterpret_cast<const char*>(source);
pArgs->target=target;
}

View file

@ -345,7 +345,7 @@ UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
uint32_t targetUniChar = 0x0000;
UChar32 mySourceChar = 0x0000;
UConverterDataHZ *myConverterData=(UConverterDataHZ*)args->converter->extraInfo;
UBool isTargetUCharDBCS = (UBool) myConverterData->isTargetUCharDBCS;
UBool isTargetUCharDBCS = myConverterData->isTargetUCharDBCS;
UBool oldIsTargetUCharDBCS;
int len =0;
const char* escSeq=nullptr;
@ -363,7 +363,7 @@ UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
targetUniChar = missingCharMarker;
if (myTargetIndex < targetLength){
mySourceChar = (char16_t) mySource[mySourceIndex++];
mySourceChar = mySource[mySourceIndex++];
oldIsTargetUCharDBCS = isTargetUCharDBCS;
@ -389,7 +389,7 @@ UConverter_fromUnicode_HZ_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args,
}
}
if (targetUniChar != missingCharMarker){
myConverterData->isTargetUCharDBCS = isTargetUCharDBCS = (UBool)(targetUniChar>0x00FF);
myConverterData->isTargetUCharDBCS = isTargetUCharDBCS = targetUniChar > 0x00FF;
if(oldIsTargetUCharDBCS != isTargetUCharDBCS || !myConverterData->isEscapeAppended ){
/*Shifting from a double byte to single byte mode*/
if(!isTargetUCharDBCS){

View file

@ -174,7 +174,7 @@ isPNJConsonant(UChar32 c) {
if (c < 0xa00 || 0xa50 <= c) {
return false;
} else {
return (UBool)(pnjMap[c - 0xa00] & 1);
return pnjMap[c - 0xa00] & 1;
}
}
@ -183,7 +183,7 @@ isPNJBindiTippi(UChar32 c) {
if (c < 0xa00 || 0xa50 <= c) {
return false;
} else {
return (UBool)(pnjMap[c - 0xa00] >> 1);
return pnjMap[c - 0xa00] >> 1;
}
}
U_CDECL_BEGIN
@ -1484,7 +1484,7 @@ UConverter_toUnicode_ISCII_OFFSETS_LOGIC(UConverterToUnicodeArgs *args, UErrorCo
*/
*err = U_INVALID_CHAR_FOUND;
CALLBACK:
args->converter->toUBytes[0] = (uint8_t) sourceChar;
args->converter->toUBytes[0] = sourceChar;
args->converter->toULength = 1;
break;
}

View file

@ -381,7 +381,7 @@ ucnv_Latin1FromUTF8(UConverterFromUnicodeArgs *pFromUArgs,
b=*source++;
if(U8_IS_SINGLE(b)) {
/* convert ASCII */
*target++=(uint8_t)b;
*target++ = b;
--targetCapacity;
} else if( /* handle U+0080..U+00FF inline */
b>=0xc2 && b<=0xc3 &&

File diff suppressed because it is too large Load diff

View file

@ -883,8 +883,8 @@ static int8_t
getWindow(const uint32_t offsets[8], uint32_t c) {
int i;
for(i=0; i<8; ++i) {
if((uint32_t)(c-offsets[i])<=0x7f) {
return (int8_t)(i);
if (c - offsets[i] <= 0x7f) {
return static_cast<int8_t>(i);
}
}
return -1;
@ -893,9 +893,9 @@ getWindow(const uint32_t offsets[8], uint32_t c) {
/* is the character in the dynamic window starting at the offset, or in the direct-encoded range? */
static UBool
isInOffsetWindowOrDirect(uint32_t offset, uint32_t c) {
return (UBool)(c<=offset+0x7f &&
return c<=offset+0x7f &&
(c>=offset || (c<=0x7f &&
(c>=0x20 || (1UL<<c)&0x2601))));
(c>=0x20 || (1UL<<c)&0x2601)));
/* binary 0010 0110 0000 0001,
check for b==0xd || b==0xa || b==9 || b==0 */
}
@ -963,7 +963,7 @@ getDynamicOffset(uint32_t c, uint32_t *pOffset) {
int i;
for(i=0; i<7; ++i) {
if((uint32_t)(c-fixedOffsets[i])<=0x7f) {
if (c - fixedOffsets[i] <= 0x7f) {
*pOffset=fixedOffsets[i];
return 0xf9+i;
}
@ -973,16 +973,16 @@ getDynamicOffset(uint32_t c, uint32_t *pOffset) {
/* No dynamic window for US-ASCII. */
return -1;
} else if(c<0x3400 ||
(uint32_t)(c-0x10000)<(0x14000-0x10000) ||
(uint32_t)(c-0x1d000)<=(0x1ffff-0x1d000)
c - 0x10000 < 0x14000 - 0x10000 ||
c - 0x1d000 <= 0x1ffff - 0x1d000
) {
/* This character is in a code range for a "small", i.e., reasonably windowable, script. */
*pOffset=c&0x7fffff80;
return (int)(c>>7);
return static_cast<int>(c >> 7);
} else if(0xe000<=c && c!=0xfeff && c<0xfff0) {
/* For these characters we need to take the gapOffset into account. */
*pOffset=c&0x7fffff80;
return (int)((c-gapOffset)>>7);
return static_cast<int>((c - gapOffset) >> 7);
} else {
return -1;
}
@ -1208,8 +1208,8 @@ getTrailSingle:
c=((uint32_t)(SD0+dynamicWindow)<<16)|((uint32_t)code<<8)|(c-currentOffset)|0x80;
length=3;
goto outputBytes;
} else if((uint32_t)(c-0x3400)<(0xd800-0x3400) &&
(source>=sourceLimit || (uint32_t)(*source-0x3400)<(0xd800-0x3400))
} else if ((c - 0x3400) < (0xd800 - 0x3400) &&
(source >= sourceLimit || (uint32_t)(*source - 0x3400) < (0xd800 - 0x3400))
) {
/*
* this character is not compressible (a BMP ideograph or similar);
@ -1248,7 +1248,7 @@ getTrailSingle:
c=*source++;
++nextSourceIndex;
if((uint32_t)(c-0x3400)<(0xd800-0x3400)) {
if ((c - 0x3400) < (0xd800 - 0x3400)) {
/* not compressible, write character directly */
if(targetCapacity>=2) {
*target++=(uint8_t)(c>>8);
@ -1262,10 +1262,10 @@ getTrailSingle:
length=2;
goto outputBytes;
}
} else if((uint32_t)(c-0x3400)>=(0xf300-0x3400) /* c<0x3400 || c>=0xf300 */) {
} else if (c - 0x3400 >= 0xf300 - 0x3400 /* c<0x3400 || c>=0xf300 */) {
/* compress BMP character if the following one is not an uncompressible ideograph */
if(!(source<sourceLimit && (uint32_t)(*source-0x3400)<(0xd800-0x3400))) {
if(((uint32_t)(c-0x30)<10 || (uint32_t)(c-0x61)<26 || (uint32_t)(c-0x41)<26)) {
if (c - 0x30 < 10 || c - 0x61 < 26 || c - 0x41 < 26) {
/* ASCII digit or letter */
isSingleByteMode=true;
c|=((uint32_t)(UC0+dynamicWindow)<<8)|c;
@ -1691,8 +1691,8 @@ getTrailSingle:
c=((uint32_t)(SD0+dynamicWindow)<<16)|((uint32_t)code<<8)|(c-currentOffset)|0x80;
length=3;
goto outputBytes;
} else if((uint32_t)(c-0x3400)<(0xd800-0x3400) &&
(source>=sourceLimit || (uint32_t)(*source-0x3400)<(0xd800-0x3400))
} else if (c - 0x3400 < 0xd800 - 0x3400 &&
(source >= sourceLimit || static_cast<uint32_t>(*source - 0x3400) < 0xd800 - 0x3400)
) {
/*
* this character is not compressible (a BMP ideograph or similar);
@ -1729,7 +1729,7 @@ getTrailSingle:
}
c=*source++;
if((uint32_t)(c-0x3400)<(0xd800-0x3400)) {
if (c - 0x3400 < 0xd800 - 0x3400) {
/* not compressible, write character directly */
if(targetCapacity>=2) {
*target++=(uint8_t)(c>>8);
@ -1739,10 +1739,10 @@ getTrailSingle:
length=2;
goto outputBytes;
}
} else if((uint32_t)(c-0x3400)>=(0xf300-0x3400) /* c<0x3400 || c>=0xf300 */) {
} else if (c - 0x3400 >= 0xf300 - 0x3400 /* c<0x3400 || c>=0xf300 */) {
/* compress BMP character if the following one is not an uncompressible ideograph */
if(!(source<sourceLimit && (uint32_t)(*source-0x3400)<(0xd800-0x3400))) {
if(((uint32_t)(c-0x30)<10 || (uint32_t)(c-0x61)<26 || (uint32_t)(c-0x41)<26)) {
if (c - 0x30 < 10 || c - 0x61 < 26 || c - 0x41 < 26) {
/* ASCII digit or letter */
isSingleByteMode=true;
c|=((uint32_t)(UC0+dynamicWindow)<<8)|c;

View file

@ -377,7 +377,7 @@ ucnvsel_swap(const UDataSwapper *ds,
}
/* check data format and format version */
const UDataInfo *pInfo = (const UDataInfo *)((const char *)inData + 4);
const UDataInfo* pInfo = reinterpret_cast<const UDataInfo*>(static_cast<const char*>(inData) + 4);
if(!(
pInfo->dataFormat[0] == 0x43 && /* dataFormat="CSel" */
pInfo->dataFormat[1] == 0x53 &&
@ -407,11 +407,11 @@ ucnvsel_swap(const UDataSwapper *ds,
}
}
const uint8_t *inBytes = (const uint8_t *)inData + headerSize;
uint8_t *outBytes = (uint8_t *)outData + headerSize;
const uint8_t* inBytes = static_cast<const uint8_t*>(inData) + headerSize;
uint8_t* outBytes = static_cast<uint8_t*>(outData) + headerSize;
/* read the indexes */
const int32_t *inIndexes = (const int32_t *)inBytes;
const int32_t* inIndexes = reinterpret_cast<const int32_t*>(inBytes);
int32_t indexes[16];
int32_t i;
for(i = 0; i < 16; ++i) {

View file

@ -108,11 +108,11 @@ swapFormatVersion3(const UDataSwapper *ds,
return 0;
}
inBytes=(const uint8_t *)inData;
outBytes=(uint8_t *)outData;
inBytes = static_cast<const uint8_t*>(inData);
outBytes = static_cast<uint8_t*>(outData);
inHeader=(const UCATableHeader *)inData;
outHeader=(UCATableHeader *)outData;
inHeader = static_cast<const UCATableHeader*>(inData);
outHeader = static_cast<UCATableHeader*>(outData);
/*
* The collation binary must contain at least the UCATableHeader,
@ -175,7 +175,7 @@ swapFormatVersion3(const UDataSwapper *ds,
header.leadByteToScript= ds->readUInt32(inHeader->leadByteToScript);
/* swap the 32-bit integers in the header */
ds->swapArray32(ds, inHeader, (int32_t)((const char *)&inHeader->jamoSpecial-(const char *)inHeader),
ds->swapArray32(ds, inHeader, static_cast<int32_t>(reinterpret_cast<const char*>(&inHeader->jamoSpecial) - reinterpret_cast<const char*>(inHeader)),
outHeader, pErrorCode);
ds->swapArray32(ds, &(inHeader->scriptToLeadByte), sizeof(header.scriptToLeadByte) + sizeof(header.leadByteToScript),
&(outHeader->scriptToLeadByte), pErrorCode);
@ -198,7 +198,7 @@ swapFormatVersion3(const UDataSwapper *ds,
/* no contractions: expansions bounded by the main trie */
count=header.mappingPosition-header.expansion;
}
ds->swapArray32(ds, inBytes+header.expansion, (int32_t)count,
ds->swapArray32(ds, inBytes + header.expansion, static_cast<int32_t>(count),
outBytes+header.expansion, pErrorCode);
}
@ -216,7 +216,7 @@ swapFormatVersion3(const UDataSwapper *ds,
/* swap the main trie */
if(header.mappingPosition!=0) {
count=header.endExpansionCE-header.mappingPosition;
utrie_swap(ds, inBytes+header.mappingPosition, (int32_t)count,
utrie_swap(ds, inBytes + header.mappingPosition, static_cast<int32_t>(count),
outBytes+header.mappingPosition, pErrorCode);
}
@ -241,7 +241,7 @@ swapFormatVersion3(const UDataSwapper *ds,
/* swap UCA contractions */
if(header.contractionUCACombosSize!=0) {
count=header.contractionUCACombosSize*inHeader->contractionUCACombosWidth*U_SIZEOF_UCHAR;
ds->swapArray16(ds, inBytes+header.contractionUCACombos, (int32_t)count,
ds->swapArray16(ds, inBytes + header.contractionUCACombos, static_cast<int32_t>(count),
outBytes+header.contractionUCACombos, pErrorCode);
}
@ -306,10 +306,10 @@ swapFormatVersion4(const UDataSwapper *ds,
UErrorCode &errorCode) {
if(U_FAILURE(errorCode)) { return 0; }
const uint8_t *inBytes=(const uint8_t *)inData;
uint8_t *outBytes=(uint8_t *)outData;
const uint8_t* inBytes = static_cast<const uint8_t*>(inData);
uint8_t* outBytes = static_cast<uint8_t*>(outData);
const int32_t *inIndexes=(const int32_t *)inBytes;
const int32_t* inIndexes = reinterpret_cast<const int32_t*>(inBytes);
int32_t indexes[IX_TOTAL_SIZE+1];
// Need at least IX_INDEXES_LENGTH and IX_OPTIONS.

View file

@ -258,11 +258,11 @@ inline uint32_t maybeFilterValue(uint32_t value, uint32_t trieNullValue, uint32_
UChar32 getRange(const void *t, UChar32 start,
UCPMapValueFilter *filter, const void *context, uint32_t *pValue) {
if ((uint32_t)start > MAX_UNICODE) {
if (static_cast<uint32_t>(start) > MAX_UNICODE) {
return U_SENTINEL;
}
const UCPTrie *trie = reinterpret_cast<const UCPTrie *>(t);
UCPTrieValueWidth valueWidth = (UCPTrieValueWidth)trie->valueWidth;
UCPTrieValueWidth valueWidth = static_cast<UCPTrieValueWidth>(trie->valueWidth);
if (start >= trie->highStart) {
if (pValue != nullptr) {
int32_t di = trie->dataLength - UCPTRIE_HIGH_VALUE_NEG_DATA_OFFSET;
@ -304,7 +304,7 @@ UChar32 getRange(const void *t, UChar32 start,
i1 += UCPTRIE_SMALL_INDEX_LENGTH;
}
i3Block = trie->index[
(int32_t)trie->index[i1] + ((c >> UCPTRIE_SHIFT_2) & UCPTRIE_INDEX_2_MASK)];
static_cast<int32_t>(trie->index[i1]) + ((c >> UCPTRIE_SHIFT_2) & UCPTRIE_INDEX_2_MASK)];
if (i3Block == prevI3Block && (c - start) >= UCPTRIE_CP_PER_INDEX_2_ENTRY) {
// The index-3 block is the same as the previous one, and filled with value.
U_ASSERT((c & (UCPTRIE_CP_PER_INDEX_2_ENTRY - 1)) == 0);
@ -341,7 +341,7 @@ UChar32 getRange(const void *t, UChar32 start,
// 18-bit indexes stored in groups of 9 entries per 8 indexes.
int32_t group = (i3Block & 0x7fff) + (i3 & ~7) + (i3 >> 3);
int32_t gi = i3 & 7;
block = ((int32_t)index[group++] << (2 + (2 * gi))) & 0x30000;
block = (static_cast<int32_t>(index[group++]) << (2 + (2 * gi))) & 0x30000;
block |= index[group + gi];
}
if (block == prevBlock && (c - start) >= dataBlockLength) {

View file

@ -130,7 +130,7 @@ private:
const icu::UnicodeString *
EquivIterator::next() {
const icu::UnicodeString* _next = (const icu::UnicodeString*) _hash.get(*_current);
const icu::UnicodeString* _next = static_cast<const icu::UnicodeString*>(_hash.get(*_current));
if (_next == nullptr) {
U_ASSERT(_current == _start);
return nullptr;
@ -260,7 +260,7 @@ currSymbolsEquiv_cleanup()
*/
static void U_CALLCONV
deleteIsoCodeEntry(void *obj) {
IsoCodeEntry *entry = (IsoCodeEntry*)obj;
IsoCodeEntry* entry = static_cast<IsoCodeEntry*>(obj);
uprv_free(entry);
}
@ -269,7 +269,7 @@ deleteIsoCodeEntry(void *obj) {
*/
static void U_CALLCONV
deleteUnicode(void *obj) {
icu::UnicodeString *entry = (icu::UnicodeString*)obj;
icu::UnicodeString* entry = static_cast<icu::UnicodeString*>(obj);
delete entry;
}
@ -306,10 +306,9 @@ _findMetaData(const char16_t* currency, UErrorCode& ec) {
// move out of the root locale file later; if it does, update this
// code.]
UResourceBundle* currencyData = ures_openDirect(U_ICUDATA_CURR, CURRENCY_DATA, &ec);
UResourceBundle* currencyMeta = ures_getByKey(currencyData, CURRENCY_META, currencyData, &ec);
LocalUResourceBundlePointer currencyMeta(ures_getByKey(currencyData, CURRENCY_META, currencyData, &ec));
if (U_FAILURE(ec)) {
ures_close(currencyMeta);
// Config/build error; return hard-coded defaults
return LAST_RESORT_DATA;
}
@ -317,32 +316,25 @@ _findMetaData(const char16_t* currency, UErrorCode& ec) {
// Look up our currency, or if that's not available, then DEFAULT
char buf[ISO_CURRENCY_CODE_LENGTH+1];
UErrorCode ec2 = U_ZERO_ERROR; // local error code: soft failure
UResourceBundle* rb = ures_getByKey(currencyMeta, myUCharsToChars(buf, currency), nullptr, &ec2);
LocalUResourceBundlePointer rb(ures_getByKey(currencyMeta.getAlias(), myUCharsToChars(buf, currency), nullptr, &ec2));
if (U_FAILURE(ec2)) {
ures_close(rb);
rb = ures_getByKey(currencyMeta,DEFAULT_META, nullptr, &ec);
rb.adoptInstead(ures_getByKey(currencyMeta.getAlias(),DEFAULT_META, nullptr, &ec));
if (U_FAILURE(ec)) {
ures_close(currencyMeta);
ures_close(rb);
// Config/build error; return hard-coded defaults
return LAST_RESORT_DATA;
}
}
int32_t len;
const int32_t *data = ures_getIntVector(rb, &len, &ec);
const int32_t *data = ures_getIntVector(rb.getAlias(), &len, &ec);
if (U_FAILURE(ec) || len != 4) {
// Config/build error; return hard-coded defaults
if (U_SUCCESS(ec)) {
ec = U_INVALID_FORMAT_ERROR;
}
ures_close(currencyMeta);
ures_close(rb);
return LAST_RESORT_DATA;
}
ures_close(currencyMeta);
ures_close(rb);
return data;
}
@ -380,8 +372,8 @@ struct CReg : public icu::UMemory {
CReg(const char16_t* _iso, const char* _id)
: next(nullptr)
{
int32_t len = (int32_t)uprv_strlen(_id);
if (len > (int32_t)(sizeof(id)-1)) {
int32_t len = static_cast<int32_t>(uprv_strlen(_id));
if (len > static_cast<int32_t>(sizeof(id) - 1)) {
len = (sizeof(id)-1);
}
uprv_strncpy(id, _id, len);
@ -565,14 +557,14 @@ ucurr_forLocale(const char* locale,
localStatus = U_ZERO_ERROR;
UResourceBundle *rb = ures_openDirect(U_ICUDATA_CURR, CURRENCY_DATA, &localStatus);
UResourceBundle *cm = ures_getByKey(rb, CURRENCY_MAP, rb, &localStatus);
UResourceBundle *countryArray = ures_getByKey(rb, id.data(), cm, &localStatus);
LocalUResourceBundlePointer countryArray(ures_getByKey(rb, id.data(), cm, &localStatus));
// https://unicode-org.atlassian.net/browse/ICU-21997
// Prefer to use currencies that are legal tender.
if (U_SUCCESS(localStatus)) {
int32_t arrayLength = ures_getSize(countryArray);
int32_t arrayLength = ures_getSize(countryArray.getAlias());
for (int32_t i = 0; i < arrayLength; ++i) {
LocalUResourceBundlePointer currencyReq(
ures_getByIndex(countryArray, i, nullptr, &localStatus));
ures_getByIndex(countryArray.getAlias(), i, nullptr, &localStatus));
// The currency is legal tender if it is *not* marked with tender{"false"}.
UErrorCode tenderStatus = localStatus;
const char16_t *tender =
@ -592,7 +584,6 @@ ucurr_forLocale(const char* locale,
localStatus = U_MISSING_RESOURCE_ERROR;
}
}
ures_close(countryArray);
}
if ((U_FAILURE(localStatus)) && strchr(id.data(), '_') != nullptr) {
@ -805,21 +796,19 @@ ucurr_getPluralName(const char16_t* currency,
rb = ures_getByKey(rb, CURRENCYPLURALS, rb, &ec2);
// Fetch resource with multi-level resource inheritance fallback
rb = ures_getByKeyWithFallback(rb, buf, rb, &ec2);
LocalUResourceBundlePointer curr(ures_getByKeyWithFallback(rb, buf, rb, &ec2));
s = ures_getStringByKeyWithFallback(rb, pluralCount, len, &ec2);
s = ures_getStringByKeyWithFallback(curr.getAlias(), pluralCount, len, &ec2);
if (U_FAILURE(ec2)) {
// fall back to "other"
ec2 = U_ZERO_ERROR;
s = ures_getStringByKeyWithFallback(rb, "other", len, &ec2);
s = ures_getStringByKeyWithFallback(curr.getAlias(), "other", len, &ec2);
if (U_FAILURE(ec2)) {
ures_close(rb);
// fall back to long name in Currencies
return ucurr_getName(currency, locale, UCURR_LONG_NAME,
isChoiceFormat, len, ec);
}
}
ures_close(rb);
// If we've succeeded we're done. Otherwise, try to fallback.
// If that fails (because we are already at root) then exit.
@ -866,8 +855,8 @@ typedef struct {
// Comparison function used in quick sort.
static int U_CALLCONV currencyNameComparator(const void* a, const void* b) {
const CurrencyNameStruct* currName_1 = (const CurrencyNameStruct*)a;
const CurrencyNameStruct* currName_2 = (const CurrencyNameStruct*)b;
const CurrencyNameStruct* currName_1 = static_cast<const CurrencyNameStruct*>(a);
const CurrencyNameStruct* currName_2 = static_cast<const CurrencyNameStruct*>(b);
for (int32_t i = 0;
i < MIN(currName_1->currencyNameLen, currName_2->currencyNameLen);
++i) {
@ -911,34 +900,29 @@ getCurrencyNameCount(const char* loc, int32_t* total_currency_name_count, int32_
for (;;) {
UErrorCode ec2 = U_ZERO_ERROR;
// TODO: ures_openDirect?
UResourceBundle* rb = ures_open(U_ICUDATA_CURR, locale.data(), &ec2);
UResourceBundle* curr = ures_getByKey(rb, CURRENCIES, nullptr, &ec2);
int32_t n = ures_getSize(curr);
LocalUResourceBundlePointer rb(ures_open(U_ICUDATA_CURR, locale.data(), &ec2));
LocalUResourceBundlePointer curr(ures_getByKey(rb.getAlias(), CURRENCIES, nullptr, &ec2));
int32_t n = ures_getSize(curr.getAlias());
for (int32_t i=0; i<n; ++i) {
UResourceBundle* names = ures_getByIndex(curr, i, nullptr, &ec2);
LocalUResourceBundlePointer names(ures_getByIndex(curr.getAlias(), i, nullptr, &ec2));
int32_t len;
s = ures_getStringByIndex(names, UCURR_SYMBOL_NAME, &len, &ec2);
s = ures_getStringByIndex(names.getAlias(), UCURR_SYMBOL_NAME, &len, &ec2);
++(*total_currency_symbol_count); // currency symbol
if (currencySymbolsEquiv != nullptr) {
*total_currency_symbol_count += countEquivalent(*currencySymbolsEquiv, UnicodeString(true, s, len));
}
++(*total_currency_symbol_count); // iso code
++(*total_currency_name_count); // long name
ures_close(names);
}
// currency plurals
UErrorCode ec3 = U_ZERO_ERROR;
UResourceBundle* curr_p = ures_getByKey(rb, CURRENCYPLURALS, nullptr, &ec3);
n = ures_getSize(curr_p);
LocalUResourceBundlePointer curr_p(ures_getByKey(rb.getAlias(), CURRENCYPLURALS, nullptr, &ec3));
n = ures_getSize(curr_p.getAlias());
for (int32_t i=0; i<n; ++i) {
UResourceBundle* names = ures_getByIndex(curr_p, i, nullptr, &ec3);
*total_currency_name_count += ures_getSize(names);
ures_close(names);
LocalUResourceBundlePointer names(ures_getByIndex(curr_p.getAlias(), i, nullptr, &ec3));
*total_currency_name_count += ures_getSize(names.getAlias());
}
ures_close(curr_p);
ures_close(curr);
ures_close(rb);
if (!fallback(locale)) {
break;
@ -953,7 +937,10 @@ toUpperCase(const char16_t* source, int32_t len, const char* locale) {
int32_t destLen = u_strToUpper(dest, 0, source, len, locale, &ec);
ec = U_ZERO_ERROR;
dest = (char16_t*)uprv_malloc(sizeof(char16_t) * MAX(destLen, len));
dest = static_cast<char16_t*>(uprv_malloc(sizeof(char16_t) * MAX(destLen, len)));
if (dest == nullptr) {
return nullptr;
}
u_strToUpper(dest, destLen, source, len, locale, &ec);
if (U_FAILURE(ec)) {
u_memcpy(dest, source, len);
@ -962,6 +949,7 @@ toUpperCase(const char16_t* source, int32_t len, const char* locale) {
}
static void deleteCurrencyNames(CurrencyNameStruct* currencyNames, int32_t count);
// Collect all available currency names associated with the given locale
// (enable fallback chain).
// Read currenc names defined in resource bundle "Currencies" and
@ -975,6 +963,11 @@ collectCurrencyNames(const char* locale,
CurrencyNameStruct** currencySymbols,
int32_t* total_currency_symbol_count,
UErrorCode& ec) {
if (U_FAILURE(ec)) {
*currencyNames = *currencySymbols = nullptr;
*total_currency_name_count = *total_currency_symbol_count = 0;
return;
}
U_NAMESPACE_USE
const icu::Hashtable *currencySymbolsEquiv = getCurrSymbolsEquiv();
// Look up the Currencies resource for the given locale.
@ -983,21 +976,32 @@ collectCurrencyNames(const char* locale,
CharString loc = ulocimp_getName(locale, ec2);
if (U_FAILURE(ec2)) {
ec = U_ILLEGAL_ARGUMENT_ERROR;
*currencyNames = *currencySymbols = nullptr;
*total_currency_name_count = *total_currency_symbol_count = 0;
return;
}
// Get maximum currency name count first.
getCurrencyNameCount(loc.data(), total_currency_name_count, total_currency_symbol_count);
*currencyNames = (CurrencyNameStruct*)uprv_malloc
(sizeof(CurrencyNameStruct) * (*total_currency_name_count));
*currencySymbols = (CurrencyNameStruct*)uprv_malloc
(sizeof(CurrencyNameStruct) * (*total_currency_symbol_count));
if(currencyNames == nullptr || currencySymbols == nullptr) {
ec = U_MEMORY_ALLOCATION_ERROR;
*currencyNames = static_cast<CurrencyNameStruct*>(
uprv_malloc(sizeof(CurrencyNameStruct) * (*total_currency_name_count)));
if(*currencyNames == nullptr) {
*currencySymbols = nullptr;
*total_currency_name_count = *total_currency_symbol_count = 0;
ec = U_MEMORY_ALLOCATION_ERROR;
return;
}
*currencySymbols = static_cast<CurrencyNameStruct*>(
uprv_malloc(sizeof(CurrencyNameStruct) * (*total_currency_symbol_count)));
if (U_FAILURE(ec)) return;
if(*currencySymbols == nullptr) {
uprv_free(*currencyNames);
*currencyNames = nullptr;
*total_currency_name_count = *total_currency_symbol_count = 0;
ec = U_MEMORY_ALLOCATION_ERROR;
return;
}
const char16_t* s = nullptr; // currency name
char* iso = nullptr; // currency ISO code
@ -1009,113 +1013,91 @@ collectCurrencyNames(const char* locale,
UErrorCode ec4 = U_ZERO_ERROR;
// Using hash to remove duplicates caused by locale fallback
UHashtable* currencyIsoCodes = uhash_open(uhash_hashChars, uhash_compareChars, nullptr, &ec3);
UHashtable* currencyPluralIsoCodes = uhash_open(uhash_hashChars, uhash_compareChars, nullptr, &ec4);
LocalUHashtablePointer currencyIsoCodes(uhash_open(uhash_hashChars, uhash_compareChars, nullptr, &ec3));
LocalUHashtablePointer currencyPluralIsoCodes(uhash_open(uhash_hashChars, uhash_compareChars, nullptr, &ec4));
for (int32_t localeLevel = 0; ; ++localeLevel) {
ec2 = U_ZERO_ERROR;
// TODO: ures_openDirect
UResourceBundle* rb = ures_open(U_ICUDATA_CURR, loc.data(), &ec2);
UResourceBundle* curr = ures_getByKey(rb, CURRENCIES, nullptr, &ec2);
int32_t n = ures_getSize(curr);
LocalUResourceBundlePointer rb(ures_open(U_ICUDATA_CURR, loc.data(), &ec2));
LocalUResourceBundlePointer curr(ures_getByKey(rb.getAlias(), CURRENCIES, nullptr, &ec2));
int32_t n = ures_getSize(curr.getAlias());
for (int32_t i=0; i<n; ++i) {
UResourceBundle* names = ures_getByIndex(curr, i, nullptr, &ec2);
LocalUResourceBundlePointer names(ures_getByIndex(curr.getAlias(), i, nullptr, &ec2));
int32_t len;
s = ures_getStringByIndex(names, UCURR_SYMBOL_NAME, &len, &ec2);
s = ures_getStringByIndex(names.getAlias(), UCURR_SYMBOL_NAME, &len, &ec2);
// TODO: uhash_put wont change key/value?
iso = (char*)ures_getKey(names);
if (localeLevel == 0) {
uhash_put(currencyIsoCodes, iso, iso, &ec3);
} else {
if (uhash_get(currencyIsoCodes, iso) != nullptr) {
ures_close(names);
continue;
} else {
uhash_put(currencyIsoCodes, iso, iso, &ec3);
}
iso = const_cast<char*>(ures_getKey(names.getAlias()));
if (localeLevel != 0 && uhash_get(currencyIsoCodes.getAlias(), iso) != nullptr) {
continue;
}
uhash_put(currencyIsoCodes.getAlias(), iso, iso, &ec3);
// Add currency symbol.
(*currencySymbols)[*total_currency_symbol_count].IsoCode = iso;
(*currencySymbols)[*total_currency_symbol_count].currencyName = (char16_t*)s;
(*currencySymbols)[*total_currency_symbol_count].flag = 0;
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = len;
(*currencySymbols)[(*total_currency_symbol_count)++] = {iso, const_cast<char16_t*>(s), len, 0};
// Add equivalent symbols
if (currencySymbolsEquiv != nullptr) {
UnicodeString str(true, s, len);
icu::EquivIterator iter(*currencySymbolsEquiv, str);
const UnicodeString *symbol;
while ((symbol = iter.next()) != nullptr) {
(*currencySymbols)[*total_currency_symbol_count].IsoCode = iso;
(*currencySymbols)[*total_currency_symbol_count].currencyName =
const_cast<char16_t*>(symbol->getBuffer());
(*currencySymbols)[*total_currency_symbol_count].flag = 0;
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = symbol->length();
(*currencySymbols)[(*total_currency_symbol_count)++]
= {iso, const_cast<char16_t*>(symbol->getBuffer()), symbol->length(), 0};
}
}
// Add currency long name.
s = ures_getStringByIndex(names, UCURR_LONG_NAME, &len, &ec2);
(*currencyNames)[*total_currency_name_count].IsoCode = iso;
s = ures_getStringByIndex(names.getAlias(), UCURR_LONG_NAME, &len, &ec2);
char16_t* upperName = toUpperCase(s, len, locale);
(*currencyNames)[*total_currency_name_count].currencyName = upperName;
(*currencyNames)[*total_currency_name_count].flag = NEED_TO_BE_DELETED;
(*currencyNames)[(*total_currency_name_count)++].currencyNameLen = len;
if (upperName == nullptr) {
ec = U_MEMORY_ALLOCATION_ERROR;
goto error;
}
(*currencyNames)[(*total_currency_name_count)++] = {iso, upperName, len, NEED_TO_BE_DELETED};
// put (iso, 3, and iso) in to array
// Add currency ISO code.
(*currencySymbols)[*total_currency_symbol_count].IsoCode = iso;
(*currencySymbols)[*total_currency_symbol_count].currencyName = (char16_t*)uprv_malloc(sizeof(char16_t)*3);
char16_t* isoCode = static_cast<char16_t*>(uprv_malloc(sizeof(char16_t) * 3));
if (isoCode == nullptr) {
ec = U_MEMORY_ALLOCATION_ERROR;
goto error;
}
// Must convert iso[] into Unicode
u_charsToUChars(iso, (*currencySymbols)[*total_currency_symbol_count].currencyName, 3);
(*currencySymbols)[*total_currency_symbol_count].flag = NEED_TO_BE_DELETED;
(*currencySymbols)[(*total_currency_symbol_count)++].currencyNameLen = 3;
ures_close(names);
u_charsToUChars(iso, isoCode, 3);
(*currencySymbols)[(*total_currency_symbol_count)++] = {iso, isoCode, 3, NEED_TO_BE_DELETED};
}
// currency plurals
UErrorCode ec5 = U_ZERO_ERROR;
UResourceBundle* curr_p = ures_getByKey(rb, CURRENCYPLURALS, nullptr, &ec5);
n = ures_getSize(curr_p);
LocalUResourceBundlePointer curr_p(ures_getByKey(rb.getAlias(), CURRENCYPLURALS, nullptr, &ec5));
n = ures_getSize(curr_p.getAlias());
for (int32_t i=0; i<n; ++i) {
UResourceBundle* names = ures_getByIndex(curr_p, i, nullptr, &ec5);
iso = (char*)ures_getKey(names);
LocalUResourceBundlePointer names(ures_getByIndex(curr_p.getAlias(), i, nullptr, &ec5));
iso = const_cast<char*>(ures_getKey(names.getAlias()));
// Using hash to remove duplicated ISO codes in fallback chain.
if (localeLevel == 0) {
uhash_put(currencyPluralIsoCodes, iso, iso, &ec4);
} else {
if (uhash_get(currencyPluralIsoCodes, iso) != nullptr) {
ures_close(names);
continue;
} else {
uhash_put(currencyPluralIsoCodes, iso, iso, &ec4);
}
if (localeLevel != 0 && uhash_get(currencyPluralIsoCodes.getAlias(), iso) != nullptr) {
continue;
}
int32_t num = ures_getSize(names);
uhash_put(currencyPluralIsoCodes.getAlias(), iso, iso, &ec4);
int32_t num = ures_getSize(names.getAlias());
int32_t len;
for (int32_t j = 0; j < num; ++j) {
// TODO: remove duplicates between singular name and
// currency long name?
s = ures_getStringByIndex(names, j, &len, &ec5);
(*currencyNames)[*total_currency_name_count].IsoCode = iso;
s = ures_getStringByIndex(names.getAlias(), j, &len, &ec5);
char16_t* upperName = toUpperCase(s, len, locale);
(*currencyNames)[*total_currency_name_count].currencyName = upperName;
(*currencyNames)[*total_currency_name_count].flag = NEED_TO_BE_DELETED;
(*currencyNames)[(*total_currency_name_count)++].currencyNameLen = len;
if (upperName == nullptr) {
ec = U_MEMORY_ALLOCATION_ERROR;
goto error;
}
(*currencyNames)[(*total_currency_name_count)++] = {iso, upperName, len, NEED_TO_BE_DELETED};
}
ures_close(names);
}
ures_close(curr_p);
ures_close(curr);
ures_close(rb);
if (!fallback(loc)) {
break;
}
}
uhash_close(currencyIsoCodes);
uhash_close(currencyPluralIsoCodes);
// quick sort the struct
qsort(*currencyNames, *total_currency_name_count,
sizeof(CurrencyNameStruct), currencyNameComparator);
@ -1147,11 +1129,17 @@ collectCurrencyNames(const char* locale,
// fail on hashtable errors
if (U_FAILURE(ec3)) {
ec = ec3;
return;
}
if (U_FAILURE(ec4)) {
} else if (U_FAILURE(ec4)) {
ec = ec4;
return;
}
error:
// clean up if we got error
if (U_FAILURE(ec)) {
deleteCurrencyNames(*currencyNames, *total_currency_name_count);
deleteCurrencyNames(*currencySymbols, *total_currency_symbol_count);
*currencyNames = *currencySymbols = nullptr;
*total_currency_name_count = *total_currency_symbol_count = 0;
}
}
@ -1485,7 +1473,13 @@ getCacheEntry(const char* locale, UErrorCode& ec) {
deleteCacheEntry(cacheEntry);
}
}
cacheEntry = (CurrencyNameCacheEntry*)uprv_malloc(sizeof(CurrencyNameCacheEntry));
cacheEntry = static_cast<CurrencyNameCacheEntry*>(uprv_malloc(sizeof(CurrencyNameCacheEntry)));
if (cacheEntry == nullptr) {
deleteCurrencyNames(currencyNames, total_currency_name_count);
deleteCurrencyNames(currencySymbols, total_currency_symbol_count);
ec = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
}
currCache[currentCacheEntryIndex] = cacheEntry;
uprv_strcpy(cacheEntry->locale, locale);
cacheEntry->currencyNames = currencyNames;
@ -2030,6 +2024,7 @@ static const struct CurrencyList {
{"ZRN", UCURR_COMMON|UCURR_DEPRECATED},
{"ZRZ", UCURR_COMMON|UCURR_DEPRECATED},
{"ZWD", UCURR_COMMON|UCURR_DEPRECATED},
{"ZWG", UCURR_COMMON|UCURR_NON_DEPRECATED},
{"ZWL", UCURR_COMMON|UCURR_DEPRECATED},
{"ZWR", UCURR_COMMON|UCURR_DEPRECATED},
{ nullptr, 0 } // Leave here to denote the end of the list.
@ -2095,18 +2090,18 @@ ucurr_createCurrencyList(UHashtable *isoCodes, UErrorCode* status){
// Look up the CurrencyMap element in the root bundle.
UResourceBundle *rb = ures_openDirect(U_ICUDATA_CURR, CURRENCY_DATA, &localStatus);
UResourceBundle *currencyMapArray = ures_getByKey(rb, CURRENCY_MAP, rb, &localStatus);
LocalUResourceBundlePointer currencyMapArray(ures_getByKey(rb, CURRENCY_MAP, rb, &localStatus));
if (U_SUCCESS(localStatus)) {
// process each entry in currency map
for (int32_t i=0; i<ures_getSize(currencyMapArray); i++) {
// process each entry in currency map
for (int32_t i=0; i<ures_getSize(currencyMapArray.getAlias()); i++) {
// get the currency resource
UResourceBundle *currencyArray = ures_getByIndex(currencyMapArray, i, nullptr, &localStatus);
// process each currency
LocalUResourceBundlePointer currencyArray(ures_getByIndex(currencyMapArray.getAlias(), i, nullptr, &localStatus));
// process each currency
if (U_SUCCESS(localStatus)) {
for (int32_t j=0; j<ures_getSize(currencyArray); j++) {
for (int32_t j=0; j<ures_getSize(currencyArray.getAlias()); j++) {
// get the currency resource
UResourceBundle *currencyRes = ures_getByIndex(currencyArray, j, nullptr, &localStatus);
LocalUResourceBundlePointer currencyRes(ures_getByIndex(currencyArray.getAlias(), j, nullptr, &localStatus));
IsoCodeEntry *entry = (IsoCodeEntry*)uprv_malloc(sizeof(IsoCodeEntry));
if (entry == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
@ -2115,41 +2110,36 @@ ucurr_createCurrencyList(UHashtable *isoCodes, UErrorCode* status){
// get the ISO code
int32_t isoLength = 0;
UResourceBundle *idRes = ures_getByKey(currencyRes, "id", nullptr, &localStatus);
if (idRes == nullptr) {
LocalUResourceBundlePointer idRes(ures_getByKey(currencyRes.getAlias(), "id", nullptr, &localStatus));
if (idRes.isNull()) {
continue;
}
const char16_t *isoCode = ures_getString(idRes, &isoLength, &localStatus);
const char16_t *isoCode = ures_getString(idRes.getAlias(), &isoLength, &localStatus);
// get from date
UDate fromDate = U_DATE_MIN;
UResourceBundle *fromRes = ures_getByKey(currencyRes, "from", nullptr, &localStatus);
LocalUResourceBundlePointer fromRes(ures_getByKey(currencyRes.getAlias(), "from", nullptr, &localStatus));
if (U_SUCCESS(localStatus)) {
int32_t fromLength = 0;
const int32_t *fromArray = ures_getIntVector(fromRes, &fromLength, &localStatus);
const int32_t *fromArray = ures_getIntVector(fromRes.getAlias(), &fromLength, &localStatus);
int64_t currDate64 = ((uint64_t)fromArray[0]) << 32;
currDate64 |= ((int64_t)fromArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
fromDate = (UDate)currDate64;
}
ures_close(fromRes);
// get to date
UDate toDate = U_DATE_MAX;
localStatus = U_ZERO_ERROR;
UResourceBundle *toRes = ures_getByKey(currencyRes, "to", nullptr, &localStatus);
LocalUResourceBundlePointer toRes(ures_getByKey(currencyRes.getAlias(), "to", nullptr, &localStatus));
if (U_SUCCESS(localStatus)) {
int32_t toLength = 0;
const int32_t *toArray = ures_getIntVector(toRes, &toLength, &localStatus);
const int32_t *toArray = ures_getIntVector(toRes.getAlias(), &toLength, &localStatus);
int64_t currDate64 = (uint64_t)toArray[0] << 32;
currDate64 |= ((int64_t)toArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
toDate = (UDate)currDate64;
}
ures_close(toRes);
ures_close(idRes);
ures_close(currencyRes);
entry->isoCode = isoCode;
entry->from = fromDate;
@ -2161,13 +2151,10 @@ ucurr_createCurrencyList(UHashtable *isoCodes, UErrorCode* status){
} else {
*status = localStatus;
}
ures_close(currencyArray);
}
} else {
*status = localStatus;
}
ures_close(currencyMapArray);
}
static const UEnumeration gEnumCurrencyList = {
@ -2186,19 +2173,18 @@ static void U_CALLCONV initIsoCodes(UErrorCode &status) {
U_ASSERT(gIsoCodes == nullptr);
ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cleanup);
UHashtable *isoCodes = uhash_open(uhash_hashUChars, uhash_compareUChars, nullptr, &status);
LocalUHashtablePointer isoCodes(uhash_open(uhash_hashUChars, uhash_compareUChars, nullptr, &status));
if (U_FAILURE(status)) {
return;
}
uhash_setValueDeleter(isoCodes, deleteIsoCodeEntry);
uhash_setValueDeleter(isoCodes.getAlias(), deleteIsoCodeEntry);
ucurr_createCurrencyList(isoCodes, &status);
ucurr_createCurrencyList(isoCodes.getAlias(), &status);
if (U_FAILURE(status)) {
uhash_close(isoCodes);
return;
}
gIsoCodes = isoCodes; // Note: gIsoCodes is const. Once set up here it is never altered,
// and read only access is safe without synchronization.
gIsoCodes = isoCodes.orphan(); // Note: gIsoCodes is const. Once set up here it is never altered,
// and read only access is safe without synchronization.
}
static void populateCurrSymbolsEquiv(icu::Hashtable *hash, UErrorCode &status) {
@ -2320,30 +2306,30 @@ ucurr_countCurrencies(const char* locale,
UResourceBundle *cm = ures_getByKey(rb, CURRENCY_MAP, rb, &localStatus);
// Using the id derived from the local, get the currency data
UResourceBundle *countryArray = ures_getByKey(rb, id.data(), cm, &localStatus);
LocalUResourceBundlePointer countryArray(ures_getByKey(rb, id.data(), cm, &localStatus));
// process each currency to see which one is valid for the given date
if (U_SUCCESS(localStatus))
{
for (int32_t i=0; i<ures_getSize(countryArray); i++)
for (int32_t i=0; i<ures_getSize(countryArray.getAlias()); i++)
{
// get the currency resource
UResourceBundle *currencyRes = ures_getByIndex(countryArray, i, nullptr, &localStatus);
LocalUResourceBundlePointer currencyRes(ures_getByIndex(countryArray.getAlias(), i, nullptr, &localStatus));
// get the from date
int32_t fromLength = 0;
UResourceBundle *fromRes = ures_getByKey(currencyRes, "from", nullptr, &localStatus);
const int32_t *fromArray = ures_getIntVector(fromRes, &fromLength, &localStatus);
LocalUResourceBundlePointer fromRes(ures_getByKey(currencyRes.getAlias(), "from", nullptr, &localStatus));
const int32_t *fromArray = ures_getIntVector(fromRes.getAlias(), &fromLength, &localStatus);
int64_t currDate64 = (int64_t)((uint64_t)(fromArray[0]) << 32);
currDate64 |= ((int64_t)fromArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
UDate fromDate = (UDate)currDate64;
if (ures_getSize(currencyRes)> 2)
if (ures_getSize(currencyRes.getAlias())> 2)
{
int32_t toLength = 0;
UResourceBundle *toRes = ures_getByKey(currencyRes, "to", nullptr, &localStatus);
const int32_t *toArray = ures_getIntVector(toRes, &toLength, &localStatus);
LocalUResourceBundlePointer toRes(ures_getByKey(currencyRes.getAlias(), "to", nullptr, &localStatus));
const int32_t *toArray = ures_getIntVector(toRes.getAlias(), &toLength, &localStatus);
currDate64 = (int64_t)toArray[0] << 32;
currDate64 |= ((int64_t)toArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
@ -2353,8 +2339,6 @@ ucurr_countCurrencies(const char* locale,
{
currCount++;
}
ures_close(toRes);
}
else
{
@ -2363,16 +2347,9 @@ ucurr_countCurrencies(const char* locale,
currCount++;
}
}
// close open resources
ures_close(currencyRes);
ures_close(fromRes);
} // end For loop
} // end if (U_SUCCESS(localStatus))
ures_close(countryArray);
// Check for errors
if (*ec == U_ZERO_ERROR || localStatus != U_ZERO_ERROR)
{
@ -2386,7 +2363,6 @@ ucurr_countCurrencies(const char* locale,
// no errors
return currCount;
}
}
// If we got here, either error code is invalid or
@ -2433,39 +2409,38 @@ ucurr_forLocaleAndDate(const char* locale,
UResourceBundle *cm = ures_getByKey(rb, CURRENCY_MAP, rb, &localStatus);
// Using the id derived from the local, get the currency data
UResourceBundle *countryArray = ures_getByKey(rb, id.data(), cm, &localStatus);
LocalUResourceBundlePointer countryArray(ures_getByKey(rb, id.data(), cm, &localStatus));
// process each currency to see which one is valid for the given date
bool matchFound = false;
if (U_SUCCESS(localStatus))
{
if ((index <= 0) || (index> ures_getSize(countryArray)))
if ((index <= 0) || (index> ures_getSize(countryArray.getAlias())))
{
// requested index is out of bounds
ures_close(countryArray);
return 0;
}
for (int32_t i=0; i<ures_getSize(countryArray); i++)
for (int32_t i=0; i<ures_getSize(countryArray.getAlias()); i++)
{
// get the currency resource
UResourceBundle *currencyRes = ures_getByIndex(countryArray, i, nullptr, &localStatus);
s = ures_getStringByKey(currencyRes, "id", &resLen, &localStatus);
LocalUResourceBundlePointer currencyRes(ures_getByIndex(countryArray.getAlias(), i, nullptr, &localStatus));
s = ures_getStringByKey(currencyRes.getAlias(), "id", &resLen, &localStatus);
// get the from date
int32_t fromLength = 0;
UResourceBundle *fromRes = ures_getByKey(currencyRes, "from", nullptr, &localStatus);
const int32_t *fromArray = ures_getIntVector(fromRes, &fromLength, &localStatus);
LocalUResourceBundlePointer fromRes(ures_getByKey(currencyRes.getAlias(), "from", nullptr, &localStatus));
const int32_t *fromArray = ures_getIntVector(fromRes.getAlias(), &fromLength, &localStatus);
int64_t currDate64 = (int64_t)((uint64_t)fromArray[0] << 32);
currDate64 |= ((int64_t)fromArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
UDate fromDate = (UDate)currDate64;
if (ures_getSize(currencyRes)> 2)
if (ures_getSize(currencyRes.getAlias()) > 2)
{
int32_t toLength = 0;
UResourceBundle *toRes = ures_getByKey(currencyRes, "to", nullptr, &localStatus);
const int32_t *toArray = ures_getIntVector(toRes, &toLength, &localStatus);
LocalUResourceBundlePointer toRes(ures_getByKey(currencyRes.getAlias(), "to", nullptr, &localStatus));
const int32_t *toArray = ures_getIntVector(toRes.getAlias(), &toLength, &localStatus);
currDate64 = (int64_t)toArray[0] << 32;
currDate64 |= ((int64_t)toArray[1] & (int64_t)INT64_C(0x00000000FFFFFFFF));
@ -2479,8 +2454,6 @@ ucurr_forLocaleAndDate(const char* locale,
matchFound = true;
}
}
ures_close(toRes);
}
else
{
@ -2493,11 +2466,6 @@ ucurr_forLocaleAndDate(const char* locale,
}
}
}
// close open resources
ures_close(currencyRes);
ures_close(fromRes);
// check for loop exit
if (matchFound)
{
@ -2507,8 +2475,6 @@ ucurr_forLocaleAndDate(const char* locale,
} // end For loop
}
ures_close(countryArray);
// Check for errors
if (*ec == U_ZERO_ERROR || localStatus != U_ZERO_ERROR)
{
@ -2578,20 +2544,16 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
memcpy(en, &defaultKeywordValues, sizeof(UEnumeration));
en->context = values;
UResourceBundle *bundle = ures_openDirect(U_ICUDATA_CURR, "supplementalData", status);
ures_getByKey(bundle, "CurrencyMap", bundle, status);
UResourceBundle bundlekey, regbndl, curbndl, to;
ures_initStackObject(&bundlekey);
ures_initStackObject(&regbndl);
ures_initStackObject(&curbndl);
ures_initStackObject(&to);
UResourceBundle* rb = ures_openDirect(U_ICUDATA_CURR, "supplementalData", status);
LocalUResourceBundlePointer bundle(ures_getByKey(rb, "CurrencyMap", rb, status));
StackUResourceBundle bundlekey, regbndl, curbndl, to;
while (U_SUCCESS(*status) && ures_hasNext(bundle)) {
ures_getNextResource(bundle, &bundlekey, status);
while (U_SUCCESS(*status) && ures_hasNext(bundle.getAlias())) {
ures_getNextResource(bundle.getAlias(), bundlekey.getAlias(), status);
if (U_FAILURE(*status)) {
break;
}
const char *region = ures_getKey(&bundlekey);
const char *region = ures_getKey(bundlekey.getAlias());
UBool isPrefRegion = prefRegion == region;
if (!isPrefRegion && commonlyUsed) {
// With commonlyUsed=true, we do not put
@ -2599,29 +2561,29 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
// result list.
continue;
}
ures_getByKey(bundle, region, &regbndl, status);
ures_getByKey(bundle.getAlias(), region, regbndl.getAlias(), status);
if (U_FAILURE(*status)) {
break;
}
while (U_SUCCESS(*status) && ures_hasNext(&regbndl)) {
ures_getNextResource(&regbndl, &curbndl, status);
if (ures_getType(&curbndl) != URES_TABLE) {
while (U_SUCCESS(*status) && ures_hasNext(regbndl.getAlias())) {
ures_getNextResource(regbndl.getAlias(), curbndl.getAlias(), status);
if (ures_getType(curbndl.getAlias()) != URES_TABLE) {
// Currently, an empty ARRAY is mixed in.
continue;
}
char *curID = (char *)uprv_malloc(sizeof(char) * ULOC_KEYWORDS_CAPACITY);
int32_t curIDLength = ULOC_KEYWORDS_CAPACITY;
if (curID == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
break;
}
int32_t curIDLength = ULOC_KEYWORDS_CAPACITY;
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
ures_getUTF8StringByKey(&curbndl, "id", curID, &curIDLength, true, status);
ures_getUTF8StringByKey(curbndl.getAlias(), "id", curID, &curIDLength, true, status);
/* optimize - use the utf-8 string */
#else
{
const char16_t* defString = ures_getStringByKey(&curbndl, "id", &curIDLength, status);
const char16_t* defString = ures_getStringByKey(curbndl.getAlias(), "id", &curIDLength, status);
if(U_SUCCESS(*status)) {
if(curIDLength+1 > ULOC_KEYWORDS_CAPACITY) {
*status = U_BUFFER_OVERFLOW_ERROR;
@ -2636,7 +2598,7 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
break;
}
UBool hasTo = false;
ures_getByKey(&curbndl, "to", &to, status);
ures_getByKey(curbndl.getAlias(), "to", to.getAlias(), status);
if (U_FAILURE(*status)) {
// Do nothing here...
*status = U_ZERO_ERROR;
@ -2669,6 +2631,10 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
while ((value = (char *)ulist_getNext(otherValues)) != nullptr) {
if (!ulist_containsString(values, value, (int32_t)uprv_strlen(value))) {
char *tmpValue = (char *)uprv_malloc(sizeof(char) * ULOC_KEYWORDS_CAPACITY);
if (tmpValue == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
break;
}
uprv_memcpy(tmpValue, value, uprv_strlen(value) + 1);
ulist_addItemEndList(values, tmpValue, true, status);
if (U_FAILURE(*status)) {
@ -2677,7 +2643,6 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
}
}
}
ulist_resetList((UList *)(en->context));
} else {
ulist_deleteList(values);
@ -2685,14 +2650,7 @@ U_CAPI UEnumeration *U_EXPORT2 ucurr_getKeywordValuesForLocale(const char *key,
values = nullptr;
en = nullptr;
}
ures_close(&to);
ures_close(&curbndl);
ures_close(&regbndl);
ures_close(&bundlekey);
ures_close(bundle);
ulist_deleteList(otherValues);
return en;
}
@ -2703,19 +2661,18 @@ ucurr_getNumericCode(const char16_t* currency) {
if (currency && u_strlen(currency) == ISO_CURRENCY_CODE_LENGTH) {
UErrorCode status = U_ZERO_ERROR;
UResourceBundle *bundle = ures_openDirect(nullptr, "currencyNumericCodes", &status);
ures_getByKey(bundle, "codeMap", bundle, &status);
UResourceBundle* bundle = ures_openDirect(nullptr, "currencyNumericCodes", &status);
LocalUResourceBundlePointer codeMap(ures_getByKey(bundle, "codeMap", bundle, &status));
if (U_SUCCESS(status)) {
char alphaCode[ISO_CURRENCY_CODE_LENGTH+1];
myUCharsToChars(alphaCode, currency);
T_CString_toUpperCase(alphaCode);
ures_getByKey(bundle, alphaCode, bundle, &status);
int tmpCode = ures_getInt(bundle, &status);
ures_getByKey(codeMap.getAlias(), alphaCode, codeMap.getAlias(), &status);
int tmpCode = ures_getInt(codeMap.getAlias(), &status);
if (U_SUCCESS(status)) {
code = tmpCode;
}
}
ures_close(bundle);
}
return code;
}

View file

@ -274,7 +274,7 @@ typedef struct DataCacheElement {
* here for each entry.
*/
static void U_CALLCONV DataCacheElement_deleter(void *pDCEl) {
DataCacheElement *p = (DataCacheElement *)pDCEl;
DataCacheElement* p = static_cast<DataCacheElement*>(pDCEl);
udata_close(p->item); /* unmaps storage */
uprv_free(p->name); /* delete the hash key string. */
uprv_free(pDCEl); /* delete 'this' */
@ -316,7 +316,7 @@ static UDataMemory *udata_findCachedData(const char *path, UErrorCode &err)
baseName = findBasename(path); /* Cache remembers only the base name, not the full path. */
umtx_lock(nullptr);
el = (DataCacheElement *)uhash_get(htable, baseName);
el = static_cast<DataCacheElement*>(uhash_get(htable, baseName));
umtx_unlock(nullptr);
if (el != nullptr) {
retVal = el->item;
@ -344,7 +344,7 @@ static UDataMemory *udata_cacheDataItem(const char *path, UDataMemory *item, UEr
/* Create a new DataCacheElement - the thingy we store in the hash table -
* and copy the supplied path and UDataMemoryItems into it.
*/
newElement = (DataCacheElement *)uprv_malloc(sizeof(DataCacheElement));
newElement = static_cast<DataCacheElement*>(uprv_malloc(sizeof(DataCacheElement)));
if (newElement == nullptr) {
*pErr = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
@ -357,8 +357,8 @@ static UDataMemory *udata_cacheDataItem(const char *path, UDataMemory *item, UEr
UDatamemory_assign(newElement->item, item);
baseName = findBasename(path);
nameLen = (int32_t)uprv_strlen(baseName);
newElement->name = (char *)uprv_malloc(nameLen+1);
nameLen = static_cast<int32_t>(uprv_strlen(baseName));
newElement->name = static_cast<char*>(uprv_malloc(nameLen + 1));
if (newElement->name == nullptr) {
*pErr = U_MEMORY_ALLOCATION_ERROR;
uprv_free(newElement->item);
@ -370,7 +370,7 @@ static UDataMemory *udata_cacheDataItem(const char *path, UDataMemory *item, UEr
/* Stick the new DataCacheElement into the hash table.
*/
umtx_lock(nullptr);
oldValue = (DataCacheElement *)uhash_get(htable, path);
oldValue = static_cast<DataCacheElement*>(uhash_get(htable, path));
if (oldValue != nullptr) {
subErr = U_USING_DEFAULT_WARNING;
}
@ -469,13 +469,13 @@ UDataPathIterator::UDataPathIterator(const char *inPath, const char *pkg,
/** Item **/
basename = findBasename(item);
basenameLen = (int32_t)uprv_strlen(basename);
basenameLen = static_cast<int32_t>(uprv_strlen(basename));
/** Item path **/
if(basename == item) {
nextPath = path;
} else {
itemPath.append(item, (int32_t)(basename-item), *pErrorCode);
itemPath.append(item, static_cast<int32_t>(basename - item), *pErrorCode);
nextPath = itemPath.data();
}
#ifdef UDATA_DEBUG
@ -531,16 +531,16 @@ const char *UDataPathIterator::next(UErrorCode *pErrorCode)
if(nextPath == itemPath.data()) { /* we were processing item's path. */
nextPath = path; /* start with regular path next tm. */
pathLen = (int32_t)uprv_strlen(currentPath);
pathLen = static_cast<int32_t>(uprv_strlen(currentPath));
} else {
/* fix up next for next time */
nextPath = uprv_strchr(currentPath, U_PATH_SEP_CHAR);
if(nextPath == nullptr) {
/* segment: entire path */
pathLen = (int32_t)uprv_strlen(currentPath);
pathLen = static_cast<int32_t>(uprv_strlen(currentPath));
} else {
/* segment: until next segment */
pathLen = (int32_t)(nextPath - currentPath);
pathLen = static_cast<int32_t>(nextPath - currentPath);
/* skip divider */
nextPath ++;
}
@ -777,17 +777,6 @@ openCommonData(const char *path, /* Path from OpenChoice? */
return nullptr;
}
#if defined(OS390_STUBDATA) && defined(OS390BATCH)
if (!UDataMemory_isLoaded(&tData)) {
char ourPathBuffer[1024];
/* One more chance, for extendCommonData() */
uprv_strncpy(ourPathBuffer, path, 1019);
ourPathBuffer[1019]=0;
uprv_strcat(ourPathBuffer, ".dat");
uprv_mapFile(&tData, ourPathBuffer, pErrorCode);
}
#endif
if (U_FAILURE(*pErrorCode)) {
return nullptr;
}
@ -1231,7 +1220,7 @@ doOpenChoice(const char *path, const char *type, const char *name,
if(isICUData) {
pkgName.append(U_ICUDATA_NAME, *pErrorCode);
} else {
pkgName.append(path, (int32_t)(treeChar-path), *pErrorCode);
pkgName.append(path, static_cast<int32_t>(treeChar - path), *pErrorCode);
if (first == nullptr) {
/*
This user data has no path, but there is a tree name.

View file

@ -47,12 +47,12 @@ uprv_swapArray16(const UDataSwapper *ds,
}
/* setup and swapping */
p=(const uint16_t *)inData;
q=(uint16_t *)outData;
p = static_cast<const uint16_t*>(inData);
q = static_cast<uint16_t*>(outData);
count=length/2;
while(count>0) {
x=*p++;
*q++=(uint16_t)((x<<8)|(x>>8));
*q++ = static_cast<uint16_t>((x << 8) | (x >> 8));
--count;
}
@ -95,12 +95,12 @@ uprv_swapArray32(const UDataSwapper *ds,
}
/* setup and swapping */
p=(const uint32_t *)inData;
q=(uint32_t *)outData;
p = static_cast<const uint32_t*>(inData);
q = static_cast<uint32_t*>(outData);
count=length/4;
while(count>0) {
x=*p++;
*q++=(uint32_t)((x<<24)|((x<<8)&0xff0000)|((x>>8)&0xff00)|(x>>24));
*q++ = (x << 24) | ((x << 8) & 0xff0000) | ((x >> 8) & 0xff00) | (x >> 24);
--count;
}
@ -142,8 +142,8 @@ uprv_swapArray64(const UDataSwapper *ds,
}
/* setup and swapping */
p=(const uint64_t *)inData;
q=(uint64_t *)outData;
p = static_cast<const uint64_t*>(inData);
q = static_cast<uint64_t*>(outData);
count=length/8;
while(count>0) {
uint64_t x=*p++;
@ -176,7 +176,7 @@ uprv_copyArray64(const UDataSwapper *ds,
static uint16_t U_CALLCONV
uprv_readSwapUInt16(uint16_t x) {
return (uint16_t)((x<<8)|(x>>8));
return static_cast<uint16_t>((x << 8) | (x >> 8));
}
static uint16_t U_CALLCONV
@ -186,7 +186,7 @@ uprv_readDirectUInt16(uint16_t x) {
static uint32_t U_CALLCONV
uprv_readSwapUInt32(uint32_t x) {
return (uint32_t)((x<<24)|((x<<8)&0xff0000)|((x>>8)&0xff00)|(x>>24));
return (x << 24) | ((x << 8) & 0xff0000) | ((x >> 8) & 0xff00) | (x >> 24);
}
static uint32_t U_CALLCONV
@ -196,7 +196,7 @@ uprv_readDirectUInt32(uint32_t x) {
static void U_CALLCONV
uprv_writeSwapUInt16(uint16_t *p, uint16_t x) {
*p=(uint16_t)((x<<8)|(x>>8));
*p = static_cast<uint16_t>((x << 8) | (x >> 8));
}
static void U_CALLCONV
@ -206,7 +206,7 @@ uprv_writeDirectUInt16(uint16_t *p, uint16_t x) {
static void U_CALLCONV
uprv_writeSwapUInt32(uint32_t *p, uint32_t x) {
*p=(uint32_t)((x<<24)|((x<<8)&0xff0000)|((x>>8)&0xff00)|(x>>24));
*p = (x << 24) | ((x << 8) & 0xff0000) | ((x >> 8) & 0xff00) | (x >> 24);
}
static void U_CALLCONV

Some files were not shown because too many files have changed in this diff Show more