intl/icu/source/i18n/regeximp.cpp

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

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

mercurial