1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 // Copyright (C) 2012 International Business Machines Corporation
5 // and others. All rights reserved.
9 // ICU Regular Expressions,
10 // miscellaneous implementation functions.
13 #include "unicode/utypes.h"
15 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
17 #include "unicode/utf16.h"
21 CaseFoldingUTextIterator::CaseFoldingUTextIterator(UText &text) :
22 fUText(text), fcsp(NULL), fFoldChars(NULL), fFoldLength(0) {
23 fcsp = ucase_getSingleton();
26 CaseFoldingUTextIterator::~CaseFoldingUTextIterator() {}
28 UChar32 CaseFoldingUTextIterator::next() {
31 if (fFoldChars == NULL) {
32 // We are not in a string folding of an earlier character.
33 // Start handling the next char from the input UText.
34 originalC = UTEXT_NEXT32(&fUText);
35 if (originalC == U_SENTINEL) {
38 fFoldLength = ucase_toFullFolding(fcsp, originalC, &fFoldChars, U_FOLD_CASE_DEFAULT);
39 if (fFoldLength >= UCASE_MAX_STRING_LENGTH || fFoldLength < 0) {
40 // input code point folds to a single code point, possibly itself.
41 // See comment in ucase.h for explanation of return values from ucase_toFullFoldings.
42 if (fFoldLength < 0) {
43 fFoldLength = ~fFoldLength;
45 foldedC = (UChar32)fFoldLength;
49 // String foldings fall through here.
53 U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC);
54 if (fFoldIndex >= fFoldLength) {
61 UBool CaseFoldingUTextIterator::inExpansion() {
62 return fFoldChars != NULL;
67 CaseFoldingUCharIterator::CaseFoldingUCharIterator(const UChar *chars, int64_t start, int64_t limit) :
68 fChars(chars), fIndex(start), fLimit(limit), fcsp(NULL), fFoldChars(NULL), fFoldLength(0) {
69 fcsp = ucase_getSingleton();
73 CaseFoldingUCharIterator::~CaseFoldingUCharIterator() {}
76 UChar32 CaseFoldingUCharIterator::next() {
79 if (fFoldChars == NULL) {
80 // We are not in a string folding of an earlier character.
81 // Start handling the next char from the input UText.
82 if (fIndex >= fLimit) {
85 U16_NEXT(fChars, fIndex, fLimit, originalC);
87 fFoldLength = ucase_toFullFolding(fcsp, originalC, &fFoldChars, U_FOLD_CASE_DEFAULT);
88 if (fFoldLength >= UCASE_MAX_STRING_LENGTH || fFoldLength < 0) {
89 // input code point folds to a single code point, possibly itself.
90 // See comment in ucase.h for explanation of return values from ucase_toFullFoldings.
91 if (fFoldLength < 0) {
92 fFoldLength = ~fFoldLength;
94 foldedC = (UChar32)fFoldLength;
98 // String foldings fall through here.
102 U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC);
103 if (fFoldIndex >= fFoldLength) {
110 UBool CaseFoldingUCharIterator::inExpansion() {
111 return fFoldChars != NULL;
114 int64_t CaseFoldingUCharIterator::getIndex() {