2014-01-29 05:08:55 +00:00
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* Copyright (C) 2014, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
******************************************************************************
|
|
|
|
* quantityformatter.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __QUANTITY_FORMATTER_H__
|
|
|
|
#define __QUANTITY_FORMATTER_H__
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uobject.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2014-01-29 22:57:06 +00:00
|
|
|
class SimplePatternFormatter;
|
2014-01-29 05:08:55 +00:00
|
|
|
class UnicodeString;
|
|
|
|
class PluralRules;
|
|
|
|
class NumberFormat;
|
|
|
|
class Formattable;
|
2014-02-04 00:29:17 +00:00
|
|
|
class FieldPosition;
|
2014-01-29 05:08:55 +00:00
|
|
|
|
|
|
|
/**
|
2014-01-29 22:57:06 +00:00
|
|
|
* A plural aware formatter that is good for expressing a single quantity and
|
2014-01-29 05:08:55 +00:00
|
|
|
* a unit.
|
|
|
|
* <p>
|
|
|
|
* First use the add() methods to add a pattern for each plural variant.
|
|
|
|
* There must be a pattern for the "other" variant.
|
|
|
|
* Then use the format() method.
|
|
|
|
* <p>
|
|
|
|
* Concurrent calls only to const methods on a QuantityFormatter object are
|
|
|
|
* safe, but concurrent const and non-const method calls on a QuantityFormatter
|
|
|
|
* object are not safe and require synchronization.
|
|
|
|
*
|
|
|
|
*/
|
2014-01-29 05:52:11 +00:00
|
|
|
class U_I18N_API QuantityFormatter : public UMemory {
|
2014-01-29 05:08:55 +00:00
|
|
|
// TODO(Travis Keep): Add test for copy constructor, assignment, and reset.
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
QuantityFormatter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
*/
|
|
|
|
QuantityFormatter(const QuantityFormatter& other);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment operator
|
|
|
|
*/
|
|
|
|
QuantityFormatter &operator=(const QuantityFormatter& other);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~QuantityFormatter();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all variants from this object including the "other" variant.
|
|
|
|
*/
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a plural variant.
|
|
|
|
*
|
|
|
|
* @param variant "zero", "one", "two", "few", "many", "other"
|
|
|
|
* @param rawPattern the pattern for the variant e.g "{0} meters"
|
|
|
|
* @param status any error returned here.
|
|
|
|
* @return TRUE on success; FALSE otherwise.
|
|
|
|
*/
|
|
|
|
UBool add(
|
|
|
|
const char *variant,
|
|
|
|
const UnicodeString &rawPattern,
|
|
|
|
UErrorCode &status);
|
|
|
|
|
2014-02-04 00:29:17 +00:00
|
|
|
/**
|
|
|
|
* returns TRUE if this object has at least the "other" variant.
|
|
|
|
*/
|
|
|
|
UBool isValid() const;
|
|
|
|
|
2014-01-29 05:08:55 +00:00
|
|
|
/**
|
|
|
|
* Formats a quantity with this object appending the result to appendTo.
|
|
|
|
* At least the "other" variant must be added to this object for this
|
|
|
|
* method to work.
|
|
|
|
*
|
|
|
|
* @param quantity the single quantity.
|
|
|
|
* @param fmt formats the quantity
|
|
|
|
* @param rules computes the plural variant to use.
|
|
|
|
* @param appendTo result appended here.
|
|
|
|
* @param status any error returned here.
|
|
|
|
* @return appendTo
|
|
|
|
*/
|
|
|
|
UnicodeString &format(
|
|
|
|
const Formattable &quantity,
|
|
|
|
const NumberFormat &fmt,
|
|
|
|
const PluralRules &rules,
|
|
|
|
UnicodeString &appendTo,
|
2014-02-04 00:29:17 +00:00
|
|
|
FieldPosition &pos,
|
2014-01-29 05:08:55 +00:00
|
|
|
UErrorCode &status) const;
|
|
|
|
|
|
|
|
private:
|
2014-01-29 22:57:06 +00:00
|
|
|
SimplePatternFormatter *formatters[6];
|
2014-01-29 05:08:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif
|