mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-1560 sync with Java
X-SVN-Rev: 7199
This commit is contained in:
parent
532c799c63
commit
54d8e90e03
3 changed files with 55 additions and 19 deletions
|
@ -438,8 +438,25 @@ void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPositi
|
|||
index.start = compoundStart; // Reset start
|
||||
int32_t limit = index.limit;
|
||||
|
||||
if (index.start == index.limit) {
|
||||
// Short circuit for empty range
|
||||
break;
|
||||
}
|
||||
|
||||
trans[i]->filteredTransliterate(text, index, incremental);
|
||||
|
||||
// In a properly written transliterator, start == limit after
|
||||
// handleTransliterate() returns when incremental is false.
|
||||
// Catch cases where the subclass doesn't do this, and throw
|
||||
// an exception. (Just pinning start to limit is a bad idea,
|
||||
// because what's probably happening is that the subclass
|
||||
// isn't transliterating all the way to the end, and it should
|
||||
// in non-incremental mode.)
|
||||
if (!incremental && index.start != index.limit) {
|
||||
// We can't throw an exception, so just fudge things
|
||||
index.start = index.limit;
|
||||
}
|
||||
|
||||
// Cumulative delta for insertions/deletions
|
||||
delta += index.limit - limit;
|
||||
|
||||
|
|
|
@ -614,6 +614,9 @@ void Transliterator::filteredTransliterate(Replaceable& text,
|
|||
|
||||
// Delete the rollback copy
|
||||
text.handleReplaceBetween(rollbackOrigin, rollbackOrigin + runLength, EMPTY);
|
||||
|
||||
// Move start past committed text
|
||||
index.start = passStart;
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -622,15 +625,25 @@ void Transliterator::filteredTransliterate(Replaceable& text,
|
|||
handleTransliterate(text, index, isIncrementalRun);
|
||||
delta = index.limit - limit; // change in length
|
||||
|
||||
// In a properly written transliterator, start == limit after
|
||||
// handleTransliterate() returns when incremental is false.
|
||||
// Catch cases where the subclass doesn't do this, and throw
|
||||
// an exception. (Just pinning start to limit is a bad idea,
|
||||
// because what's probably happening is that the subclass
|
||||
// isn't transliterating all the way to the end, and it should
|
||||
// in non-incremental mode.)
|
||||
if (!incremental && index.start != index.limit) {
|
||||
// We can't throw an exception, so just fudge things
|
||||
index.start = index.limit;
|
||||
}
|
||||
|
||||
// Adjust overall limit for insertions/deletions. Don't need
|
||||
// to worry about contextLimit because handleTransliterate()
|
||||
// maintains that.
|
||||
globalLimit += delta;
|
||||
}
|
||||
|
||||
// If we failed to complete transliterate this run,
|
||||
// then we are done.
|
||||
if (index.start != index.limit) {
|
||||
if (filter == NULL || isIncrementalRun) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -555,40 +555,46 @@ protected:
|
|||
/**
|
||||
* Abstract method that concrete subclasses define to implement
|
||||
* keyboard transliteration. This method should transliterate all
|
||||
* characters between <code>index.cursor</code> and
|
||||
* <code>index.limit</code> that can be unambiguously
|
||||
* characters between <code>pos.start</code> and
|
||||
* <code>pos.contextLimit</code> that can be unambiguously
|
||||
* transliterated, regardless of future insertions of text at
|
||||
* <code>index.limit</code>. <code>index.cursor</code> should
|
||||
* <code>pos.contextLimit</code>. <code>pos.start</code> should
|
||||
* be advanced past committed characters (those that will not
|
||||
* change in future calls to this method).
|
||||
* <code>index.limit</code> should be updated to reflect text
|
||||
* <code>pos.contextLimit</code> should be updated to reflect text
|
||||
* replacements that shorten or lengthen the text between
|
||||
* <code>index.cursor</code> and <code>index.limit</code>. Upon
|
||||
* return, neither <code>index.cursor</code> nor
|
||||
* <code>index.limit</code> should be less than the initial value
|
||||
* of <code>index.cursor</code>. <code>index.start</code>
|
||||
* <code>pos.start</code> and <code>pos.contextLimit</code>. Upon
|
||||
* return, neither <code>pos.start</code> nor
|
||||
* <code>pos.contextLimit</code> should be less than the initial value
|
||||
* of <code>pos.start</code>. <code>pos.contextStart</code>
|
||||
* should <em>not</em> be changed.
|
||||
*
|
||||
* <p>Subclasses may safely assume that all characters in
|
||||
* [index.start, index.limit) are unfiltered. In other words, the
|
||||
* [pos.start, pos.limit) are unfiltered. In other words, the
|
||||
* filter has already been applied by the time this method is
|
||||
* called. See filteredTransliterate().
|
||||
*
|
||||
* <p>This method is <b>not</b> for public consumption. Calling
|
||||
* this method directly will transliterate [index.start,
|
||||
* index.limit) without applying the filter. End user code that
|
||||
* this method directly will transliterate [pos.start,
|
||||
* pos.limit) without applying the filter. End user code that
|
||||
* wants to call this method should be calling transliterate().
|
||||
* Subclass code that wants to call this method should probably be
|
||||
* calling filteredTransliterate().
|
||||
*
|
||||
*
|
||||
* <p>If incremental is true, then upon return pos.start may be
|
||||
* less than pos.limit, if some characters are unprocessed. If
|
||||
* incremental is false, then pos.start should be equal to pos.limit.
|
||||
*
|
||||
* @param text the buffer holding transliterated and
|
||||
* untransliterated text
|
||||
* @param index an array of three integers. See {@link
|
||||
* #transliterate(Replaceable, int[], String)}.
|
||||
* @param pos the start and limit of the text, the position
|
||||
* of the cursor, and the start and limit of transliteration.
|
||||
* @param incremental if true, assume more text may be coming after
|
||||
* pos.contextLimit. Otherwise, assume the text is complete.
|
||||
* @see #transliterate
|
||||
*/
|
||||
*/
|
||||
virtual void handleTransliterate(Replaceable& text,
|
||||
UTransPosition& index,
|
||||
UTransPosition& pos,
|
||||
UBool incremental) const = 0;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue