2 ******************************************************************************
3 * Copyright (C) 2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************
9 #ifndef __QUANTITY_FORMATTER_H__
10 #define __QUANTITY_FORMATTER_H__
12 #include "unicode/utypes.h"
13 #include "unicode/uobject.h"
15 #if !UCONFIG_NO_FORMATTING
19 class SimplePatternFormatter
;
27 * A plural aware formatter that is good for expressing a single quantity and
30 * First use the add() methods to add a pattern for each plural variant.
31 * There must be a pattern for the "other" variant.
32 * Then use the format() method.
34 * Concurrent calls only to const methods on a QuantityFormatter object are
35 * safe, but concurrent const and non-const method calls on a QuantityFormatter
36 * object are not safe and require synchronization.
39 class U_I18N_API QuantityFormatter
: public UMemory
{
42 * Default constructor.
49 QuantityFormatter(const QuantityFormatter
& other
);
54 QuantityFormatter
&operator=(const QuantityFormatter
& other
);
62 * Removes all variants from this object including the "other" variant.
67 * Adds a plural variant.
69 * @param variant "zero", "one", "two", "few", "many", "other"
70 * @param rawPattern the pattern for the variant e.g "{0} meters"
71 * @param status any error returned here.
72 * @return TRUE on success; FALSE if status was set to a non zero error.
76 const UnicodeString
&rawPattern
,
80 * returns TRUE if this object has at least the "other" variant.
82 UBool
isValid() const;
85 * Gets the pattern formatter that would be used for a particular variant.
86 * If isValid() returns TRUE, this method is guaranteed to return a
89 const SimplePatternFormatter
*getByVariant(const char *variant
) const;
92 * Formats a quantity with this object appending the result to appendTo.
93 * At least the "other" variant must be added to this object for this
96 * @param quantity the single quantity.
97 * @param fmt formats the quantity
98 * @param rules computes the plural variant to use.
99 * @param appendTo result appended here.
100 * @param status any error returned here.
103 UnicodeString
&format(
104 const Formattable
&quantity
,
105 const NumberFormat
&fmt
,
106 const PluralRules
&rules
,
107 UnicodeString
&appendTo
,
109 UErrorCode
&status
) const;
112 SimplePatternFormatter
*formatters
[6];