OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ******************************************************************************* |
| 3 * Copyright (C) 2015, International Business Machines |
| 4 * Corporation and others. All Rights Reserved. |
| 5 ******************************************************************************* |
| 6 * smallintformatter.h |
| 7 * |
| 8 * created on: 2015jan06 |
| 9 * created by: Travis Keep |
| 10 */ |
| 11 |
| 12 #ifndef __SMALLINTFORMATTER_H__ |
| 13 #define __SMALLINTFORMATTER_H__ |
| 14 |
| 15 #include "unicode/uobject.h" |
| 16 #include "unicode/utypes.h" |
| 17 |
| 18 U_NAMESPACE_BEGIN |
| 19 |
| 20 class UnicodeString; |
| 21 |
| 22 /** |
| 23 * A representation an acceptable range of digit counts for integers. |
| 24 */ |
| 25 class U_I18N_API IntDigitCountRange : public UMemory { |
| 26 public: |
| 27 /** |
| 28 * No constraints: 0 up to INT32_MAX |
| 29 */ |
| 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; } |
| 35 private: |
| 36 int32_t fMin; |
| 37 int32_t fMax; |
| 38 }; |
| 39 |
| 40 |
| 41 /** |
| 42 * A formatter for small, positive integers. |
| 43 */ |
| 44 class U_I18N_API SmallIntFormatter : public UMemory { |
| 45 public: |
| 46 /** |
| 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. |
| 50 * |
| 51 * @param positiveValue the value to format |
| 52 * @param range the acceptable range of digit counts. |
| 53 */ |
| 54 static int32_t estimateDigitCount( |
| 55 int32_t positiveValue, const IntDigitCountRange &range); |
| 56 |
| 57 /** |
| 58 * Returns TRUE if this class can format positiveValue using |
| 59 * the given range of digit counts. |
| 60 * |
| 61 * @param positiveValue the value to format |
| 62 * @param range the acceptable range of digit counts. |
| 63 */ |
| 64 static UBool canFormat( |
| 65 int32_t positiveValue, const IntDigitCountRange &range); |
| 66 |
| 67 /** |
| 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. |
| 75 * |
| 76 * @param positiveValue the value to format |
| 77 * @param range the acceptable range of digit counts. |
| 78 */ |
| 79 static UnicodeString &format( |
| 80 int32_t positiveValue, |
| 81 const IntDigitCountRange &range, |
| 82 UnicodeString &appendTo); |
| 83 |
| 84 }; |
| 85 |
| 86 U_NAMESPACE_END |
| 87 |
| 88 #endif // __SMALLINTFORMATTER_H__ |
OLD | NEW |