Skip to content

Commit

Permalink
ICU-22621 Clang-Tidy: modernize-return-braced-init-list
Browse files Browse the repository at this point in the history
  • Loading branch information
roubert committed Mar 21, 2024
1 parent 80a01a4 commit 9172150
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion icu4c/source/common/brkiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ BreakIterator::makeInstance(const Locale& loc, int32_t kind, UErrorCode& status)
Locale
BreakIterator::getLocale(ULocDataLocaleType type, UErrorCode& status) const {
if (type == ULOC_REQUESTED_LOCALE) {
return Locale(requestLocale);
return {requestLocale};
}
U_LOCALE_BASED(locBased, *this);
return locBased.getLocale(type, status);
Expand Down
8 changes: 4 additions & 4 deletions icu4c/source/common/uresdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ const uint8_t *ResourceDataValue::getBinary(int32_t &length, UErrorCode &errorCo

ResourceArray ResourceDataValue::getArray(UErrorCode &errorCode) const {
if(U_FAILURE(errorCode)) {
return ResourceArray();
return {};
}
const uint16_t *items16 = nullptr;
const Resource *items32 = nullptr;
Expand All @@ -590,14 +590,14 @@ ResourceArray ResourceDataValue::getArray(UErrorCode &errorCode) const {
break;
default:
errorCode = U_RESOURCE_TYPE_MISMATCH;
return ResourceArray();
return {};
}
return ResourceArray(items16, items32, length, fTraceInfo);
}

ResourceTable ResourceDataValue::getTable(UErrorCode &errorCode) const {
if(U_FAILURE(errorCode)) {
return ResourceTable();
return {};
}
const uint16_t *keys16 = nullptr;
const int32_t *keys32 = nullptr;
Expand Down Expand Up @@ -627,7 +627,7 @@ ResourceTable ResourceDataValue::getTable(UErrorCode &errorCode) const {
break;
default:
errorCode = U_RESOURCE_TYPE_MISMATCH;
return ResourceTable();
return {};
}
return ResourceTable(keys16, keys32, items16, items32, length, fTraceInfo);
}
Expand Down
5 changes: 3 additions & 2 deletions icu4c/source/i18n/astro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ UnicodeString CalendarAstronomer::Ecliptic::toString() const
snprintf(tmp, sizeof(tmp), "[%.5f,%.5f]", longitude*RAD_DEG, latitude*RAD_DEG);
return UnicodeString(tmp, "");
#else
return UnicodeString();
return {};
#endif
}

Expand All @@ -820,10 +820,11 @@ UnicodeString CalendarAstronomer::Equatorial::toString() const
(ascension*RAD_DEG), (declination*RAD_DEG));
return UnicodeString(tmp, "");
#else
return UnicodeString();
return {};
#endif
}


// =============== Calendar Cache ================

void CalendarCache::createCache(CalendarCache** cache, UErrorCode& status) {
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/datefmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,13 @@ DateFormat::getBestPattern(
UErrorCode &status) {
UnifiedCache *cache = UnifiedCache::getInstance(status);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
DateFmtBestPatternKey key(locale, skeleton, status);
const DateFmtBestPattern *patternPtr = nullptr;
cache->get(key, patternPtr, status);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
UnicodeString result(patternPtr->fPattern);
patternPtr->removeRef();
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/displayoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

U_NAMESPACE_BEGIN

DisplayOptions::Builder DisplayOptions::builder() { return DisplayOptions::Builder(); }
DisplayOptions::Builder DisplayOptions::builder() { return {}; }

DisplayOptions::Builder DisplayOptions::copyToBuilder() const { return Builder(*this); }

Expand Down
22 changes: 11 additions & 11 deletions icu4c/source/i18n/dtptngen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,11 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UErro
UnicodeString
DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDateTimePatternMatchOptions options, UErrorCode& status) {
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
if (U_FAILURE(internalErrorCode)) {
status = internalErrorCode;
return UnicodeString();
return {};
}
const UnicodeString *bestPattern = nullptr;
UnicodeString dtFormat;
Expand All @@ -1166,15 +1166,15 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
// Replace hour metacharacters 'j', 'C' and 'J', set flags as necessary
UnicodeString patternFormMapped = mapSkeletonMetacharacters(patternForm, &flags, status);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}

resultPattern.remove();
dtMatcher->set(patternFormMapped, fp);
const PtnSkeleton* specifiedSkeleton = nullptr;
bestPattern=getBestRaw(*dtMatcher, -1, distanceInfo, status, &specifiedSkeleton);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}

