1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/regeximp.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 1.4 +// 1.5 +// Copyright (C) 2012 International Business Machines Corporation 1.6 +// and others. All rights reserved. 1.7 +// 1.8 +// file: regeximp.cpp 1.9 +// 1.10 +// ICU Regular Expressions, 1.11 +// miscellaneous implementation functions. 1.12 +// 1.13 + 1.14 +#include "unicode/utypes.h" 1.15 + 1.16 +#if !UCONFIG_NO_REGULAR_EXPRESSIONS 1.17 +#include "regeximp.h" 1.18 +#include "unicode/utf16.h" 1.19 + 1.20 +U_NAMESPACE_BEGIN 1.21 + 1.22 +CaseFoldingUTextIterator::CaseFoldingUTextIterator(UText &text) : 1.23 + fUText(text), fcsp(NULL), fFoldChars(NULL), fFoldLength(0) { 1.24 + fcsp = ucase_getSingleton(); 1.25 +} 1.26 + 1.27 +CaseFoldingUTextIterator::~CaseFoldingUTextIterator() {} 1.28 + 1.29 +UChar32 CaseFoldingUTextIterator::next() { 1.30 + UChar32 foldedC; 1.31 + UChar32 originalC; 1.32 + if (fFoldChars == NULL) { 1.33 + // We are not in a string folding of an earlier character. 1.34 + // Start handling the next char from the input UText. 1.35 + originalC = UTEXT_NEXT32(&fUText); 1.36 + if (originalC == U_SENTINEL) { 1.37 + return originalC; 1.38 + } 1.39 + fFoldLength = ucase_toFullFolding(fcsp, originalC, &fFoldChars, U_FOLD_CASE_DEFAULT); 1.40 + if (fFoldLength >= UCASE_MAX_STRING_LENGTH || fFoldLength < 0) { 1.41 + // input code point folds to a single code point, possibly itself. 1.42 + // See comment in ucase.h for explanation of return values from ucase_toFullFoldings. 1.43 + if (fFoldLength < 0) { 1.44 + fFoldLength = ~fFoldLength; 1.45 + } 1.46 + foldedC = (UChar32)fFoldLength; 1.47 + fFoldChars = NULL; 1.48 + return foldedC; 1.49 + } 1.50 + // String foldings fall through here. 1.51 + fFoldIndex = 0; 1.52 + } 1.53 + 1.54 + U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC); 1.55 + if (fFoldIndex >= fFoldLength) { 1.56 + fFoldChars = NULL; 1.57 + } 1.58 + return foldedC; 1.59 +} 1.60 + 1.61 + 1.62 +UBool CaseFoldingUTextIterator::inExpansion() { 1.63 + return fFoldChars != NULL; 1.64 +} 1.65 + 1.66 + 1.67 + 1.68 +CaseFoldingUCharIterator::CaseFoldingUCharIterator(const UChar *chars, int64_t start, int64_t limit) : 1.69 + fChars(chars), fIndex(start), fLimit(limit), fcsp(NULL), fFoldChars(NULL), fFoldLength(0) { 1.70 + fcsp = ucase_getSingleton(); 1.71 +} 1.72 + 1.73 + 1.74 +CaseFoldingUCharIterator::~CaseFoldingUCharIterator() {} 1.75 + 1.76 + 1.77 +UChar32 CaseFoldingUCharIterator::next() { 1.78 + UChar32 foldedC; 1.79 + UChar32 originalC; 1.80 + if (fFoldChars == NULL) { 1.81 + // We are not in a string folding of an earlier character. 1.82 + // Start handling the next char from the input UText. 1.83 + if (fIndex >= fLimit) { 1.84 + return U_SENTINEL; 1.85 + } 1.86 + U16_NEXT(fChars, fIndex, fLimit, originalC); 1.87 + 1.88 + fFoldLength = ucase_toFullFolding(fcsp, originalC, &fFoldChars, U_FOLD_CASE_DEFAULT); 1.89 + if (fFoldLength >= UCASE_MAX_STRING_LENGTH || fFoldLength < 0) { 1.90 + // input code point folds to a single code point, possibly itself. 1.91 + // See comment in ucase.h for explanation of return values from ucase_toFullFoldings. 1.92 + if (fFoldLength < 0) { 1.93 + fFoldLength = ~fFoldLength; 1.94 + } 1.95 + foldedC = (UChar32)fFoldLength; 1.96 + fFoldChars = NULL; 1.97 + return foldedC; 1.98 + } 1.99 + // String foldings fall through here. 1.100 + fFoldIndex = 0; 1.101 + } 1.102 + 1.103 + U16_NEXT(fFoldChars, fFoldIndex, fFoldLength, foldedC); 1.104 + if (fFoldIndex >= fFoldLength) { 1.105 + fFoldChars = NULL; 1.106 + } 1.107 + return foldedC; 1.108 +} 1.109 + 1.110 + 1.111 +UBool CaseFoldingUCharIterator::inExpansion() { 1.112 + return fFoldChars != NULL; 1.113 +} 1.114 + 1.115 +int64_t CaseFoldingUCharIterator::getIndex() { 1.116 + return fIndex; 1.117 +} 1.118 + 1.119 + 1.120 +U_NAMESPACE_END 1.121 + 1.122 +#endif 1.123 +