diff --git a/icu4c/source/common/rbbi.cpp b/icu4c/source/common/rbbi.cpp index 9b7d5fd73cd..41d242fff9c 100644 --- a/icu4c/source/common/rbbi.cpp +++ b/icu4c/source/common/rbbi.cpp @@ -1,6 +1,6 @@ /* *************************************************************************** -* Copyright (C) 1999-2006 International Business Machines Corporation * +* Copyright (C) 1999-2007 International Business Machines Corporation * * and others. All rights reserved. * *************************************************************************** */ @@ -1034,7 +1034,7 @@ int32_t RuleBasedBreakIterator::handleNext(const RBBIStateTable *statetable) { lookaheadStatus = 0; // TODO: make a standalone hard break in a rule work. if (lookAheadHardBreak) { - utext_setNativeIndex(fText, result); + UTEXT_SETNATIVEINDEX(fText, result); return result; } // Look-ahead completed, but other rules may match further. Continue on @@ -1085,13 +1085,13 @@ continueOn: // (This really indicates a defect in the break rules. They should always match // at least one character.) if (result == initialPosition) { - utext_setNativeIndex(fText, initialPosition); + UTEXT_SETNATIVEINDEX(fText, initialPosition); UTEXT_NEXT32(fText); result = (int32_t)UTEXT_GETNATIVEINDEX(fText); } // Leave the iterator at our result position. - utext_setNativeIndex(fText, result); + UTEXT_SETNATIVEINDEX(fText, result); #ifdef RBBI_DEBUG if (fTrace) { RBBIDebugPrintf("result = %d\n\n", result); @@ -1179,7 +1179,7 @@ int32_t RuleBasedBreakIterator::handlePrevious(const RBBIStateTable *statetable) } else if (result == initialPosition) { // Ran off start, no match found. // move one index one (towards the start, since we are doing a previous()) - utext_setNativeIndex(fText, initialPosition); + UTEXT_SETNATIVEINDEX(fText, initialPosition); UTEXT_PREVIOUS32(fText); // TODO: shouldn't be necessary. We're already at beginning. Check. } break; @@ -1245,7 +1245,7 @@ int32_t RuleBasedBreakIterator::handlePrevious(const RBBIStateTable *statetable) lookaheadStatus = 0; // TODO: make a standalone hard break in a rule work. if (lookAheadHardBreak) { - utext_setNativeIndex(fText, result); + UTEXT_SETNATIVEINDEX(fText, result); return result; } // Look-ahead completed, but other rules may match further. Continue on @@ -1293,13 +1293,13 @@ continueOn: // (This really indicates a defect in the break rules. They should always match // at least one character.) if (result == initialPosition) { - utext_setNativeIndex(fText, initialPosition); + UTEXT_SETNATIVEINDEX(fText, initialPosition); UTEXT_PREVIOUS32(fText); result = (int32_t)UTEXT_GETNATIVEINDEX(fText); } // Leave the iterator at our result position. - utext_setNativeIndex(fText, result); + UTEXT_SETNATIVEINDEX(fText, result); #ifdef RBBI_DEBUG if (fTrace) { RBBIDebugPrintf("result = %d\n\n", result); diff --git a/icu4c/source/common/unicode/utext.h b/icu4c/source/common/unicode/utext.h index 170ccfd30bb..57ac909ca17 100644 --- a/icu4c/source/common/unicode/utext.h +++ b/icu4c/source/common/unicode/utext.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2004-2006, International Business Machines +* Copyright (C) 2004-2007, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -718,6 +718,23 @@ utext_extract(UText *ut, (ut)->chunkNativeStart+(ut)->chunkOffset : \ (ut)->pFuncs->mapOffsetToNative(ut)) +/** + * inline version of utext_setNativeIndex(), for performance-critical situations. + * + * Set the current iteration position to the nearest code point + * boundary at or preceding the specified index. + * The index is in the native units of the original input text. + * If the index is out of range, it will be pinned to be within + * the range of the input text. + * + * @draft ICU 3.8 + */ +#define UTEXT_SETNATIVEINDEX(ut, ix) \ + { int64_t __offset = (ix) - (ut)->chunkNativeStart; \ + if (__offset>=0 && __offset<=(int64_t)(ut)->nativeIndexingLimit) { \ + (ut)->chunkOffset=(int32_t)__offset; \ + } else { \ + utext_setNativeIndex((ut), (ix)); } }