1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// Copyright (C) 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2015, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* digitaffixesandpadding.h
*
* created on: 2015jan06
* created by: Travis Keep
*/
#ifndef __DIGITAFFIXESANDPADDING_H__
#define __DIGITAFFIXESANDPADDING_H__
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include "unicode/uobject.h"
#include "pluralaffix.h"
U_NAMESPACE_BEGIN
class DigitList;
class ValueFormatter;
class UnicodeString;
class FieldPositionHandler;
class PluralRules;
class VisibleDigitsWithExponent;
/**
* A formatter of numbers. This class can format any numerical value
* except for not a number (NaN), positive infinity, and negative infinity.
* This class manages prefixes, suffixes, and padding but delegates the
* formatting of actual positive values to a ValueFormatter.
*/
class U_I18N_API DigitAffixesAndPadding : public UMemory {
public:
/**
* Equivalent to DecimalFormat EPadPosition, but redeclared here to prevent
* depending on DecimalFormat which would cause a circular dependency.
*/
enum EPadPosition {
kPadBeforePrefix,
kPadAfterPrefix,
kPadBeforeSuffix,
kPadAfterSuffix
};
/**
* The positive prefix
*/
PluralAffix fPositivePrefix;
/**
* The positive suffix
*/
PluralAffix fPositiveSuffix;
/**
* The negative suffix
*/
PluralAffix fNegativePrefix;
/**
* The negative suffix
*/
PluralAffix fNegativeSuffix;
/**
* The padding position
*/
EPadPosition fPadPosition;
/**
* The padding character.
*/
UChar32 fPadChar;
/**
* The field width in code points. The format method inserts instances of
* the padding character as needed in the desired padding position so that
* the entire formatted string contains this many code points. If the
* formatted string already exceeds this many code points, the format method
* inserts no padding.
*/
int32_t fWidth;
/**
* Pad position is before prefix; padding character is '*' field width is 0.
* The affixes are all the empty string with no annotated fields with just
* the 'other' plural variation.
*/
DigitAffixesAndPadding()
: fPadPosition(kPadBeforePrefix), fPadChar(0x2a), fWidth(0) { }
/**
* Returns TRUE if this object is equal to rhs.
*/
UBool equals(const DigitAffixesAndPadding &rhs) const {
return (fPositivePrefix.equals(rhs.fPositivePrefix) &&
fPositiveSuffix.equals(rhs.fPositiveSuffix) &&
fNegativePrefix.equals(rhs.fNegativePrefix) &&
fNegativeSuffix.equals(rhs.fNegativeSuffix) &&
fPadPosition == rhs.fPadPosition &&
fWidth == rhs.fWidth &&
fPadChar == rhs.fPadChar);
}
/**
* Returns TRUE if a plural rules instance is needed to complete the
* formatting by detecting if any of the affixes have multiple plural
* variations.
*/
UBool needsPluralRules() const;
/**
* Formats value and appends to appendTo.
*
* @param value the value to format. May be NaN or ininite.
* @param formatter handles the details of formatting the actual value.
* @param handler records field positions
* @param optPluralRules the plural rules, but may be NULL if
* needsPluralRules returns FALSE.
* @appendTo formatted string appended here.
* @status any error returned here.
*/
UnicodeString &format(
const VisibleDigitsWithExponent &value,
const ValueFormatter &formatter,
FieldPositionHandler &handler,
const PluralRules *optPluralRules,
UnicodeString &appendTo,
UErrorCode &status) const;
/**
* For testing only.
*/
UnicodeString &format(
DigitList &value,
const ValueFormatter &formatter,
FieldPositionHandler &handler,
const PluralRules *optPluralRules,
UnicodeString &appendTo,
UErrorCode &status) const;
/**
* Formats a 32-bit integer and appends to appendTo. When formatting an
* integer, this method is preferred to plain format as it can run
* several times faster under certain conditions.
*
* @param value the value to format.
* @param formatter handles the details of formatting the actual value.
* @param handler records field positions
* @param optPluralRules the plural rules, but may be NULL if
* needsPluralRules returns FALSE.
* @appendTo formatted string appended here.
* @status any error returned here.
*/
UnicodeString &formatInt32(
int32_t value,
const ValueFormatter &formatter,
FieldPositionHandler &handler,
const PluralRules *optPluralRules,
UnicodeString &appendTo,
UErrorCode &status) const;
private:
UnicodeString &appendPadding(int32_t paddingCount, UnicodeString &appendTo) const;
};
U_NAMESPACE_END
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif // __DIGITAFFIXANDPADDING_H__
|