const SimpleFormatter *MeasureFormat::getFormatter( const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index, UErrorCode &errorCode) const { if (U_FAILURE(errorCode)) { return NULL; } const SimpleFormatter *pattern = getFormatterOrNull(unit, width, index); if (pattern == NULL) { errorCode = U_MISSING_RESOURCE_ERROR; } return pattern; }
const SimpleFormatter *MeasureFormat::getPluralFormatter( const MeasureUnit &unit, UMeasureFormatWidth width, int32_t index, UErrorCode &errorCode) const { if (U_FAILURE(errorCode)) { return NULL; } if (index != StandardPlural::OTHER) { const SimpleFormatter *pattern = getFormatterOrNull(unit, width, index); if (pattern != NULL) { return pattern; } } return getFormatter(unit, width, StandardPlural::OTHER, errorCode); }
int32_t MeasureFormat::withPerUnitAndAppend( const UnicodeString &formatted, const MeasureUnit &perUnit, UnicodeString &appendTo, UErrorCode &status) const { int32_t offset = -1; if (U_FAILURE(status)) { return offset; } const SimpleFormatter *perUnitFormatter = getFormatterOrNull(perUnit, width, MeasureFormatCacheData::PER_UNIT_INDEX); if (perUnitFormatter != NULL) { const UnicodeString *params[] = {&formatted}; perUnitFormatter->formatAndAppend( params, UPRV_LENGTHOF(params), appendTo, &offset, 1, status); return offset; } const SimpleFormatter *perFormatter = getPerFormatter(width, status); const SimpleFormatter *pattern = getPluralFormatter(perUnit, width, StandardPlural::ONE, status); if (U_FAILURE(status)) { return offset; } UnicodeString perUnitString = pattern->getTextWithNoArguments(); perUnitString.trim(); const UnicodeString *params[] = {&formatted, &perUnitString}; perFormatter->formatAndAppend( params, UPRV_LENGTHOF(params), appendTo, &offset, 1, status); return offset; }