]>
git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/regeximp.cpp
2 // Copyright (C) 2012 International Business Machines Corporation
3 // and others. All rights reserved.
7 // ICU Regular Expressions,
8 // miscellaneous implementation functions.
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_REGULAR_EXPRESSIONS
15 #include "unicode/utf16.h"
19 CaseFoldingUTextIterator::CaseFoldingUTextIterator(UText
&text
) :
20 fUText(text
), fcsp(NULL
), fFoldChars(NULL
), fFoldLength(0) {
21 fcsp
= ucase_getSingleton();
24 CaseFoldingUTextIterator::~CaseFoldingUTextIterator() {}
26 UChar32
CaseFoldingUTextIterator::next() {
29 if (fFoldChars
== NULL
) {
30 // We are not in a string folding of an earlier character.
31 // Start handling the next char from the input UText.
32 originalC
= UTEXT_NEXT32(&fUText
);
33 if (originalC
== U_SENTINEL
) {
36 fFoldLength
= ucase_toFullFolding(fcsp
, originalC
, &fFoldChars
, U_FOLD_CASE_DEFAULT
);
37 if (fFoldLength
>= UCASE_MAX_STRING_LENGTH
|| fFoldLength
< 0) {
38 // input code point folds to a single code point, possibly itself.
39 // See comment in ucase.h for explanation of return values from ucase_toFullFoldings.
40 if (fFoldLength
< 0) {
41 fFoldLength
= ~fFoldLength
;
43 foldedC
= (UChar32
)fFoldLength
;
47 // String foldings fall through here.
51 U16_NEXT(fFoldChars
, fFoldIndex
, fFoldLength
, foldedC
);
52 if (fFoldIndex
>= fFoldLength
) {
59 UBool
CaseFoldingUTextIterator::inExpansion() {
60 return fFoldChars
!= NULL
;
65 CaseFoldingUCharIterator::CaseFoldingUCharIterator(const UChar
*chars
, int64_t start
, int64_t limit
) :
66 fChars(chars
), fIndex(start
), fLimit(limit
), fcsp(NULL
), fFoldChars(NULL
), fFoldLength(0) {
67 fcsp
= ucase_getSingleton();
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(fcsp
, 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() {