// Allow implicit conversion from char16_t* to UnicodeString for this file: // Helpful in toString methods and elsewhere. #define UNISTR_FROM_STRING_EXPLICIT
if (properties.minimumExponentDigits != -1) { // Scientific notation is required. // This whole section feels like a hack, but it is needed for regression tests. // The mapping from property bag to scientific notation is nontrivial due to LDML rules. if (maxInt > 8) { // But #13110: The maximum of 8 digits has unknown origins and is not in the spec. // If maxInt is greater than 8, it is set to minInt, even if minInt is greater than 8.
maxInt = minInt;
macros.integerWidth = IntegerWidth::zeroFillTo(minInt).truncateAt(maxInt);
} elseif (maxInt > minInt && minInt > 1) { // Bug #13289: if maxInt > minInt > 1, then minInt should be 1.
minInt = 1;
macros.integerWidth = IntegerWidth::zeroFillTo(minInt).truncateAt(maxInt);
} int engineering = maxInt < 0 ? -1 : maxInt;
macros.notation = ScientificNotation( // Engineering interval: static_cast<int8_t>(engineering), // Enforce minimum integer digits (for patterns like "000.00E0"):
(engineering == minInt), // Minimum exponent digits: static_cast<digits_t>(properties.minimumExponentDigits), // Exponent sign always shown:
properties.exponentSignAlwaysShown ? UNUM_SIGN_ALWAYS : UNUM_SIGN_AUTO); // Scientific notation also involves overriding the rounding mode. // TODO: Overriding here is a bit of a hack. Should this logic go earlier? if (macros.precision.fType == Precision::PrecisionType::RND_FRACTION) { // For the purposes of rounding, get the original min/max int/frac, since the local // variables have been manipulated for display purposes. int maxInt_ = properties.maximumIntegerDigits; int minInt_ = properties.minimumIntegerDigits; int minFrac_ = properties.minimumFractionDigits; int maxFrac_ = properties.maximumFractionDigits; if (minInt_ == 0 && maxFrac_ == 0) { // Patterns like "#E0" and "##E0", which mean no rounding!
macros.precision = Precision::unlimited();
} elseif (minInt_ == 0 && minFrac_ == 0) { // Patterns like "#.##E0" (no zeros in the mantissa), which mean round to maxFrac+1
macros.precision = Precision::constructSignificant(1, maxFrac_ + 1);
} else { int maxSig_ = minInt_ + maxFrac_; // Bug #20058: if maxInt_ > minInt_ > 1, then minInt_ should be 1. if (maxInt_ > minInt_ && minInt_ > 1) {
minInt_ = 1;
} int minSig_ = minInt_ + minFrac_; // To avoid regression, maxSig is not reset when minInt_ set to 1. // TODO: Reset maxSig_ = 1 + minFrac_ to follow the spec.
macros.precision = Precision::constructSignificant(minSig_, maxSig_);
}
macros.roundingMode = roundingMode;
}
}
// There are two ways to set affixes in DecimalFormat: via the pattern string (applyPattern), and via the // explicit setters (setPositivePrefix and friends). The way to resolve the settings is as follows: // // 1) If the explicit setting is present for the field, use it. // 2) Otherwise, follows UTS 35 rules based on the pattern string. // // Importantly, the explicit setters affect only the one field they override. If you set the positive // prefix, that should not affect the negative prefix.
// Convenience: Extract the properties into local variables. // Variables are named with three chars: [p/n][p/s][o/p] // [p/n] => p for positive, n for negative // [p/s] => p for prefix, s for suffix // [o/p] => o for escaped custom override string, p for pattern string
UnicodeString ppo = AffixUtils::escape(properties.positivePrefix);
UnicodeString pso = AffixUtils::escape(properties.positiveSuffix);
UnicodeString npo = AffixUtils::escape(properties.negativePrefix);
UnicodeString nso = AffixUtils::escape(properties.negativeSuffix); const UnicodeString& ppp = properties.positivePrefixPattern; const UnicodeString& psp = properties.positiveSuffixPattern; const UnicodeString& npp = properties.negativePrefixPattern; const UnicodeString& nsp = properties.negativeSuffixPattern;
// For declaring if this is a currency pattern, we need to look at the // original pattern, not at any user-specified overrides.
isCurrencyPattern = (
AffixUtils::hasCurrencySymbols(ppp, status) ||
AffixUtils::hasCurrencySymbols(psp, status) ||
AffixUtils::hasCurrencySymbols(npp, status) ||
AffixUtils::hasCurrencySymbols(nsp, status) ||
properties.currencyAsDecimal);
void CurrencyPluralInfoAffixProvider::setTo(const CurrencyPluralInfo& cpi, const DecimalFormatProperties& properties,
UErrorCode& status) { // We need to use a PropertiesAffixPatternProvider, not the simpler version ParsedPatternInfo, // because user-specified affix overrides still need to work.
fBogus = false;
DecimalFormatProperties pluralProperties(properties); for (int32_t plural = 0; plural < StandardPlural::COUNT; plural++) { constchar* keyword = StandardPlural::getKeyword(static_cast<StandardPlural::Form>(plural));
UnicodeString patternString;
patternString = cpi.getCurrencyPluralPattern(keyword, patternString);
PatternParser::parseToExistingProperties(
patternString,
pluralProperties,
IGNORE_ROUNDING_NEVER,
status);
affixesByPlural[plural].setTo(pluralProperties, status);
}
}
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.