1 /* 2 * Copyright (C) 2015, International Business Machines 3 * Corporation and others. All Rights Reserved. 4 * 5 * file name: digitinterval.cpp 6 */ 7 8 #include "unicode/utypes.h" 9 10 #include "digitinterval.h" 11 12 U_NAMESPACE_BEGIN 13 expandToContain(const DigitInterval & rhs)14void DigitInterval::expandToContain(const DigitInterval &rhs) { 15 if (fSmallestInclusive > rhs.fSmallestInclusive) { 16 fSmallestInclusive = rhs.fSmallestInclusive; 17 } 18 if (fLargestExclusive < rhs.fLargestExclusive) { 19 fLargestExclusive = rhs.fLargestExclusive; 20 } 21 } 22 shrinkToFitWithin(const DigitInterval & rhs)23void DigitInterval::shrinkToFitWithin(const DigitInterval &rhs) { 24 if (fSmallestInclusive < rhs.fSmallestInclusive) { 25 fSmallestInclusive = rhs.fSmallestInclusive; 26 } 27 if (fLargestExclusive > rhs.fLargestExclusive) { 28 fLargestExclusive = rhs.fLargestExclusive; 29 } 30 } 31 setIntDigitCount(int32_t count)32void DigitInterval::setIntDigitCount(int32_t count) { 33 fLargestExclusive = count < 0 ? INT32_MAX : count; 34 } 35 setFracDigitCount(int32_t count)36void DigitInterval::setFracDigitCount(int32_t count) { 37 fSmallestInclusive = count < 0 ? INT32_MIN : -count; 38 } 39 expandToContainDigit(int32_t digitExponent)40void DigitInterval::expandToContainDigit(int32_t digitExponent) { 41 if (fLargestExclusive <= digitExponent) { 42 fLargestExclusive = digitExponent + 1; 43 } else if (fSmallestInclusive > digitExponent) { 44 fSmallestInclusive = digitExponent; 45 } 46 } 47 contains(int32_t x) const48UBool DigitInterval::contains(int32_t x) const { 49 return (x < fLargestExclusive && x >= fSmallestInclusive); 50 } 51 52 53 U_NAMESPACE_END 54 55