Coverage Report

Created: 2023-03-29 06:15

/src/icu/icu4c/source/i18n/regeximp.cpp
Line
Count
Source (jump to first uncovered line)
1
// © 2016 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
//
4
//   Copyright (C) 2012 International Business Machines Corporation
5
//   and others. All rights reserved.
6
//
7
//   file:  regeximp.cpp
8
//
9
//           ICU Regular Expressions,
10
//             miscellaneous implementation functions.
11
//
12
13
#include "unicode/utypes.h"
14
15
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
16
#include "regeximp.h"
17
#include "unicode/utf16.h"
18
19
U_NAMESPACE_BEGIN
20
21
CaseFoldingUTextIterator::CaseFoldingUTextIterator(UText &text) :
22
0
   fUText(text), fFoldChars(nullptr), fFoldLength(0) {
23
0
}
24
25
0
CaseFoldingUTextIterator::~CaseFoldingUTextIterator() {}
26
27
0
UChar32 CaseFoldingUTextIterator::next() {
28
0
    UChar32  foldedC;
29
0
    UChar32  originalC;
30
0
    if (fFoldChars == nullptr) {
31
        // We are not in a string folding of an earlier character.
32
        // Start handling the next char from the input UText.
33
0
        originalC = UTEXT_NEXT32(&fUText);
34
0
        if (originalC == U_SENTINEL) {
35
0
            return originalC;
36
0
        }
37
0
        fFoldLength = ucase_toFullFolding(originalC, &fFoldChars, U_FOLD_CASE_DEFAULT);
38
0
        if (fFoldLength >= UCASE_MAX_STRING_LENGTH || fFoldLength < 0) {
39
            // input code point folds to a single code point, possibly itself.
40
            // See comment in ucase.h for explanation of return values from ucase_toFullFoldings.
41
0
            if (fFoldLength < 0) {
42
0
                fFoldLength = ~fFoldLength;
43
0
            }
44
0
            foldedC = (UChar32)fFoldLength;
45
0
            fFoldChars = nullptr;
46
0
            return foldedC;
47
0
        }
48
        // String foldings fall through here.
49
0
        fFoldIndex = 0;
50
0
    }
51
52
0
    U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC);
53
0
    if (fFoldIndex >= fFoldLength) {
54
0
        fFoldChars = nullptr;
55
0
    }
56
0
    return foldedC;
57
0
}
58
    
59
60
0
UBool CaseFoldingUTextIterator::inExpansion() {
61
0
    return fFoldChars != nullptr;
62
0
}
63
64
65
66
CaseFoldingUCharIterator::CaseFoldingUCharIterator(const char16_t *chars, int64_t start, int64_t limit) :
67
0
   fChars(chars), fIndex(start), fLimit(limit), fFoldChars(nullptr), fFoldLength(0) {
68
0
}
69
70
71
0
CaseFoldingUCharIterator::~CaseFoldingUCharIterator() {}
72
73
74
0
UChar32 CaseFoldingUCharIterator::next() {
75
0
    UChar32  foldedC;
76
0
    UChar32  originalC;
77
0
    if (fFoldChars == nullptr) {
78
        // We are not in a string folding of an earlier character.
79
        // Start handling the next char from the input UText.
80
0
        if (fIndex >= fLimit) {
81
0
            return U_SENTINEL;
82
0
        }
83
0
        U16_NEXT(fChars, fIndex, fLimit, originalC);
84
85
0
        fFoldLength = ucase_toFullFolding(originalC, &fFoldChars, U_FOLD_CASE_DEFAULT);
86
0
        if (fFoldLength >= UCASE_MAX_STRING_LENGTH || fFoldLength < 0) {
87
            // input code point folds to a single code point, possibly itself.
88
            // See comment in ucase.h for explanation of return values from ucase_toFullFoldings.
89
0
            if (fFoldLength < 0) {
90
0
                fFoldLength = ~fFoldLength;
91
0
            }
92
0
            foldedC = (UChar32)fFoldLength;
93
0
            fFoldChars = nullptr;
94
0
            return foldedC;
95
0
        }
96
        // String foldings fall through here.
97
0
        fFoldIndex = 0;
98
0
    }
99
100
0
    U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC);
101
0
    if (fFoldIndex >= fFoldLength) {
102
0
        fFoldChars = nullptr;
103
0
    }
104
0
    return foldedC;
105
0
}
106
    
107
108
0
UBool CaseFoldingUCharIterator::inExpansion() {
109
0
    return fFoldChars != nullptr;
110
0
}
111
112
0
int64_t CaseFoldingUCharIterator::getIndex() {
113
0
    return fIndex;
114
0
}
115
116
117
U_NAMESPACE_END
118
119
#endif
120