+UBool
+MessageFormat::usesNamedArguments() const {
+ return msgPattern.hasNamedArguments();
+}
+
+int32_t
+MessageFormat::getArgTypeCount() const {
+ return argTypeCount;
+}
+
+UBool MessageFormat::equalFormats(const void* left, const void* right) {
+ return *(const Format*)left==*(const Format*)right;
+}
+
+
+UBool MessageFormat::DummyFormat::operator==(const Format&) const {
+ return TRUE;
+}
+
+MessageFormat::DummyFormat* MessageFormat::DummyFormat::clone() const {
+ return new DummyFormat();
+}
+
+UnicodeString& MessageFormat::DummyFormat::format(const Formattable&,
+ UnicodeString& appendTo,
+ UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return appendTo;
+}
+
+UnicodeString& MessageFormat::DummyFormat::format(const Formattable&,
+ UnicodeString& appendTo,
+ FieldPosition&,
+ UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return appendTo;
+}
+
+UnicodeString& MessageFormat::DummyFormat::format(const Formattable&,
+ UnicodeString& appendTo,
+ FieldPositionIterator*,
+ UErrorCode& status) const {
+ if (U_SUCCESS(status)) {
+ status = U_UNSUPPORTED_ERROR;
+ }
+ return appendTo;
+}
+
+void MessageFormat::DummyFormat::parseObject(const UnicodeString&,
+ Formattable&,
+ ParsePosition& ) const {
+}
+
+
+FormatNameEnumeration::FormatNameEnumeration(UVector *fNameList, UErrorCode& /*status*/) {
+ pos=0;
+ fFormatNames = fNameList;
+}
+
+const UnicodeString*
+FormatNameEnumeration::snext(UErrorCode& status) {
+ if (U_SUCCESS(status) && pos < fFormatNames->size()) {
+ return (const UnicodeString*)fFormatNames->elementAt(pos++);
+ }
+ return NULL;
+}
+
+void
+FormatNameEnumeration::reset(UErrorCode& /*status*/) {
+ pos=0;
+}
+
+int32_t
+FormatNameEnumeration::count(UErrorCode& /*status*/) const {
+ return (fFormatNames==NULL) ? 0 : fFormatNames->size();
+}
+
+FormatNameEnumeration::~FormatNameEnumeration() {
+ delete fFormatNames;
+}
+
+MessageFormat::PluralSelectorProvider::PluralSelectorProvider(const MessageFormat &mf, UPluralType t)
+ : msgFormat(mf), rules(NULL), type(t) {
+}
+
+MessageFormat::PluralSelectorProvider::~PluralSelectorProvider() {
+ delete rules;
+}
+
+UnicodeString MessageFormat::PluralSelectorProvider::select(void *ctx, double number,
+ UErrorCode& ec) const {
+ if (U_FAILURE(ec)) {
+ return UnicodeString(FALSE, OTHER_STRING, 5);
+ }
+ MessageFormat::PluralSelectorProvider* t = const_cast<MessageFormat::PluralSelectorProvider*>(this);
+ if(rules == NULL) {
+ t->rules = PluralRules::forLocale(msgFormat.fLocale, type, ec);
+ if (U_FAILURE(ec)) {
+ return UnicodeString(FALSE, OTHER_STRING, 5);
+ }
+ }
+ // Select a sub-message according to how the number is formatted,
+ // which is specified in the selected sub-message.
+ // We avoid this circle by looking at how
+ // the number is formatted in the "other" sub-message
+ // which must always be present and usually contains the number.
+ // Message authors should be consistent across sub-messages.
+ PluralSelectorContext &context = *static_cast<PluralSelectorContext *>(ctx);
+ int32_t otherIndex = msgFormat.findOtherSubMessage(context.startIndex);
+ context.numberArgIndex = msgFormat.findFirstPluralNumberArg(otherIndex, context.argName);
+ if(context.numberArgIndex > 0 && msgFormat.cachedFormatters != NULL) {
+ context.formatter =
+ (const Format*)uhash_iget(msgFormat.cachedFormatters, context.numberArgIndex);
+ }
+ if(context.formatter == NULL) {
+ context.formatter = msgFormat.getDefaultNumberFormat(ec);
+ context.forReplaceNumber = TRUE;
+ }
+ if (context.number.getDouble(ec) != number) {
+ ec = U_INTERNAL_PROGRAM_ERROR;
+ return UnicodeString(FALSE, OTHER_STRING, 5);
+ }
+ context.formatter->format(context.number, context.numberString, ec);
+ auto* decFmt = dynamic_cast<const DecimalFormat *>(context.formatter);
+ if(decFmt != NULL) {
+ number::impl::DecimalQuantity dq;
+ decFmt->formatToDecimalQuantity(context.number, dq, ec);
+ if (U_FAILURE(ec)) {
+ return UnicodeString(FALSE, OTHER_STRING, 5);
+ }
+ return rules->select(dq);
+ } else {
+ return rules->select(number);
+ }
+}
+
+void MessageFormat::PluralSelectorProvider::reset() {
+ delete rules;
+ rules = NULL;
+}
+
+