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: digitinterval.cpp
8 : */
9 :
10 : #include "unicode/utypes.h"
11 :
12 : #include "digitinterval.h"
13 :
14 : U_NAMESPACE_BEGIN
15 :
16 0 : void DigitInterval::expandToContain(const DigitInterval &rhs) {
17 0 : if (fSmallestInclusive > rhs.fSmallestInclusive) {
18 0 : fSmallestInclusive = rhs.fSmallestInclusive;
19 : }
20 0 : if (fLargestExclusive < rhs.fLargestExclusive) {
21 0 : fLargestExclusive = rhs.fLargestExclusive;
22 : }
23 0 : }
24 :
25 0 : void DigitInterval::shrinkToFitWithin(const DigitInterval &rhs) {
26 0 : if (fSmallestInclusive < rhs.fSmallestInclusive) {
27 0 : fSmallestInclusive = rhs.fSmallestInclusive;
28 : }
29 0 : if (fLargestExclusive > rhs.fLargestExclusive) {
30 0 : fLargestExclusive = rhs.fLargestExclusive;
31 : }
32 0 : }
33 :
34 0 : void DigitInterval::setIntDigitCount(int32_t count) {
35 0 : fLargestExclusive = count < 0 ? INT32_MAX : count;
36 0 : }
37 :
38 0 : void DigitInterval::setFracDigitCount(int32_t count) {
39 0 : fSmallestInclusive = count < 0 ? INT32_MIN : -count;
40 0 : }
41 :
42 0 : void DigitInterval::expandToContainDigit(int32_t digitExponent) {
43 0 : if (fLargestExclusive <= digitExponent) {
44 0 : fLargestExclusive = digitExponent + 1;
45 0 : } else if (fSmallestInclusive > digitExponent) {
46 0 : fSmallestInclusive = digitExponent;
47 : }
48 0 : }
49 :
50 0 : UBool DigitInterval::contains(int32_t x) const {
51 0 : return (x < fLargestExclusive && x >= fSmallestInclusive);
52 : }
53 :
54 :
55 : U_NAMESPACE_END
56 :
|