* @param index of the resource array item
* @param value resource value
*/
- virtual void put(int32_t index, ResourceValue &value, UErrorCode &errorCode);
+ virtual void put(int32_t index, const ResourceValue &value, UErrorCode &errorCode);
/**
* Returns a nested resource array at the array index as another sink.
virtual ResourceTableSink *getOrCreateTableSink(
int32_t index, int32_t initialSize, UErrorCode &errorCode);
+ /**
+ * "Leaves" the array.
+ * Indicates that all of the resources and sub-resources of the current array
+ * have been enumerated.
+ */
+ virtual void leave(UErrorCode &errorCode);
+
private:
ResourceArraySink(const ResourceArraySink &); // no copy constructor
ResourceArraySink &operator=(const ResourceArraySink &); // no assignment operator
* @param key resource key string
* @param value resource value
*/
- virtual void put(const char *key, ResourceValue &value, UErrorCode &errorCode);
+ virtual void put(const char *key, const ResourceValue &value, UErrorCode &errorCode);
/**
* Adds a no-fallback/no-inheritance marker for this key.
virtual ResourceTableSink *getOrCreateTableSink(
const char *key, int32_t initialSize, UErrorCode &errorCode);
+ /**
+ * "Leaves" the table.
+ * Indicates that all of the resources and sub-resources of the current table
+ * have been enumerated.
+ */
+ virtual void leave(UErrorCode &errorCode);
+
private:
ResourceTableSink(const ResourceTableSink &); // no copy constructor
ResourceTableSink &operator=(const ResourceTableSink &); // no assignment operator
NumericDateFormatters &operator=(const NumericDateFormatters &other);
};
+static UMeasureFormatWidth getRegularWidth(UMeasureFormatWidth width) {
+ if (width >= WIDTH_INDEX_COUNT) {
+ return UMEASFMT_WIDTH_NARROW;
+ }
+ return width;
+}
+
/**
* Instances contain all MeasureFormat specific data for a particular locale.
* This data is cached. It is never copied, but is shared via shared pointers.
delete currencyFormats[widthIndex];
currencyFormats[widthIndex] = nfToAdopt;
}
- const NumberFormat *getCurrencyFormat(int32_t widthIndex) const {
- return currencyFormats[widthIndex];
+ const NumberFormat *getCurrencyFormat(UMeasureFormatWidth width) const {
+ return currencyFormats[getRegularWidth(width)];
}
void adoptIntegerFormat(NumberFormat *nfToAdopt) {
delete integerFormat;
const NumericDateFormatters *getNumericDateFormatters() const {
return numericDateFormatters;
}
- void setPerUnitFormatterIfAbsent(int32_t unitIndex, int32_t width, ResourceValue &value,
+ void setPerUnitFormatterIfAbsent(int32_t unitIndex, int32_t width, const ResourceValue &value,
UErrorCode &errorCode) {
if (perUnitFormatters[unitIndex][width] == NULL) {
perUnitFormatters[unitIndex][width] =
delete numericDateFormatters;
}
-static int32_t widthToIndex(UMeasureFormatWidth width) {
- if (width >= WIDTH_INDEX_COUNT) {
- return WIDTH_INDEX_COUNT - 1;
- }
- return width;
-}
-
static UBool isCurrency(const MeasureUnit &unit) {
return (uprv_strcmp(unit.getType(), "currency") == 0);
}
struct UnitPatternSink : public ResourceTableSink {
UnitPatternSink(UnitDataSink &sink) : outer(sink) {}
~UnitPatternSink();
- virtual void put(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ virtual void put(const char *key, const ResourceValue &value, UErrorCode &errorCode) {
if (U_FAILURE(errorCode)) { return; }
if (uprv_strcmp(key, "dnam") == 0) {
// Skip the unit display name for now.
struct UnitCompoundSink : public ResourceTableSink {
UnitCompoundSink(UnitDataSink &sink) : outer(sink) {}
~UnitCompoundSink();
- virtual void put(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ virtual void put(const char *key, const ResourceValue &value, UErrorCode &errorCode) {
if (U_SUCCESS(errorCode) && uprv_strcmp(key, "per") == 0) {
outer.cacheData.perFormatters[outer.width].
compile(value.getUnicodeString(errorCode), errorCode);
cacheData(outputData),
width(UMEASFMT_WIDTH_COUNT), type(NULL), unitIndex(0), hasPatterns(FALSE) {}
~UnitDataSink();
- virtual void put(const char *key, ResourceValue &value, UErrorCode &errorCode) {
+ virtual void put(const char *key, const ResourceValue &value, UErrorCode &errorCode) {
// Handle aliases like
// units:alias{"/LOCALE/unitsShort"}
// which should only occur in the root bundle.
delete listFormatter;
listFormatter = ListFormatter::createInstance(
locale,
- listStyles[widthToIndex(width)],
+ listStyles[getRegularWidth(width)],
status);
}
if (isCurrency(amtUnit)) {
UChar isoCode[4];
u_charsToUChars(amtUnit.getSubtype(), isoCode, 4);
- return cache->getCurrencyFormat(widthToIndex(width))->format(
+ return cache->getCurrencyFormat(width)->format(
new CurrencyAmount(amtNumber, isoCode, status),
appendTo,
pos,
status);
}
- const QuantityFormatter *quantityFormatter = getQuantityFormatter(
- amtUnit.getIndex(), widthToIndex(width), status);
+ const QuantityFormatter *quantityFormatter = getQuantityFormatter(amtUnit, width, status);
if (U_FAILURE(status)) {
return appendTo;
}
}
const QuantityFormatter *MeasureFormat::getQuantityFormatter(
- int32_t index,
- int32_t widthIndex,
+ const MeasureUnit &unit,
+ UMeasureFormatWidth width,
UErrorCode &status) const {
if (U_FAILURE(status)) {
return NULL;
}
- const QuantityFormatter *formatters =
- cache->formatters[index];
- if (formatters[widthIndex].isValid()) {
- return &formatters[widthIndex];
+ width = getRegularWidth(width);
+ const QuantityFormatter *formatters = cache->formatters[unit.getIndex()];
+ if (formatters[width].isValid()) {
+ return &formatters[width];
}
- int32_t fallbackWidth = cache->widthFallback[widthIndex];
+ int32_t fallbackWidth = cache->widthFallback[width];
if (fallbackWidth != UMEASFMT_WIDTH_COUNT && formatters[fallbackWidth].isValid()) {
return &formatters[fallbackWidth];
}
}
const SimplePatternFormatter *MeasureFormat::getPerUnitFormatter(
- int32_t index,
- int32_t widthIndex) const {
+ const MeasureUnit &unit,
+ UMeasureFormatWidth width) const {
+ width = getRegularWidth(width);
const SimplePatternFormatter * const * perUnitFormatters =
- cache->getPerUnitFormattersByIndex(index);
- if (perUnitFormatters[widthIndex] != NULL) {
- return perUnitFormatters[widthIndex];
+ cache->getPerUnitFormattersByIndex(unit.getIndex());
+ if (perUnitFormatters[width] != NULL) {
+ return perUnitFormatters[width];
}
- int32_t fallbackWidth = cache->widthFallback[widthIndex];
+ int32_t fallbackWidth = cache->widthFallback[width];
if (fallbackWidth != UMEASFMT_WIDTH_COUNT && perUnitFormatters[fallbackWidth] != NULL) {
return perUnitFormatters[fallbackWidth];
}
}
const SimplePatternFormatter *MeasureFormat::getPerFormatter(
- int32_t widthIndex,
+ UMeasureFormatWidth width,
UErrorCode &status) const {
if (U_FAILURE(status)) {
return NULL;
}
+ width = getRegularWidth(width);
const SimplePatternFormatter * perFormatters = cache->perFormatters;
- if (perFormatters[widthIndex].getPlaceholderCount() == 2) {
- return &perFormatters[widthIndex];
+ if (perFormatters[width].getPlaceholderCount() == 2) {
+ return &perFormatters[width];
}
- int32_t fallbackWidth = cache->widthFallback[widthIndex];
+ int32_t fallbackWidth = cache->widthFallback[width];
if (fallbackWidth != UMEASFMT_WIDTH_COUNT &&
perFormatters[fallbackWidth].getPlaceholderCount() == 2) {
return &perFormatters[fallbackWidth];
if (U_FAILURE(status)) {
return offset;
}
- const SimplePatternFormatter *perUnitFormatter = getPerUnitFormatter(
- perUnit.getIndex(), widthToIndex(width));
+ const SimplePatternFormatter *perUnitFormatter = getPerUnitFormatter(perUnit, width);
if (perUnitFormatter != NULL) {
const UnicodeString *params[] = {&formatted};
perUnitFormatter->formatAndAppend(
status);
return offset;
}
- const SimplePatternFormatter *perFormatter = getPerFormatter(
- widthToIndex(width), status);
- const QuantityFormatter *qf = getQuantityFormatter(
- perUnit.getIndex(), widthToIndex(width), status);
+ const SimplePatternFormatter *perFormatter = getPerFormatter(width, status);
+ const QuantityFormatter *qf = getQuantityFormatter(perUnit, width, status);
if (U_FAILURE(status)) {
return offset;
}