// NOTE: The object lifecycle of ScientificModifier and ScientificHandler differ greatly in Java and C++. // // During formatting, we need to provide an object with state (the exponent) as the inner modifier. // // In Java, where the priority is put on reducing object creations, the unsafe code path re-uses the // ScientificHandler as a ScientificModifier, and the safe code path pre-computes 25 ScientificModifier // instances. This scheme reduces the number of object creations by 1 in both safe and unsafe. // // In C++, MicroProps provides a pre-allocated ScientificModifier, and ScientificHandler simply populates // the state (the exponent) into that ScientificModifier. There is no difference between safe and unsafe.
int32_t ScientificModifier::getCodePointCount() const { // NOTE: This method is only called one place, NumberRangeFormatterImpl. // The call site only cares about != 0 and != 1. // Return a very large value so that if this method is used elsewhere, we should notice. return 999;
}
bool ScientificModifier::containsField(Field field) const {
(void)field; // This method is not used for inner modifiers.
UPRV_UNREACHABLE_EXIT;
}
void ScientificModifier::getParameters(Parameters& output) const { // Not part of any plural sets
output.obj = nullptr;
}
bool ScientificModifier::strictEquals(const Modifier& other) const { constauto* _other = dynamic_cast<const ScientificModifier*>(&other); if (_other == nullptr) { returnfalse;
} // TODO: Check for locale symbols and settings as well? Could be less efficient. return fExponent == _other->fExponent;
}
// Note: Visual Studio does not compile this function without full name space. Why?
icu::number::impl::ScientificHandler::ScientificHandler(const Notation *notation, const DecimalFormatSymbols *symbols, const MicroPropsGenerator *parent) :
fSettings(notation->fUnion.scientific), fSymbols(symbols), fParent(parent) {}
// Do not apply scientific notation to special doubles if (quantity.isInfinite() || quantity.isNaN()) {
micros.modInner = µs.helpers.emptyStrongModifier; return;
}
// Treat zero as if it had magnitude 0
int32_t exponent; if (quantity.isZeroish()) { if (fSettings.fRequireMinInt && micros.rounder.isSignificantDigits()) { // Show "00.000E0" on pattern "00.000E0"
micros.rounder.apply(quantity, fSettings.fEngineeringInterval, status);
exponent = 0;
} else {
micros.rounder.apply(quantity, status);
exponent = 0;
}
} else {
exponent = -micros.rounder.chooseMultiplierAndApply(quantity, *this, status);
}
// Use MicroProps's helper ScientificModifier and save it as the modInner.
ScientificModifier &mod = micros.helpers.scientificModifier;
mod.set(exponent, this);
micros.modInner = &mod;
// Change the exponent only after we select appropriate plural form // for formatting purposes so that we preserve expected formatted // string behavior.
quantity.adjustExponent(exponent);
// We already performed rounding. Do not perform it again.
micros.rounder = RoundingImpl::passThrough();
}
int32_t ScientificHandler::getMultiplier(int32_t magnitude) const {
int32_t interval = fSettings.fEngineeringInterval;
int32_t digitsShown; if (fSettings.fRequireMinInt) { // For patterns like "000.00E0" and ".00E0"
digitsShown = interval;
} elseif (interval <= 1) { // For patterns like "0.00E0" and "@@@E0"
digitsShown = 1;
} else { // For patterns like "##0.00"
digitsShown = ((magnitude % interval + interval) % interval) + 1;
} return digitsShown - magnitude - 1;
}
#endif/* #if !UCONFIG_NO_FORMATTING */
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 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.