2 *******************************************************************************
3 * Copyright (C) 2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
8 * created on: 2015jan06
9 * created by: Travis Keep
12 #ifndef __SMALLINTFORMATTER_H__
13 #define __SMALLINTFORMATTER_H__
15 #include "unicode/uobject.h"
16 #include "unicode/utypes.h"
23 * A representation an acceptable range of digit counts for integers.
25 class U_I18N_API IntDigitCountRange
: public UMemory
{
28 * No constraints: 0 up to INT32_MAX
30 IntDigitCountRange() : fMin(0), fMax(INT32_MAX
) { }
31 IntDigitCountRange(int32_t min
, int32_t max
);
32 int32_t pin(int32_t digitCount
) const;
33 int32_t getMax() const { return fMax
; }
34 int32_t getMin() const { return fMin
; }
42 * A formatter for small, positive integers.
44 class U_I18N_API SmallIntFormatter
: public UMemory
{
47 * Estimates the actual digit count needed to format positiveValue
48 * using the given range of digit counts.
49 * Returns a value that is at least the actual digit count needed.
51 * @param positiveValue the value to format
52 * @param range the acceptable range of digit counts.
54 static int32_t estimateDigitCount(
55 int32_t positiveValue
, const IntDigitCountRange
&range
);
58 * Returns TRUE if this class can format positiveValue using
59 * the given range of digit counts.
61 * @param positiveValue the value to format
62 * @param range the acceptable range of digit counts.
64 static UBool
canFormat(
65 int32_t positiveValue
, const IntDigitCountRange
&range
);
68 * Formats positiveValue using the given range of digit counts.
69 * Always uses standard digits '0' through '9'. Formatted value is
70 * left padded with '0' as necessary to achieve minimum digit count.
71 * Does not produce any grouping separators or trailing decimal point.
72 * Calling format to format a value with a particular digit count range
73 * when canFormat indicates that the same value and digit count range
74 * cannot be formatted results in undefined behavior.
76 * @param positiveValue the value to format
77 * @param range the acceptable range of digit counts.
79 static UnicodeString
&format(
80 int32_t positiveValue
,
81 const IntDigitCountRange
&range
,
82 UnicodeString
&appendTo
);
88 #endif // __SMALLINTFORMATTER_H__