ICU-1533 disable rollback code

X-SVN-Rev: 7055
This commit is contained in:
Alan Liu 2001-11-21 19:55:39 +00:00
parent 412163dd3f
commit 2b109067ec
3 changed files with 49 additions and 4 deletions

View File

@ -355,6 +355,18 @@ UnicodeString& CompoundTransliterator::toRules(UnicodeString& rulesSource,
return rulesSource;
}
/**
* Rollback makes global filters and compound transliterators very
* bulletproof, but it also makes some transliterators completely
* non-incremental -- that is, for some transliterators, rollback
* is always triggered, until finishTransliteration() is called.
* Since this eliminates most of the usefulness of incremental
* mode, rollback should usually be disabled.
*
* This is used by Transliterator and CompoundTransliterator.
*/
// #define TRANSLIT_ROLLBACK
/**
* Implements {@link Transliterator#handleTransliterate}.
*/
@ -430,6 +442,7 @@ void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPositi
// operation.
int32_t compoundStart = index.start;
#ifdef TRANSLIT_ROLLBACK
// Rollback may be required. Consider a compound
// transliterator with two or more transliterators in it. For
// discussion purposes, assume that the first transliterator
@ -451,6 +464,7 @@ void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPositi
rollbackCopy = text.length();
text.copy(compoundStart, compoundLimit, rollbackCopy);
}
#endif
int32_t delta = 0; // delta in length
@ -466,6 +480,7 @@ void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPositi
delta += index.limit - limit;
if (incremental) {
#ifdef TRANSLIT_ROLLBACK
// If one component transliterator does not complete,
// then roll everything back and return. It's okay if
// component zero doesn't complete since it gets
@ -474,6 +489,7 @@ void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPositi
doRollback = TRUE;
break;
}
#endif
// In the incremental case, only allow subsequent
// transliterators to modify what has already been
@ -485,6 +501,7 @@ void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPositi
}
compoundLimit += delta;
#ifdef TRANSLIT_ROLLBACK
rollbackCopy += delta;
if (doRollback) {
@ -513,6 +530,7 @@ void CompoundTransliterator::handleTransliterate(Replaceable& text, UTransPositi
// Delete the rollback copy
text.handleReplaceBetween(rollbackCopy, text.length(), EMPTY);
}
#endif
// Start is good where it is -- where the last transliterator left
// it. Limit needs to be put back where it was, modulo

View File

@ -392,6 +392,18 @@ void Transliterator::_transliterate(Replaceable& text,
#endif
}
/**
* Rollback makes global filters and compound transliterators very
* bulletproof, but it also makes some transliterators completely
* non-incremental -- that is, for some transliterators, rollback
* is always triggered, until finishTransliteration() is called.
* Since this eliminates most of the usefulness of incremental
* mode, rollback should usually be disabled.
*
* This is used by Transliterator and CompoundTransliterator.
*/
// #define TRANSLIT_ROLLBACK
/**
* This method breaks up the input text into runs of unfiltered
* characters. It passes each such run to
@ -495,12 +507,14 @@ void Transliterator::filteredTransliterate(Replaceable& text,
// incremental. This is the solution implemented here.
int32_t rollbackStart = 0;
int32_t rollbackCopy = 0;
#ifdef TRANSLIT_ROLLBACK
if (isIncrementalSegment) {
// Make a rollback copy at the end of the string
rollbackStart = index.start;
rollbackCopy = text.length();
text.copy(rollbackStart, limit, rollbackCopy);
}
#endif
// Delegate to subclass for actual transliteration.
handleTransliterate(text, index, isIncrementalSegment);
@ -512,6 +526,7 @@ void Transliterator::filteredTransliterate(Replaceable& text,
// maintains that.
globalLimit += delta;
#ifdef TRANSLIT_ROLLBACK
// If we failed to complete transliterate this segment,
// then we are done. If rollback is required, then do so.
if (index.start != index.limit) {
@ -546,6 +561,13 @@ void Transliterator::filteredTransliterate(Replaceable& text,
rollbackCopy += delta;
text.handleReplaceBetween(rollbackCopy, text.length(), EMPTY);
}
#else
// If we failed to complete transliterate this segment,
// then we are done.
if (index.start != index.limit) {
break;
}
#endif
// If we did completely transliterate this
// segment, then repeat with the next unfiltered segment.

View File

@ -2109,6 +2109,10 @@ void TransliteratorTest::TestNewEngine() {
delete t;
#if 0
// This test will only work if Transliterator.ROLLBACK is
// true. Otherwise, this test will fail, revealing a
// limitation of global filters in incremental mode.
Transliterator *a =
Transliterator::createFromRules("a", "a > A;", UTRANS_FORWARD, pe, ec);
Transliterator *A =
@ -2142,6 +2146,11 @@ void TransliteratorTest::TestNewEngine() {
}
expect(*t, "aAaA", "bAbA");
delete a;
delete A;
delete array[1];
delete t;
#endif
expect("$smooth = x; $macron = q; [:^L:] { ([aeiouyAEIOUY] $macron?) } [^aeiouyAEIOUY$smooth$macron] > | $1 $smooth ;",
"a",
@ -2156,10 +2165,6 @@ void TransliteratorTest::TestNewEngine() {
"$rough <> h ;");
expect(gr, CharsToUnicodeString("\\u03B1\\u0314"), "ha");
delete a;
delete A;
delete array[1];
delete t;
}
/**