]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/digitinterval.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 * Copyright (C) 2015, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 * file name: digitinterval.cpp
10 #include "unicode/utypes.h"
12 #include "digitinterval.h"
16 void DigitInterval::expandToContain(const DigitInterval
&rhs
) {
17 if (fSmallestInclusive
> rhs
.fSmallestInclusive
) {
18 fSmallestInclusive
= rhs
.fSmallestInclusive
;
20 if (fLargestExclusive
< rhs
.fLargestExclusive
) {
21 fLargestExclusive
= rhs
.fLargestExclusive
;
25 void DigitInterval::shrinkToFitWithin(const DigitInterval
&rhs
) {
26 if (fSmallestInclusive
< rhs
.fSmallestInclusive
) {
27 fSmallestInclusive
= rhs
.fSmallestInclusive
;
29 if (fLargestExclusive
> rhs
.fLargestExclusive
) {
30 fLargestExclusive
= rhs
.fLargestExclusive
;
34 void DigitInterval::setIntDigitCount(int32_t count
) {
35 fLargestExclusive
= count
< 0 ? INT32_MAX
: count
;
38 void DigitInterval::setFracDigitCount(int32_t count
) {
39 fSmallestInclusive
= count
< 0 ? INT32_MIN
: -count
;
42 void DigitInterval::expandToContainDigit(int32_t digitExponent
) {
43 if (fLargestExclusive
<= digitExponent
) {
44 fLargestExclusive
= digitExponent
+ 1;
45 } else if (fSmallestInclusive
> digitExponent
) {
46 fSmallestInclusive
= digitExponent
;
50 UBool
DigitInterval::contains(int32_t x
) const {
51 return (x
< fLargestExclusive
&& x
>= fSmallestInclusive
);