Line data Source code
1 : // © 2016 and later: Unicode, Inc. and others.
2 : // License & terms of use: http://www.unicode.org/copyright.html
3 : /*
4 : * Copyright (C) 2015, International Business Machines
5 : * Corporation and others. All Rights Reserved.
6 : *
7 : * file name: digitgrouping.cpp
8 : */
9 :
10 : #include "unicode/utypes.h"
11 :
12 : #include "digitgrouping.h"
13 : #include "smallintformatter.h"
14 :
15 : U_NAMESPACE_BEGIN
16 :
17 0 : UBool DigitGrouping::isSeparatorAt(
18 : int32_t digitsLeftOfDecimal, int32_t digitPos) const {
19 0 : if (!isGroupingEnabled(digitsLeftOfDecimal) || digitPos < fGrouping) {
20 0 : return FALSE;
21 : }
22 0 : return ((digitPos - fGrouping) % getGrouping2() == 0);
23 : }
24 :
25 0 : int32_t DigitGrouping::getSeparatorCount(int32_t digitsLeftOfDecimal) const {
26 0 : if (!isGroupingEnabled(digitsLeftOfDecimal)) {
27 0 : return 0;
28 : }
29 0 : return (digitsLeftOfDecimal - 1 - fGrouping) / getGrouping2() + 1;
30 : }
31 :
32 0 : UBool DigitGrouping::isGroupingEnabled(int32_t digitsLeftOfDecimal) const {
33 0 : return (isGroupingUsed()
34 0 : && digitsLeftOfDecimal >= fGrouping + getMinGrouping());
35 : }
36 :
37 0 : UBool DigitGrouping::isNoGrouping(
38 : int32_t positiveValue, const IntDigitCountRange &range) const {
39 0 : return getSeparatorCount(
40 0 : SmallIntFormatter::estimateDigitCount(positiveValue, range)) == 0;
41 : }
42 :
43 0 : int32_t DigitGrouping::getGrouping2() const {
44 0 : return (fGrouping2 > 0 ? fGrouping2 : fGrouping);
45 : }
46 :
47 0 : int32_t DigitGrouping::getMinGrouping() const {
48 0 : return (fMinGrouping > 0 ? fMinGrouping : 1);
49 : }
50 :
51 : void
52 0 : DigitGrouping::clear() {
53 0 : fMinGrouping = 0;
54 0 : fGrouping = 0;
55 0 : fGrouping2 = 0;
56 0 : }
57 :
58 : U_NAMESPACE_END
59 :
|