-
-UBool
-TimeUnitFormat::operator==(const Format& other) const {
- if (typeid(*this) == typeid(other)) {
- TimeUnitFormat* fmt = (TimeUnitFormat*)&other;
- UBool ret = ( ((fNumberFormat && fmt->fNumberFormat && *fNumberFormat == *fmt->fNumberFormat)
- || fNumberFormat == fmt->fNumberFormat )
- && fLocale == fmt->fLocale
- && ((fPluralRules && fmt->fPluralRules && *fPluralRules == *fmt->fPluralRules)
- || fPluralRules == fmt->fPluralRules)
- && fStyle == fmt->fStyle);
- if (ret) {
- for (TimeUnit::UTimeUnitFields i = TimeUnit::UTIMEUNIT_YEAR;
- i < TimeUnit::UTIMEUNIT_FIELD_COUNT && ret;
- i = (TimeUnit::UTimeUnitFields)(i+1)) {
- ret = fTimeUnitToCountToPatterns[i]->equals(*(fmt->fTimeUnitToCountToPatterns[i]));
- }
- }
- return ret;
- }
- return false;
-}
-
-
-UnicodeString&
-TimeUnitFormat::format(const Formattable& obj, UnicodeString& toAppendTo,
- FieldPosition& pos, UErrorCode& status) const {
- if (U_FAILURE(status)) {
- return toAppendTo;
- }
- if (obj.getType() == Formattable::kObject) {
- const UObject* formatObj = obj.getObject();
- const TimeUnitAmount* amount = dynamic_cast<const TimeUnitAmount*>(formatObj);
- if (amount != NULL){
- Hashtable* countToPattern = fTimeUnitToCountToPatterns[amount->getTimeUnitField()];
- double number;
- const Formattable& amtNumber = amount->getNumber();
- if (amtNumber.getType() == Formattable::kDouble) {
- number = amtNumber.getDouble();
- } else if (amtNumber.getType() == Formattable::kLong) {
- number = amtNumber.getLong();
- } else {
- status = U_ILLEGAL_ARGUMENT_ERROR;
- return toAppendTo;
- }
- UnicodeString count = fPluralRules->select(number);
-#ifdef TMUTFMT_DEBUG
- char result[1000];
- count.extract(0, count.length(), result, "UTF-8");
- std::cout << "number: " << number << "; format plural count: " << result << "\n";
-#endif
- MessageFormat* pattern = ((MessageFormat**)countToPattern->get(count))[fStyle];
- Formattable formattable[1];
- formattable[0].setDouble(number);
- return pattern->format(formattable, 1, toAppendTo, pos, status);
- }
- }
- status = U_ILLEGAL_ARGUMENT_ERROR;
- return toAppendTo;
-}
-
-
-void
-TimeUnitFormat::parseObject(const UnicodeString& source,