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: 2015jan6
11 * created by: Travis Keep
14 #ifndef __DIGITGROUPING_H__
15 #define __DIGITGROUPING_H__
17 #include "unicode/uobject.h"
18 #include "unicode/utypes.h"
22 class IntDigitCountRange;
25 * The digit grouping policy.
27 class U_I18N_API DigitGrouping : public UMemory {
30 * Default is no digit grouping.
32 DigitGrouping() : fGrouping(0), fGrouping2(0), fMinGrouping(0) { }
35 * Returns TRUE if this object is equal to rhs.
37 UBool equals(const DigitGrouping &rhs) const {
38 return ((fGrouping == rhs.fGrouping) &&
39 (fGrouping2 == rhs.fGrouping2) &&
40 (fMinGrouping == rhs.fMinGrouping));
44 * Returns true if a separator is needed after a particular digit.
45 * @param digitsLeftOfDecimal the total count of digits left of the
47 * @param digitPos 0 is the one's place; 1 is the 10's place; -1 is the
50 UBool isSeparatorAt(int32_t digitsLeftOfDecimal, int32_t digitPos) const;
53 * Returns the total number of separators to be used to format a particular
55 * @param digitsLeftOfDecimal the total number of digits to the left of
58 int32_t getSeparatorCount(int32_t digitsLeftOfDecimal) const;
61 * Returns true if grouping is used FALSE otherwise. When
62 * isGroupingUsed() returns FALSE; isSeparatorAt always returns FALSE
63 * and getSeparatorCount always returns 0.
65 UBool isGroupingUsed() const { return fGrouping > 0; }
68 * Returns TRUE if this instance would not add grouping separators
69 * when formatting value using the given constraint on digit count.
71 * @param value the value to format.
72 * @param range the minimum and maximum digits for formatting value.
75 int32_t positiveValue, const IntDigitCountRange &range) const;
78 * Clears this instance so that digit grouping is not in effect.
85 * Primary grouping size. A value of 0, the default, or a negative
86 * number causes isGroupingUsed() to return FALSE.
91 * Secondary grouping size. If > 0, this size is used instead of
92 * 'fGrouping' for all but the group just to the left of the decimal
93 * point. The default value of 0, or a negative value indicates that
94 * there is no secondary grouping size.
99 * If set (that is > 0), uses no grouping separators if fewer than
100 * (fGrouping + fMinGrouping) digits appear left of the decimal place.
101 * The default value for this field is 0.
103 int32_t fMinGrouping;
105 UBool isGroupingEnabled(int32_t digitsLeftOfDecimal) const;
106 int32_t getGrouping2() const;
107 int32_t getMinGrouping() const;
112 #endif // __DIGITGROUPING_H__