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