// Allow implicit conversion from char16_t* to UnicodeString for this file: // Helpful in toString methods and elsewhere. #define UNISTR_FROM_STRING_EXPLICIT
// This function needs to be declared in this namespace so it can be friended. // NOTE: In Java, this logic is handled in the resolve() function. void icu::number::impl::touchRangeLocales(RangeMacroProps& macros) {
macros.formatter1.fMacros.locale = macros.locale;
macros.formatter2.fMacros.locale = macros.locale;
}
// Declare all classes that implement NumberRangeFormatterSettings // See https://stackoverflow.com/a/495056/1407170 template class icu::number::NumberRangeFormatterSettings<icu::number::UnlocalizedNumberRangeFormatter>; template class icu::number::NumberRangeFormatterSettings<icu::number::LocalizedNumberRangeFormatter>;
template<typename T> using NFS = NumberRangeFormatterSettings<T>; using LNF = LocalizedNumberRangeFormatter; using UNF = UnlocalizedNumberRangeFormatter;
LocalPointer<UFormattedNumberRangeData> results(new UFormattedNumberRangeData(), status); if (U_FAILURE(status)) { return FormattedNumberRange(status);
}
first.populateDecimalQuantity(results->quantity1, status); if (U_FAILURE(status)) { return FormattedNumberRange(status);
}
second.populateDecimalQuantity(results->quantity2, status); if (U_FAILURE(status)) { return FormattedNumberRange(status);
}
formatImpl(*results, first == second, status);
// Do not save the results object if we encountered a failure. if (U_SUCCESS(status)) { return FormattedNumberRange(results.orphan());
} else { return FormattedNumberRange(status);
}
}
void LocalizedNumberRangeFormatter::formatImpl(
UFormattedNumberRangeData& results, bool equalBeforeRounding, UErrorCode& status) const { constauto* impl = getFormatter(status); if (U_FAILURE(status)) { return;
} if (impl == nullptr) {
status = U_INTERNAL_PROGRAM_ERROR; return;
}
impl->format(results, equalBeforeRounding, status); if (U_FAILURE(status)) { return;
}
results.getStringRef().writeTerminator(status);
}
const impl::NumberRangeFormatterImpl*
LocalizedNumberRangeFormatter::getFormatter(UErrorCode& status) const { // TODO: Move this into umutex.h? (similar logic also in decimfmt.cpp) // See ICU-20146
if (U_FAILURE(status)) { return nullptr;
}
// First try to get the pre-computed formatter #ifndef __wasi__ auto* ptr = fAtomicFormatter.load(); #else auto* ptr = fAtomicFormatter; #endif if (ptr != nullptr) { return ptr;
}
// Try computing the formatter on our own
LocalPointer<NumberRangeFormatterImpl> temp(new NumberRangeFormatterImpl(fMacros, status), status); if (U_FAILURE(status)) { return nullptr;
}
// Note: ptr starts as nullptr; during compare_exchange, // it is set to what is actually stored in the atomic // if another thread beat us to computing the formatter object. auto* nonConstThis = const_cast<LocalizedNumberRangeFormatter*>(this); #ifndef __wasi__ if (!nonConstThis->fAtomicFormatter.compare_exchange_strong(ptr, temp.getAlias())) { // Another thread beat us to computing the formatter return ptr;
} else { // Our copy of the formatter got stored in the atomic return temp.orphan();
} #else
nonConstThis->fAtomicFormatter = temp.getAlias(); return temp.orphan(); #endif
}
#endif/* #if !UCONFIG_NO_FORMATTING */
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.