if ( distanceInfo->missingFieldMask==0 && distanceInfo->extraFieldMask==0 ) {
Expand All @@ -1186,7 +1186,7 @@ DateTimePatternGenerator::getBestPattern(const UnicodeString& patternForm, UDate
UnicodeString datePattern=getBestAppending(neededFields & dateMask, flags, status, options);
UnicodeString timePattern=getBestAppending(neededFields & timeMask, flags, status, options);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
if (datePattern.length()==0) {
if (timePattern.length()==0) {
Expand Down Expand Up @@ -1262,7 +1262,7 @@ DateTimePatternGenerator::mapSkeletonMetacharacters(const UnicodeString& pattern
bestAllowed = (AllowedHourFormat)fAllowedHourFormats[0];
} else {
status = U_INVALID_FORMAT_ERROR;
return UnicodeString();
return {};
}
if (bestAllowed == ALLOWED_HOUR_FORMAT_H || bestAllowed == ALLOWED_HOUR_FORMAT_HB || bestAllowed == ALLOWED_HOUR_FORMAT_Hb) {
hourChar = CAP_H;
Expand Down Expand Up @@ -1313,11 +1313,11 @@ DateTimePatternGenerator::replaceFieldTypes(const UnicodeString& pattern,
UDateTimePatternMatchOptions options,
UErrorCode& status) {
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
if (U_FAILURE(internalErrorCode)) {
status = internalErrorCode;
return UnicodeString();
return {};
}
dtMatcher->set(skeleton, fp);
UnicodeString result = adjustFieldTypes(pattern, nullptr, kDTPGNoFlags, options);
Expand Down Expand Up @@ -1770,7 +1770,7 @@ DateTimePatternGenerator::adjustFieldTypes(const UnicodeString& pattern,
UnicodeString
DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags, UErrorCode &status, UDateTimePatternMatchOptions options) {
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
UnicodeString resultPattern, tempPattern;
const UnicodeString* tempPatternPtr;
Expand All @@ -1780,7 +1780,7 @@ DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags,
const PtnSkeleton* specifiedSkeleton=nullptr;
tempPatternPtr = getBestRaw(*dtMatcher, missingFields, distanceInfo, status, &specifiedSkeleton);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
tempPattern = *tempPatternPtr;
resultPattern = adjustFieldTypes(tempPattern, specifiedSkeleton, flags, options);
Expand All @@ -1800,7 +1800,7 @@ DateTimePatternGenerator::getBestAppending(int32_t missingFields, int32_t flags,
int32_t startingMask = distanceInfo->missingFieldMask;
tempPatternPtr = getBestRaw(*dtMatcher, distanceInfo->missingFieldMask, distanceInfo, status, &specifiedSkeleton);
if (U_FAILURE(status)) {
return UnicodeString();
return {};
}
tempPattern = *tempPatternPtr;
tempPattern = adjustFieldTypes(tempPattern, specifiedSkeleton, flags, options);
Expand Down
8 changes: 4 additions & 4 deletions icu4c/source/i18n/measunit_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,13 @@ class Parser {
*/
static Parser from(StringPiece source, UErrorCode& status) {
if (U_FAILURE(status)) {
return Parser();
return {};
}
umtx_initOnce(gUnitExtrasInitOnce, &initUnitExtras, status);
if (U_FAILURE(status)) {
return Parser();
return {};
}
return Parser(source);
return {source};
}

MeasureUnitImpl parse(UErrorCode& status) {
Expand Down Expand Up @@ -663,7 +663,7 @@ class Parser {
} else {
fIndex = previ;
}
return Token(match);
return {match};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/number_currencysymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ icu::number::impl::resolveCurrency(const DecimalFormatProperties& properties, co
return CurrencyUnit(buf, status);
} else {
// Default currency (XXX)
return CurrencyUnit();
return {};
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/number_modifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ CurrencySpacingEnabledModifier::getUnicodeSet(const DecimalFormatSymbols &symbol
// Ensure the static defaults are initialized:
umtx_initOnce(gDefaultCurrencySpacingInitOnce, &initDefaultCurrencySpacing, status);
if (U_FAILURE(status)) {
return UnicodeSet();
return {};
}

const UnicodeString& pattern = symbols.getPatternForCurrencySpacing(
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/number_patternmodifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ UnicodeString MutablePatternModifier::getCurrencySymbolForUnitWidth(UErrorCode&
case UNumberUnitWidth::UNUM_UNIT_WIDTH_VARIANT:
return fCurrencySymbols.getVariantCurrencySymbol(status);
case UNumberUnitWidth::UNUM_UNIT_WIDTH_HIDDEN:
return UnicodeString();
return {};
default:
return fCurrencySymbols.getCurrencySymbol(status);
}
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/number_patternstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int32_t ParsedPatternInfo::getLengthFromEndpoints(const Endpoints& endpoints) {
UnicodeString ParsedPatternInfo::getString(int32_t flags) const {
const Endpoints& endpoints = getEndpoints(flags);
if (endpoints.start == endpoints.end) {
return UnicodeString();
return {};
}
// Create a new UnicodeString
return UnicodeString(pattern, endpoints.start, endpoints.end - endpoints.start);
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/number_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ using namespace icu::number::impl;
SimpleNumber
SimpleNumber::forInt64(int64_t value, UErrorCode& status) {
if (U_FAILURE(status)) {
return SimpleNumber();
return {};
}
auto* results = new UFormattedNumberData();
if (results == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return SimpleNumber();
return {};
}
results->quantity.setToLong(value);
return SimpleNumber(results, status);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/number_skeletons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Notation stem_to_object::notation(skeleton::StemEnum stem) {
MeasureUnit stem_to_object::unit(skeleton::StemEnum stem) {
switch (stem) {
case STEM_BASE_UNIT:
return MeasureUnit();
return {};
case STEM_PERCENT:
return MeasureUnit::getPercent();
case STEM_PERMILLE:
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/i18n/rbnf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ RuleBasedNumberFormat::getNumberOfRuleSetDisplayNameLocales() const {
Locale
RuleBasedNumberFormat::getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const {
if (U_FAILURE(status)) {
return Locale("");
return {""};
}
if (localizations && index >= 0 && index < localizations->getNumberOfDisplayLocales()) {
UnicodeString name(true, localizations->getLocaleName(index), -1);
Expand All @@ -1048,7 +1048,7 @@ RuleBasedNumberFormat::getRuleSetDisplayNameLocale(int32_t index, UErrorCode& st
bp = (char *)uprv_malloc(cap);
if (bp == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR;
return Locale("");
return {""};
}
}
name.extract(0, name.length(), bp, cap, UnicodeString::kInvariant);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/repattrn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ UnicodeString RegexPattern::pattern() const {
if (fPatternString != nullptr) {
return *fPatternString;
} else if (fPattern == nullptr) {
return UnicodeString();
return {};
} else {
UErrorCode status = U_ZERO_ERROR;
int64_t nativeLen = utext_nativeLength(fPattern);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/unicode/nounit.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace NoUnit {
* @stable ICU 68
*/
static inline MeasureUnit U_EXPORT2 base() {
return MeasureUnit();
return {};
}

/**
Expand Down
10 changes: 5 additions & 5 deletions icu4c/source/i18n/units_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ Factor extractFactorConversions(StringPiece stringFactor, UErrorCode &status) {
// Load factor for a single source
Factor loadSingleFactor(StringPiece source, const ConversionRates &ratesInfo, UErrorCode &status) {
const auto* const conversionUnit = ratesInfo.extractConversionInfo(source, status);
if (U_FAILURE(status)) return Factor();
if (U_FAILURE(status)) return {};
if (conversionUnit == nullptr) {
status = U_INTERNAL_PROGRAM_ERROR;
return Factor();
return {};
}

Factor result = extractFactorConversions(conversionUnit->factor.toStringPiece(), status);
Expand Down Expand Up @@ -277,17 +277,17 @@ UBool checkSimpleUnit(const MeasureUnitImpl &unit, UErrorCode &status) {
CharString getSpecialMappingName(const MeasureUnitImpl &simpleUnit, const ConversionRates &ratesInfo,
UErrorCode &status) {
if (!checkSimpleUnit(simpleUnit, status)) {
return CharString();
return {};
}
SingleUnitImpl singleUnit = *simpleUnit.singleUnits[0];
const auto* const conversionUnit =
ratesInfo.extractConversionInfo(singleUnit.getSimpleUnitID(), status);
if (U_FAILURE(status)) {
return CharString();
return {};
}
if (conversionUnit == nullptr) {
status = U_INTERNAL_PROGRAM_ERROR;
return CharString();
return {};
}
CharString result;
result.copyFrom(conversionUnit->specialMappingName, status);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/i18n/upluralrules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ UnicodeString select(const PluralRules &rules, const Formattable& obj, const Num
}
}
}
return UnicodeString();
return {};
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/test/intltest/fldset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ UnicodeString FieldsSet::diffFrom(const FieldsSet& other, UErrorCode& status) co
UnicodeString str;
if(!isSameType(other)) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return UnicodeString("U_ILLEGAL_ARGUMENT_ERROR: FieldsSet of a different type!");
return {"U_ILLEGAL_ARGUMENT_ERROR: FieldsSet of a different type!"};
}
for (int i=0; i<fieldCount(); i++) {
if (isSet((UCalendarDateFields)i)) {
Expand Down
3 changes: 1 addition & 2 deletions icu4c/source/test/intltest/intltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ static UBool noKnownIssues = false; // if true, don't emit known issues

// [LIU] Just to get things working
UnicodeString
UCharToUnicodeString(char16_t c)
{ return UnicodeString(c); }
UCharToUnicodeString(char16_t c) { return {c}; }

// [rtg] Just to get things working
UnicodeString
Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/test/intltest/loctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4912,9 +4912,9 @@ static Locale _canonicalize(int32_t selector, /* 0==createFromName, 1==createCan
case 1:
return Locale::createCanonical(localeID);
case 2:
return Locale(localeID);
return {localeID};
default:
return Locale("");
return {""};
}
}

Expand Down
4 changes: 2 additions & 2 deletions icu4c/source/test/intltest/testidna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ UnicodeString TestIDNA::testCompareReferenceImpl(UnicodeString& src,
+ " Got: " + UnicodeString(u_errorName(gotStatus))
+ " for Source: "+ prettify(srcUChars)
+ " Options: " + options);
return UnicodeString("");
return {""};
}

// now we know that both implementations yielded same error
Expand All @@ -1430,7 +1430,7 @@ UnicodeString TestIDNA::testCompareReferenceImpl(UnicodeString& src,
+ " with "+ UnicodeString(uIDNAName)
+" for input: " + prettify(srcUChars));
}
return UnicodeString("");
return {""};
}

void TestIDNA::testCompareReferenceImpl(const char16_t* src, int32_t srcLen){
Expand Down

0 comments on commit 9172150

Please sign in to comment.