]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/regeximp.cpp
1 // © 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
), fFoldChars(NULL
), fFoldLength(0) {
25 CaseFoldingUTextIterator::~CaseFoldingUTextIterator() {}
27 UChar32
CaseFoldingUTextIterator::next() {
30 if (fFoldChars
== NULL
) {
31 // We are not in a string folding of an earlier character.
32 // Start handling the next char from the input UText.
33 originalC
= UTEXT_NEXT32(&fUText
);
34 if (originalC
== U_SENTINEL
) {
37 fFoldLength
= ucase_toFullFolding(originalC
, &fFoldChars
, U_FOLD_CASE_DEFAULT
);
38 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 if (fFoldLength
< 0) {
42 fFoldLength
= ~fFoldLength
;
44 foldedC
= (UChar32
)fFoldLength
;
48 // String foldings fall through here.
52 U16_NEXT(fFoldChars
, fFoldIndex
, fFoldLength
, foldedC
);
53 if (fFoldIndex
>= fFoldLength
) {
60 UBool
CaseFoldingUTextIterator::inExpansion() {
61 return fFoldChars
!= NULL
;
66 CaseFoldingUCharIterator::CaseFoldingUCharIterator(const UChar
*chars
, int64_t start
, int64_t limit
) :
67 fChars(chars
), fIndex(start
), fLimit(limit
), fFoldChars(NULL
), fFoldLength(0) {
71 CaseFoldingUCharIterator::~CaseFoldingUCharIterator() {}
74 UChar32
CaseFoldingUCharIterator::next() {
77 if (fFoldChars
== NULL
) {
78 // We are not in a string folding of an earlier character.
79 // Start handling the next char from the input UText.
80 if (fIndex
>= fLimit
) {
83 U16_NEXT(fChars
, fIndex
, fLimit
, originalC
);
85 fFoldLength
= ucase_toFullFolding(originalC
, &fFoldChars
, U_FOLD_CASE_DEFAULT
);
86 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 if (fFoldLength
< 0) {
90 fFoldLength
= ~fFoldLength
;
92 foldedC
= (UChar32
)fFoldLength
;
96 // String foldings fall through here.
100 U16_NEXT(fFoldChars
, fFoldIndex
, fFoldLength
, foldedC
);
101 if (fFoldIndex
>= fFoldLength
) {
108 UBool
CaseFoldingUCharIterator::inExpansion() {
109 return fFoldChars
!= NULL
;
112 int64_t CaseFoldingUCharIterator::getIndex() {