]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/digitinterval.cpp
ICU-62109.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / digitinterval.cpp
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 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
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
34 void DigitInterval::setIntDigitCount(int32_t count) {
35 fLargestExclusive = count < 0 ? INT32_MAX : count;
36 }
37
38 void DigitInterval::setFracDigitCount(int32_t count) {
39 fSmallestInclusive = count < 0 ? INT32_MIN : -count;
40 }
41
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
50 UBool DigitInterval::contains(int32_t x) const {
51 return (x < fLargestExclusive && x >= fSmallestInclusive);
52 }
53
54
55 U_NAMESPACE_END
56