X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/common/ruleiter.cpp?ds=sidebyside diff --git a/icuSources/common/ruleiter.cpp b/icuSources/common/ruleiter.cpp index 30f136c0..667795ef 100644 --- a/icuSources/common/ruleiter.cpp +++ b/icuSources/common/ruleiter.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (c) 2003-2005, International Business Machines +* Copyright (c) 2003-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Author: Alan Liu @@ -10,9 +10,13 @@ */ #include "ruleiter.h" #include "unicode/parsepos.h" -#include "unicode/unistr.h" #include "unicode/symtable.h" -#include "util.h" +#include "unicode/unistr.h" +#include "unicode/utf16.h" +#include "patternprops.h" + +/* \U87654321 or \ud800\udc00 */ +#define MAX_U_NOTATION_LEN 12 U_NAMESPACE_BEGIN @@ -21,7 +25,8 @@ RuleCharacterIterator::RuleCharacterIterator(const UnicodeString& theText, const text(theText), pos(thePos), sym(theSym), - buf(0) + buf(0), + bufPos(0) {} UBool RuleCharacterIterator::atEnd() const { @@ -36,7 +41,7 @@ UChar32 RuleCharacterIterator::next(int32_t options, UBool& isEscaped, UErrorCod for (;;) { c = _current(); - _advance(UTF_CHAR_LENGTH(c)); + _advance(U16_LENGTH(c)); if (c == SymbolTable::SYMBOL_REF && buf == 0 && (options & PARSE_VARIABLES) != 0 && sym != 0) { @@ -59,15 +64,14 @@ UChar32 RuleCharacterIterator::next(int32_t options, UBool& isEscaped, UErrorCod continue; } - if ((options & SKIP_WHITESPACE) != 0 && - uprv_isRuleWhiteSpace(c)) { + if ((options & SKIP_WHITESPACE) != 0 && PatternProps::isWhiteSpace(c)) { continue; } if (c == 0x5C /*'\\'*/ && (options & PARSE_ESCAPES) != 0) { - UnicodeString s; + UnicodeString tempEscape; int32_t offset = 0; - c = lookahead(s).unescapeAt(offset); + c = lookahead(tempEscape, MAX_U_NOTATION_LEN).unescapeAt(offset); jumpahead(offset); isEscaped = TRUE; if (c < 0) { @@ -98,17 +102,20 @@ void RuleCharacterIterator::skipIgnored(int32_t options) { if ((options & SKIP_WHITESPACE) != 0) { for (;;) { UChar32 a = _current(); - if (!uprv_isRuleWhiteSpace(a)) break; - _advance(UTF_CHAR_LENGTH(a)); + if (!PatternProps::isWhiteSpace(a)) break; + _advance(U16_LENGTH(a)); } } } -UnicodeString& RuleCharacterIterator::lookahead(UnicodeString& result) const { +UnicodeString& RuleCharacterIterator::lookahead(UnicodeString& result, int32_t maxLookAhead) const { + if (maxLookAhead < 0) { + maxLookAhead = 0x7FFFFFFF; + } if (buf != 0) { - buf->extract(bufPos, 0x7FFFFFFF, result); + buf->extract(bufPos, maxLookAhead, result); } else { - text.extract(pos.getIndex(), 0x7FFFFFFF, result); + text.extract(pos.getIndex(), maxLookAhead, result); } return result; }