1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
10 * created on: 2015jan06
11 * created by: Travis Keep
14 #ifndef __SMALLINTFORMATTER_H__
15 #define __SMALLINTFORMATTER_H__
17 #include "unicode/uobject.h"
18 #include "unicode/utypes.h"
25 * A representation an acceptable range of digit counts for integers.
27 class U_I18N_API IntDigitCountRange : public UMemory {
30 * No constraints: 0 up to INT32_MAX
32 IntDigitCountRange() : fMin(0), fMax(INT32_MAX) { }
33 IntDigitCountRange(int32_t min, int32_t max);
34 int32_t pin(int32_t digitCount) const;
35 int32_t getMax() const { return fMax; }
36 int32_t getMin() const { return fMin; }
44 * A formatter for small, positive integers.
46 class U_I18N_API SmallIntFormatter : public UMemory {
49 * Estimates the actual digit count needed to format positiveValue
50 * using the given range of digit counts.
51 * Returns a value that is at least the actual digit count needed.
53 * @param positiveValue the value to format
54 * @param range the acceptable range of digit counts.
56 static int32_t estimateDigitCount(
57 int32_t positiveValue, const IntDigitCountRange &range);
60 * Returns TRUE if this class can format positiveValue using
61 * the given range of digit counts.
63 * @param positiveValue the value to format
64 * @param range the acceptable range of digit counts.
66 static UBool canFormat(
67 int32_t positiveValue, const IntDigitCountRange &range);
70 * Formats positiveValue using the given range of digit counts.
71 * Always uses standard digits '0' through '9'. Formatted value is
72 * left padded with '0' as necessary to achieve minimum digit count.
73 * Does not produce any grouping separators or trailing decimal point.
74 * Calling format to format a value with a particular digit count range
75 * when canFormat indicates that the same value and digit count range
76 * cannot be formatted results in undefined behavior.
78 * @param positiveValue the value to format
79 * @param range the acceptable range of digit counts.
81 static UnicodeString &format(
82 int32_t positiveValue,
83 const IntDigitCountRange &range,
84 UnicodeString &appendTo);
90 #endif // __SMALLINTFORMATTER_H__