]> git.saurik.com Git - apple/icu.git/blame - icuSources/i18n/digitinterval.cpp
ICU-62107.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / digitinterval.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
2ca993e8
A
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
14U_NAMESPACE_BEGIN
15
16void 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
25void 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
34void DigitInterval::setIntDigitCount(int32_t count) {
35 fLargestExclusive = count < 0 ? INT32_MAX : count;
36}
37
38void DigitInterval::setFracDigitCount(int32_t count) {
39 fSmallestInclusive = count < 0 ? INT32_MIN : -count;
40}
41
42void DigitInterval::expandToContainDigit(int32_t digitExponent) {
43 if (fLargestExclusive <= digitExponent) {
44 fLargestExclusive = digitExponent + 1;
45 } else if (fSmallestInclusive > digitExponent) {
46 fSmallestInclusive = digitExponent;
47 }
48}
49
50UBool DigitInterval::contains(int32_t x) const {
51 return (x < fLargestExclusive && x >= fSmallestInclusive);
52}
53
54
55U_NAMESPACE_END
56