• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 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 
isSeparatorAt(int32_t digitsLeftOfDecimal,int32_t digitPos) const17 UBool DigitGrouping::isSeparatorAt(
18         int32_t digitsLeftOfDecimal, int32_t digitPos) const {
19     if (!isGroupingEnabled(digitsLeftOfDecimal) || digitPos < fGrouping) {
20         return FALSE;
21     }
22     return ((digitPos - fGrouping) % getGrouping2() == 0);
23 }
24 
getSeparatorCount(int32_t digitsLeftOfDecimal) const25 int32_t DigitGrouping::getSeparatorCount(int32_t digitsLeftOfDecimal) const {
26     if (!isGroupingEnabled(digitsLeftOfDecimal)) {
27         return 0;
28     }
29     return (digitsLeftOfDecimal - 1 - fGrouping) / getGrouping2() + 1;
30 }
31 
isGroupingEnabled(int32_t digitsLeftOfDecimal) const32 UBool DigitGrouping::isGroupingEnabled(int32_t digitsLeftOfDecimal) const {
33     return (isGroupingUsed()
34             && digitsLeftOfDecimal >= fGrouping + getMinGrouping());
35 }
36 
isNoGrouping(int32_t positiveValue,const IntDigitCountRange & range) const37 UBool DigitGrouping::isNoGrouping(
38         int32_t positiveValue, const IntDigitCountRange &range) const {
39     return getSeparatorCount(
40             SmallIntFormatter::estimateDigitCount(positiveValue, range)) == 0;
41 }
42 
getGrouping2() const43 int32_t DigitGrouping::getGrouping2() const {
44     return (fGrouping2 > 0 ? fGrouping2 : fGrouping);
45 }
46 
getMinGrouping() const47 int32_t DigitGrouping::getMinGrouping() const {
48     return (fMinGrouping > 0 ? fMinGrouping : 1);
49 }
50 
51 void
clear()52 DigitGrouping::clear() {
53     fMinGrouping = 0;
54     fGrouping = 0;
55     fGrouping2 = 0;
56 }
57 
58 U_NAMESPACE_END
59 
60