summaryrefslogtreecommitdiffstats
path: root/intl/icu/source/i18n/digitinterval.cpp
blob: 94dca9c950757dfd33ac85ab3e4edd8e4a7a05fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
 * Copyright (C) 2015, International Business Machines
 * Corporation and others.  All Rights Reserved.
 *
 * file name: digitinterval.cpp
 */

#include "unicode/utypes.h"

#include "digitinterval.h"

U_NAMESPACE_BEGIN

void DigitInterval::expandToContain(const DigitInterval &rhs) {
    if (fSmallestInclusive > rhs.fSmallestInclusive) {
        fSmallestInclusive = rhs.fSmallestInclusive;
    }
    if (fLargestExclusive < rhs.fLargestExclusive) {
        fLargestExclusive = rhs.fLargestExclusive;
    }
}

void DigitInterval::shrinkToFitWithin(const DigitInterval &rhs) {
    if (fSmallestInclusive < rhs.fSmallestInclusive) {
        fSmallestInclusive = rhs.fSmallestInclusive;
    }
    if (fLargestExclusive > rhs.fLargestExclusive) {
        fLargestExclusive = rhs.fLargestExclusive;
    }
}

void DigitInterval::setIntDigitCount(int32_t count) {
    fLargestExclusive = count < 0 ? INT32_MAX : count;
}

void DigitInterval::setFracDigitCount(int32_t count) {
    fSmallestInclusive = count < 0 ? INT32_MIN : -count;
}

void DigitInterval::expandToContainDigit(int32_t digitExponent) {
  if (fLargestExclusive <= digitExponent) {
      fLargestExclusive = digitExponent + 1;
  } else if (fSmallestInclusive > digitExponent) {
      fSmallestInclusive = digitExponent;
  }
}

UBool DigitInterval::contains(int32_t x) const {
    return (x < fLargestExclusive && x >= fSmallestInclusive);
}


U_NAMESPACE_END