// LongNameHandler takes care of formatting currency and measurement unit names, // as well as populating the gender of measure units. class LongNameHandler : public MicroPropsGenerator, public ModifierStore, public UMemory {
public: static UnicodeString getUnitDisplayName( const Locale& loc, const MeasureUnit& unit,
UNumberUnitWidth width,
UErrorCode& status);
// This function does not support inflections or other newer NumberFormatter // features: it exists to support the older not-recommended MeasureFormat. static UnicodeString getUnitPattern( const Locale& loc, const MeasureUnit& unit,
UNumberUnitWidth width,
StandardPlural::Form pluralForm,
UErrorCode& status);
private: // A set of pre-computed modifiers, one for each plural form.
SimpleModifier fModifiers[StandardPlural::Form::COUNT]; // Not owned const PluralRules *rules; // Not owned const MicroPropsGenerator *parent; // Grammatical gender of the formatted result. Not owned: must point at // static or global strings. constchar *gender = "";
// Enables MemoryPool<LongNameHandler>::emplaceBack(): requires access to // the private constructors. friendclass MemoryPool<LongNameHandler>;
// Allow macrosToMicroGenerator to call the private default constructor. friendclass NumberFormatterImpl;
// Fills in LongNameHandler fields for formatting units identified `unit`. staticvoid forArbitraryUnit(const Locale &loc, const MeasureUnit &unit, const UNumberUnitWidth &width, constchar *unitDisplayCase,
LongNameHandler *fillIn,
UErrorCode &status);
// Roughly corresponds to patternTimes(...) in the spec: // https://unicode.org/reports/tr35/tr35-general.html#compound-units // // productUnit is an rvalue reference to indicate this function consumes it, // leaving it in a not-useful / undefined state. staticvoid processPatternTimes(MeasureUnitImpl &&productUnit,
Locale loc, const UNumberUnitWidth &width, constchar *caseVariant,
UnicodeString *outArray,
UErrorCode &status);
// Sets fModifiers to use the patterns from `simpleFormats`. void simpleFormatsToModifiers(const UnicodeString *simpleFormats, Field field, UErrorCode &status);
// Sets fModifiers to a combination of `leadFormats` (one per plural form) // and `trailFormat` appended to each. // // With a leadFormat of "{0}m" and a trailFormat of "{0}/s", it produces a // pattern of "{0}m/s" by inserting each leadFormat pattern into trailFormat. void multiSimpleFormatsToModifiers(const UnicodeString *leadFormats, UnicodeString trailFormat,
Field field, UErrorCode &status);
};
// Similar to LongNameHandler, but only for MIXED units. class MixedUnitLongNameHandler : public MicroPropsGenerator, public ModifierStore, public UMemory {
public: /** *ConstructalocalizedMixedUnitLongNameHandlerforthespecified *MeasureUnit.ItmustbeaMIXEDunit. * *ThisfunctionusesafillIninsteadofreturningapointer,becausewe *wanttofillininstancesinaMemoryPool(whichcannotadoptpointersit *didn'tcreateitself). * *@paramlocThedesiredlocale. *@parammixedUnitThemixedmeasureunittoconstructa *MixedUnitLongNameHandlerfor. *@paramwidthSpecifiesthedesiredunitrendering. *@paramunitDisplayCaseSpecifiesthedesiredgrammaticalcase.Ifthe *specifiedcaseisnotfound,wefallbacktonominativeorno-case. *@paramrulesDoesnottakeownership. *@paramparentDoesnottakeownership. *@paramfillInRequired.
*/ staticvoid forMeasureUnit(const Locale &loc, const MeasureUnit &mixedUnit, const UNumberUnitWidth &width, constchar *unitDisplayCase, const PluralRules *rules, const MicroPropsGenerator *parent,
MixedUnitLongNameHandler *fillIn,
UErrorCode &status);
// Required for ModifierStore. And ModifierStore is required by // SimpleModifier constructor's last parameter. We assert his will never get // called though. const Modifier *getModifier(Signum signum, StandardPlural::Form plural) const override;
private: // Not owned const PluralRules *rules;
// Not owned const MicroPropsGenerator *parent;
// Total number of units in the MeasureUnit this handler was configured for: // for "foot-and-inch", this will be 2.
int32_t fMixedUnitCount = 1;
// Stores unit data for each of the individual units. For each unit, it // stores ARRAY_LENGTH strings, as returned by getMeasureData. (Each unit // with index `i` has ARRAY_LENGTH strings starting at index // `i*ARRAY_LENGTH` in this array.)
LocalArray<UnicodeString> fMixedUnitData;
// Formats the larger units of Mixed Unit measurements.
LocalizedNumberFormatter fNumberFormatter;
// Joins mixed units together.
LocalPointer<ListFormatter> fListFormatter;
// Allow macrosToMicroGenerator to call the private default constructor. friendclass NumberFormatterImpl;
// Enables MemoryPool<LongNameHandler>::emplaceBack(): requires access to // the private constructors. friendclass MemoryPool<MixedUnitLongNameHandler>;
// For a mixed unit, returns a Modifier that takes only one parameter: the // smallest and final unit of the set. The bigger units' values and labels // get baked into this Modifier, together with the unit label of the final // unit. const Modifier *getMixedUnitModifier(DecimalQuantity &quantity, MicroProps µs,
UErrorCode &status) const;
};
/** *AMicroPropsGeneratorthatmultiplexesbetweendifferentLongNameHandlers, *dependingontheoutputUnit. * *SeeprocessQuantity()fortheinputrequirements.
*/ class LongNameMultiplexer : public MicroPropsGenerator, public UMemory {
public: // Produces a multiplexer for LongNameHandlers, one for each unit in // `units`. An individual unit might be a mixed unit. static LongNameMultiplexer *forMeasureUnits(const Locale &loc, const MaybeStackVector<MeasureUnit> &units, const UNumberUnitWidth &width, constchar *unitDisplayCase, const PluralRules *rules, const MicroPropsGenerator *parent,
UErrorCode &status);
// The output unit must be provided via `micros.outputUnit`, it must match // one of the units provided to the factory function. void processQuantity(DecimalQuantity &quantity, MicroProps µs,
UErrorCode &status) const override;
private: /** *BecauseweonlyknowwhichLongNameHandlerwewishtocallaftercalling *earlierMicroPropsGeneratorsinthechain,LongNameMultiplexerkeepsthe *parentlink,whiletheLongNameHandlersaregivennoparents.
*/
MemoryPool<LongNameHandler> fLongNameHandlers;
MemoryPool<MixedUnitLongNameHandler> fMixedUnitHandlers; // Unowned pointers to instances owned by MaybeStackVectors.
MaybeStackArray<MicroPropsGenerator *, 8> fHandlers; // Each MeasureUnit corresponds to the same-index MicroPropsGenerator // pointed to in fHandlers.
LocalArray<MeasureUnit> fMeasureUnits;
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.