Skip to content

Commit

Permalink
ICU-22793 Clang-Tidy: google-readability-casting
Browse files Browse the repository at this point in the history
  • Loading branch information
roubert committed Sep 19, 2024
1 parent 0bf8a95 commit 72928f5
Show file tree
Hide file tree
Showing 43 changed files with 136 additions and 136 deletions.
4 changes: 2 additions & 2 deletions icu4c/source/common/propsvec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions icu4c/source/common/punycode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/ubidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/ucnv_bld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/ucnvhz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/common/ucnvmbcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ ucnv_MBCSGetFilteredUnicodeSetForUnicode(const UConverterSharedData *sharedData,

bytes=mbcsTable->fromUnicodeBytes;

useFallback=(UBool)(which==UCNV_ROUNDTRIP_AND_FALLBACK_SET);
useFallback = which == UCNV_ROUNDTRIP_AND_FALLBACK_SET;

switch(mbcsTable->outputType) {
case MBCS_OUTPUT_3:
Expand Down Expand Up @@ -2823,7 +2823,7 @@ ucnv_MBCSToUnicodeWithOffsets(UConverterToUnicodeArgs *pArgs,
* - If any of the non-initial bytes could be the start of a character,
* we stop the illegal sequence before the first one of those.
*/
UBool isDBCSOnly=(UBool)(cnv->sharedData->mbcs.dbcsOnlyState!=0);
bool isDBCSOnly = cnv->sharedData->mbcs.dbcsOnlyState != 0;
int8_t i;
for(i=1;
i<byteIndex && !isSingleOrLead(stateTable, state, isDBCSOnly, bytes[i]);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/unicode/unistr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3033,7 +3033,7 @@ class U_COMMON_API UnicodeString : public Replaceable
* @draft ICU 76
*/
inline operator std::u16string_view() const {
return { getBuffer(), (std::u16string_view::size_type)length() };
return {getBuffer(), static_cast<std::u16string_view::size_type>(length())};
}

#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/unicode/uset.h
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ class USetStringIterator {
int32_t length;
const UChar *uchars = uset_getString(uset, index, &length);
// assert uchars != nullptr;
return { ConstChar16Ptr(uchars), (uint32_t)length };
return {ConstChar16Ptr(uchars), static_cast<uint32_t>(length)};
}
return {};
}
Expand Down
8 changes: 4 additions & 4 deletions icu4c/source/common/unistr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ U_COMMON_API UnicodeString U_EXPORT2
unistr_internalConcat(const UnicodeString &s1, std::u16string_view s2) {
int32_t sumLengths;
if (s2.length() > INT32_MAX ||
uprv_add32_overflow(s1.length(), (int32_t)s2.length(), &sumLengths)) {
uprv_add32_overflow(s1.length(), static_cast<int32_t>(s2.length()), &sumLengths)) {
UnicodeString bogus;
bogus.setToBogus();
return bogus;
Expand Down Expand Up @@ -301,7 +301,7 @@ UnicodeString::UnicodeString(const char *src, int32_t length, EInvariant) {
UnicodeString UnicodeString::readOnlyAliasFromU16StringView(std::u16string_view text) {
UnicodeString result;
if (text.length() <= INT32_MAX) {
result.setTo(false, text.data(), (int32_t)text.length());
result.setTo(false, text.data(), static_cast<int32_t>(text.length()));
} else {
result.setToBogus();
}
Expand Down Expand Up @@ -1622,7 +1622,7 @@ UnicodeString::doReplace(int32_t start, int32_t length, std::u16string_view src)
setToBogus();
return *this;
}
return doReplace(start, length, src.data(), 0, (int32_t)src.length());
return doReplace(start, length, src.data(), 0, static_cast<int32_t>(src.length()));
}

// Versions of doReplace() only for append() variants.
Expand Down Expand Up @@ -1722,7 +1722,7 @@ UnicodeString::doAppend(std::u16string_view src) {
setToBogus();
return *this;
}
return doAppend(src.data(), 0, (int32_t)src.length());
return doAppend(src.data(), 0, static_cast<int32_t>(src.length()));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/common/ushape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,13 +1709,13 @@ u_shapeArabic(const char16_t *source, int32_t sourceLength,
case U_SHAPE_DIGITS_ALEN2AN_INIT_LR:
_shapeToArabicDigitsWithContext(dest, destLength,
digitBase,
(UBool)((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_LOGICAL),
(options & U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_LOGICAL,
false);
break;
case U_SHAPE_DIGITS_ALEN2AN_INIT_AL:
_shapeToArabicDigitsWithContext(dest, destLength,
digitBase,
(UBool)((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_LOGICAL),
(options & U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_LOGICAL,
true);
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/utext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ repTextReplace(UText *ut,
}

// Do the actual replace operation using methods of the Replaceable class
UnicodeString replStr((UBool)(length<0), src, length); // read-only alias
UnicodeString replStr(length < 0, src, length); // read-only alias
rep->handleReplaceBetween(start32, limit32, replStr);
int32_t newLength = rep->length();
int32_t lengthDelta = newLength - oldLength;
Expand Down
6 changes: 3 additions & 3 deletions icu4c/source/common/utrie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ utrie_open(UNewTrie *fillIn,
}
}
uprv_memset(trie, 0, sizeof(UNewTrie));
trie->isAllocated= (UBool)(fillIn==nullptr);
trie->isAllocated = fillIn == nullptr;

if(aliasData!=nullptr) {
trie->data=aliasData;
Expand Down Expand Up @@ -250,7 +250,7 @@ utrie_get32(UNewTrie *trie, UChar32 c, UBool *pInBlockZero) {

block=trie->index[c>>UTRIE_SHIFT];
if(pInBlockZero!=nullptr) {
*pInBlockZero= (UBool)(block==0);
*pInBlockZero = block == 0;
}

return trie->data[ABS(block)+(c&UTRIE_MASK)];
Expand Down Expand Up @@ -884,7 +884,7 @@ utrie_unserialize(UTrie *trie, const void *data, int32_t length, UErrorCode *pEr
*pErrorCode=U_INVALID_FORMAT_ERROR;
return -1;
}
trie->isLatin1Linear= (UBool)((options&UTRIE_OPTIONS_LATIN1_IS_LINEAR)!=0);
trie->isLatin1Linear = (options & UTRIE_OPTIONS_LATIN1_IS_LINEAR) != 0;

/* get the length values */
trie->indexLength=header->indexLength;
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/utrie_swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ utrie_swap(const UDataSwapper *ds,
return 0;
}

dataIs32=(UBool)((trie.options&UTRIE_OPTIONS_DATA_IS_32_BIT)!=0);
dataIs32 = (trie.options & UTRIE_OPTIONS_DATA_IS_32_BIT) != 0;
size=sizeof(UTrieHeader)+trie.indexLength*2+trie.dataLength*(dataIs32?4:2);

if(length>=0) {
Expand Down
8 changes: 4 additions & 4 deletions icu4c/source/common/uts46.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ uidna_labelToASCII(const UIDNA *idna,
if(!checkArgs(label, length, dest, capacity, pInfo, pErrorCode)) {
return 0;
}
UnicodeString src((UBool)(length<0), label, length);
UnicodeString src(length < 0, label, length);
UnicodeString destString(dest, 0, capacity);
IDNAInfo info;
reinterpret_cast<const IDNA *>(idna)->labelToASCII(src, destString, info, *pErrorCode);
Expand All @@ -1382,7 +1382,7 @@ uidna_labelToUnicode(const UIDNA *idna,
if(!checkArgs(label, length, dest, capacity, pInfo, pErrorCode)) {
return 0;
}
UnicodeString src((UBool)(length<0), label, length);
UnicodeString src(length < 0, label, length);
UnicodeString destString(dest, 0, capacity);
IDNAInfo info;
reinterpret_cast<const IDNA *>(idna)->labelToUnicode(src, destString, info, *pErrorCode);
Expand All @@ -1398,7 +1398,7 @@ uidna_nameToASCII(const UIDNA *idna,
if(!checkArgs(name, length, dest, capacity, pInfo, pErrorCode)) {
return 0;
}
UnicodeString src((UBool)(length<0), name, length);
UnicodeString src(length < 0, name, length);
UnicodeString destString(dest, 0, capacity);
IDNAInfo info;
reinterpret_cast<const IDNA *>(idna)->nameToASCII(src, destString, info, *pErrorCode);
Expand All @@ -1414,7 +1414,7 @@ uidna_nameToUnicode(const UIDNA *idna,
if(!checkArgs(name, length, dest, capacity, pInfo, pErrorCode)) {
return 0;
}
UnicodeString src((UBool)(length<0), name, length);
UnicodeString src(length < 0, name, length);
UnicodeString destString(dest, 0, capacity);
IDNAInfo info;
reinterpret_cast<const IDNA *>(idna)->nameToUnicode(src, destString, info, *pErrorCode);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/collationbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ ucol_openRules(const char16_t *rules, int32_t rulesLength,
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
}
UnicodeString r((UBool)(rulesLength < 0), rules, rulesLength);
UnicodeString r(rulesLength < 0, rules, rulesLength);
coll->internalBuildTailoring(r, strength, normalizationMode, parseError, nullptr, *pErrorCode);
if(U_FAILURE(*pErrorCode)) {
delete coll;
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/messageformat2_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void Parser::parseToken(const std::u16string_view& token, UErrorCode& errorCode)
U_ASSERT(inBounds(source, index));

int32_t tokenPos = 0;
while (tokenPos < (int32_t) token.length()) {
while (tokenPos < static_cast<int32_t>(token.length())) {
if (source[index] != token[tokenPos]) {
ERROR(parseError, errorCode, index);
return;
Expand Down Expand Up @@ -1674,7 +1674,7 @@ void Parser::parseUnsupportedStatement(UErrorCode& status) {
// Terrible hack to get around the ambiguity between unsupported keywords
// and supported keywords
bool Parser::nextIs(const std::u16string_view &keyword) const {
for(int32_t i = 0; i < (int32_t) keyword.length(); i++) {
for (int32_t i = 0; i < static_cast<int32_t>(keyword.length()); i++) {
if (!inBounds(source, index + i) || source[index + i] != keyword[i]) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/rbt_pars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ utrans_stripRules(const char16_t *source, int32_t sourceLen, char16_t *target, U
U16_NEXT_UNSAFE(source, index, c);
source+=index;
if(c == QUOTE) {
quoted = (UBool)!quoted;
quoted = !quoted;
}
else if (!quoted) {
if (c == RULE_COMMENT_CHAR) {
Expand Down Expand Up @@ -1739,7 +1739,7 @@ utrans_stripRules(const char16_t *source, int32_t sourceLen, char16_t *target, U
}
else if (c2 == QUOTE) {
/* \' seen. Make sure we don't do anything when we see it again. */
quoted = (UBool)!quoted;
quoted = !quoted;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/reldatefmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,8 +1448,8 @@ ureldatefmt_combineDateAndTime( const URelativeDateTimeFormatter* reldatefmt,
*status = U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
UnicodeString relDateStr((UBool)(relativeDateStringLen == -1), relativeDateString, relativeDateStringLen);
UnicodeString timeStr((UBool)(timeStringLen == -1), timeString, timeStringLen);
UnicodeString relDateStr(relativeDateStringLen == -1, relativeDateString, relativeDateStringLen);
UnicodeString timeStr(timeStringLen == -1, timeString, timeStringLen);
UnicodeString res(result, 0, resultCapacity);
((RelativeDateTimeFormatter*)reldatefmt)->combineDateAndTime(relDateStr, timeStr, res, *status);
if (U_FAILURE(*status)) {
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/ucoleitr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ ucol_openElements(const UCollator *coll,
return nullptr;
}

UnicodeString s((UBool)(textLength < 0), text, textLength);
UnicodeString s(textLength < 0, text, textLength);
CollationElementIterator *cei = rbc->createCollationElementIterator(s);
if (cei == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
Expand Down Expand Up @@ -488,7 +488,7 @@ ucol_setText( UCollationElements *elems,
*status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
UnicodeString s((UBool)(textLength < 0), text, textLength);
UnicodeString s(textLength < 0, text, textLength);
return CollationElementIterator::fromUCollationElements(elems)->setText(s, *status);
}

Expand Down
14 changes: 7 additions & 7 deletions icu4c/source/i18n/udat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ udat_open(UDateFormatStyle timeStyle,
}
}
else {
UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
UnicodeString pat(patternLength == -1, pattern, patternLength);

if (locale == nullptr) {
fmt = new SimpleDateFormat(pat, *status);
Expand All @@ -182,7 +182,7 @@ udat_open(UDateFormatStyle timeStyle,
}

if (tzID != nullptr) {
TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength));
TimeZone* zone = TimeZone::createTimeZone(UnicodeString(tzIDLength == -1, tzID, tzIDLength));
if (zone == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
delete fmt;
Expand Down Expand Up @@ -359,7 +359,7 @@ udat_parse( const UDateFormat* format,
{
if(U_FAILURE(*status)) return (UDate)0;

const UnicodeString src((UBool)(textLength == -1), text, textLength);
const UnicodeString src(textLength == -1, text, textLength);
ParsePosition pp;
int32_t stackParsePos = 0;
UDate res;
Expand Down Expand Up @@ -392,7 +392,7 @@ udat_parseCalendar(const UDateFormat* format,
{
if(U_FAILURE(*status)) return;

const UnicodeString src((UBool)(textLength == -1), text, textLength);
const UnicodeString src(textLength == -1, text, textLength);
ParsePosition pp;
int32_t stackParsePos = 0;

Expand Down Expand Up @@ -581,7 +581,7 @@ udat_applyPattern( UDateFormat *format,
const char16_t *pattern,
int32_t patternLength)
{
const UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength);
const UnicodeString pat(patternLength == -1, pattern, patternLength);
UErrorCode status = U_ZERO_ERROR;

verifyIsSimpleDateFormat(format, &status);
Expand Down Expand Up @@ -1355,8 +1355,8 @@ udat_applyPatternRelative(UDateFormat *format,
{
verifyIsRelativeDateFormat(format, status);
if(U_FAILURE(*status)) return;
const UnicodeString datePat((UBool)(datePatternLength == -1), datePattern, datePatternLength);
const UnicodeString timePat((UBool)(timePatternLength == -1), timePattern, timePatternLength);
const UnicodeString datePat(datePatternLength == -1, datePattern, datePatternLength);
const UnicodeString timePat(timePatternLength == -1, timePattern, timePatternLength);
((RelativeDateFormat*)format)->applyPatterns(datePat, timePat, *status);
}

Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/udateintervalformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ udtitvfmt_open(const char* locale,
*status = U_ILLEGAL_ARGUMENT_ERROR;
return nullptr;
}
UnicodeString skel((UBool)(skeletonLength == -1), skeleton, skeletonLength);
UnicodeString skel(skeletonLength == -1, skeleton, skeletonLength);
LocalPointer<DateIntervalFormat> formatter(
DateIntervalFormat::createInstance(skel, Locale(locale), *status));
if (U_FAILURE(*status)) {
return nullptr;
}
if (tzID != nullptr) {
TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength));
TimeZone* zone = TimeZone::createTimeZone(UnicodeString(tzIDLength == -1, tzID, tzIDLength));
if(zone == nullptr) {
*status = U_MEMORY_ALLOCATION_ERROR;
return nullptr;
Expand Down
Loading

0 comments on commit 72928f5

Please sign in to comment.