2 *******************************************************************************
3 * Copyright (C) 2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
6 * digitaffixesandpadding.h
8 * created on: 2015jan06
9 * created by: Travis Keep
12 #ifndef __DIGITAFFIXESANDPADDING_H__
13 #define __DIGITAFFIXESANDPADDING_H__
15 #include "unicode/utypes.h"
17 #if !UCONFIG_NO_FORMATTING
19 #include "unicode/uobject.h"
20 #include "pluralaffix.h"
27 class FieldPositionHandler
;
29 class VisibleDigitsWithExponent
;
32 * A formatter of numbers. This class can format any numerical value
33 * except for not a number (NaN), positive infinity, and negative infinity.
34 * This class manages prefixes, suffixes, and padding but delegates the
35 * formatting of actual positive values to a ValueFormatter.
37 class U_I18N_API DigitAffixesAndPadding
: public UMemory
{
41 * Equivalent to DecimalFormat EPadPosition, but redeclared here to prevent
42 * depending on DecimalFormat which would cause a circular dependency.
54 PluralAffix fPositivePrefix
;
59 PluralAffix fPositiveSuffix
;
64 PluralAffix fNegativePrefix
;
69 PluralAffix fNegativeSuffix
;
72 * The padding position
74 EPadPosition fPadPosition
;
77 * The padding character.
82 * The field width in code points. The format method inserts instances of
83 * the padding character as needed in the desired padding position so that
84 * the entire formatted string contains this many code points. If the
85 * formatted string already exceeds this many code points, the format method
91 * Pad position is before prefix; padding character is '*' field width is 0.
92 * The affixes are all the empty string with no annotated fields with just
93 * the 'other' plural variation.
95 DigitAffixesAndPadding()
96 : fPadPosition(kPadBeforePrefix
), fPadChar(0x2a), fWidth(0) { }
99 * Returns TRUE if this object is equal to rhs.
101 UBool
equals(const DigitAffixesAndPadding
&rhs
) const {
102 return (fPositivePrefix
.equals(rhs
.fPositivePrefix
) &&
103 fPositiveSuffix
.equals(rhs
.fPositiveSuffix
) &&
104 fNegativePrefix
.equals(rhs
.fNegativePrefix
) &&
105 fNegativeSuffix
.equals(rhs
.fNegativeSuffix
) &&
106 fPadPosition
== rhs
.fPadPosition
&&
107 fWidth
== rhs
.fWidth
&&
108 fPadChar
== rhs
.fPadChar
);
112 * Returns TRUE if a plural rules instance is needed to complete the
113 * formatting by detecting if any of the affixes have multiple plural
116 UBool
needsPluralRules() const;
119 * Formats value and appends to appendTo.
121 * @param value the value to format. May be NaN or ininite.
122 * @param formatter handles the details of formatting the actual value.
123 * @param handler records field positions
124 * @param optPluralRules the plural rules, but may be NULL if
125 * needsPluralRules returns FALSE.
126 * @appendTo formatted string appended here.
127 * @status any error returned here.
129 UnicodeString
&format(
130 const VisibleDigitsWithExponent
&value
,
131 const ValueFormatter
&formatter
,
132 FieldPositionHandler
&handler
,
133 const PluralRules
*optPluralRules
,
134 UnicodeString
&appendTo
,
135 UErrorCode
&status
) const;
140 UnicodeString
&format(
142 const ValueFormatter
&formatter
,
143 FieldPositionHandler
&handler
,
144 const PluralRules
*optPluralRules
,
145 UnicodeString
&appendTo
,
146 UErrorCode
&status
) const;
149 * Formats a 32-bit integer and appends to appendTo. When formatting an
150 * integer, this method is preferred to plain format as it can run
151 * several times faster under certain conditions.
153 * @param value the value to format.
154 * @param formatter handles the details of formatting the actual value.
155 * @param handler records field positions
156 * @param optPluralRules the plural rules, but may be NULL if
157 * needsPluralRules returns FALSE.
158 * @appendTo formatted string appended here.
159 * @status any error returned here.
161 UnicodeString
&formatInt32(
163 const ValueFormatter
&formatter
,
164 FieldPositionHandler
&handler
,
165 const PluralRules
*optPluralRules
,
166 UnicodeString
&appendTo
,
167 UErrorCode
&status
) const;
170 UnicodeString
&appendPadding(int32_t paddingCount
, UnicodeString
&appendTo
) const;
176 #endif /* #if !UCONFIG_NO_FORMATTING */
177 #endif // __DIGITAFFIXANDPADDING_H__