// This file contains compliant implementations of FormattedValue which can be // leveraged by ICU formatters. // // Each implementation is defined in its own cpp file in order to split // dependencies more modularly.
/** * Represents the type of constraint for ConstrainedFieldPosition. * * Constraints are used to control the behavior of iteration in FormattedValue. * * @internal
*/ typedefenum UCFPosConstraintType { /** * Represents the lack of a constraint. * * This is the value of fConstraint if no "constrain" methods were called. * * @internal
*/
UCFPOS_CONSTRAINT_NONE = 0,
/** * Represents that the field category is constrained. * * This is the value of fConstraint if constraintCategory was called. * * FormattedValue implementations should not change the field category * while this constraint is active. * * @internal
*/
UCFPOS_CONSTRAINT_CATEGORY,
/** * Represents that the field and field category are constrained. * * This is the value of fConstraint if constraintField was called. * * FormattedValue implementations should not change the field or field category * while this constraint is active. * * @internal
*/
UCFPOS_CONSTRAINT_FIELD
} UCFPosConstraintType;
U_NAMESPACE_BEGIN
/** * Implementation of FormattedValue using FieldPositionHandler to accept fields. * * TODO(ICU-20897): This class is unused. If it is not needed when fixing ICU-20897, * it should be deleted.
*/ class FormattedValueFieldPositionIteratorImpl : public UMemory, public FormattedValue { public:
/** @param initialFieldCapacity Initially allocate space for this many fields. */
FormattedValueFieldPositionIteratorImpl(int32_t initialFieldCapacity, UErrorCode& status);
/** * Computes the spans for duplicated values. * For example, if the string has fields: * * ...aa..[b.cc]..d.[bb.e.c]..a.. * * then the spans will be the bracketed regions. * * Assumes that the currently known fields are sorted * and all in the same category.
*/ void addOverlapSpans(UFieldCategory spanCategory, int8_t firstIndex, UErrorCode& status);
/** * Sorts the fields: start index first, length second.
*/ void sort();
// Internal struct that must be exported for MSVC struct U_I18N_API SpanInfo {
UFieldCategory category;
int32_t spanValue;
int32_t start;
int32_t length;
};
// Export an explicit template instantiation of the MaybeStackArray that // is used as a data member of CEBuffer. // // When building DLLs for Windows this is required even though // no direct access to the MaybeStackArray leaks out of the i18n library. // // See digitlst.h, pluralaffix.h, datefmt.h, and others for similar examples. // #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN templateclass U_I18N_API MaybeStackArray<SpanInfo, 8>; #endif
/** * Implementation of FormattedValue based on FormattedStringBuilder. * * The implementation currently revolves around numbers and number fields. * However, it can be generalized in the future when there is a need. * * @author sffc (Shane Carr)
*/ // Exported as U_I18N_API for tests class U_I18N_API FormattedValueStringBuilderImpl : public UMemory, public FormattedValue { public:
/** * Adds additional metadata used for span fields. * * category: the category to use for the span field. * spanValue: the value of the span field: index of the list item, for example. * start: the start position within the string of the span. -1 if unknown. * length: the length of the span, used to split adjacent fields.
*/ void appendSpanInfo(UFieldCategory category, int32_t spanValue, int32_t start, int32_t length, UErrorCode& status); void prependSpanInfo(UFieldCategory category, int32_t spanValue, int32_t start, int32_t length, UErrorCode& status);
// C API Helpers for FormattedValue // Magic number as ASCII == "UFV" struct UFormattedValueImpl; typedef IcuCApiHelper<UFormattedValue, UFormattedValueImpl, 0x55465600> UFormattedValueApiHelper; struct UFormattedValueImpl : public UMemory, public UFormattedValueApiHelper { // This pointer should be set by the child class.
FormattedValue* fFormattedValue = nullptr;
};
/** Boilerplate to check for valid status before dereferencing the fData pointer. */ #define UPRV_FORMATTED_VALUE_METHOD_GUARD(returnExpression) \ if (U_FAILURE(status)) { \ return returnExpression; \
} \ if (fData == nullptr) { \
status = fErrorCode; \ return returnExpression; \
} \
/** * Implementation of the standard methods for a UFormattedValue "subclass" C API. * @param CPPType The public C++ type, like FormattedList * @param CType The public C type, like UFormattedList * @param ImplType A name to use for the implementation class * @param HelperType A name to use for the "mixin" typedef for C API conversion * @param Prefix The C API prefix, like ulistfmt * @param MagicNumber A unique 32-bit number to use to identify this type
*/ #define UPRV_FORMATTED_VALUE_CAPI_AUTO_IMPL(CPPType, CType, ImplType, HelperType, Prefix, MagicNumber) \
U_NAMESPACE_BEGIN \ class ImplType; \ typedef IcuCApiHelper<CType, ImplType, MagicNumber> HelperType; \ class ImplType : public UFormattedValueImpl, public HelperType { \ public: \
ImplType(); \
~ImplType(); \
CPPType fImpl; \
}; \
ImplType::ImplType() { \
fFormattedValue = &fImpl; \
} \
ImplType::~ImplType() {} \
U_NAMESPACE_END \
UPRV_FORMATTED_VALUE_CAPI_NO_IMPLTYPE_AUTO_IMPL(CType, ImplType, HelperType, Prefix)
¤ 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.0.13Bemerkung:
(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.