Fix handling of Positions fields

X-SVN-Rev: 1673
This commit is contained in:
Alan Liu 2000-06-28 20:49:54 +00:00
parent 451cdc7bf9
commit 0067d14bf0
14 changed files with 93 additions and 96 deletions

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/CompoundTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.10 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.11 $
*
*****************************************************************************************
*/
@ -35,7 +35,7 @@ import java.util.Vector;
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: CompoundTransliterator.java,v $ $Revision: 1.10 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: CompoundTransliterator.java,v $ $Revision: 1.11 $ $Date: 2000/06/28 20:49:54 $
*/
public class CompoundTransliterator extends Transliterator {
@ -274,7 +274,7 @@ public class CompoundTransliterator extends Transliterator {
* S C L
*/
int cursor = index.start;
int limit = index.contextLimit;
int limit = index.limit;
int globalLimit = limit;
/* globalLimit is the overall limit. We keep track of this
* since we overwrite index.contextLimit with the previous
@ -284,7 +284,7 @@ public class CompoundTransliterator extends Transliterator {
for (int i=0; i<trans.length; ++i) {
index.start = cursor; // Reset cursor
index.contextLimit = limit;
index.limit = limit;
if (DEBUG) {
System.out.print(Utility.escape(i + ": \"" +
@ -303,13 +303,13 @@ public class CompoundTransliterator extends Transliterator {
}
// Adjust overall limit for insertions/deletions
globalLimit += index.contextLimit - limit;
globalLimit += index.limit - limit;
limit = index.start; // Move limit to end of committed text
}
// Cursor is good where it is -- where the last
// transliterator left it. Limit needs to be put back
// where it was, modulo adjustments for deletions/insertions.
index.contextLimit = globalLimit;
index.limit = globalLimit;
}
/**

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Attic/HexToUnicodeTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.7 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.8 $
*
*****************************************************************************************
*/
@ -23,7 +23,7 @@ import java.util.*;
* applyPattern() for details.
*
* @author Alan Liu
* @version $RCSfile: HexToUnicodeTransliterator.java,v $ $Revision: 1.7 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: HexToUnicodeTransliterator.java,v $ $Revision: 1.8 $ $Date: 2000/06/28 20:49:54 $
*/
public class HexToUnicodeTransliterator extends Transliterator {
private static final String COPYRIGHT =
@ -268,7 +268,7 @@ public class HexToUnicodeTransliterator extends Transliterator {
protected void handleTransliterate(Replaceable text,
Position offsets, boolean isIncremental) {
int cursor = offsets.start;
int limit = offsets.contextLimit;
int limit = offsets.limit;
int i, j, ipat;
loop:
@ -373,7 +373,8 @@ public class HexToUnicodeTransliterator extends Transliterator {
++cursor;
}
offsets.contextLimit = limit;
offsets.contextLimit += limit - offsets.limit;
offsets.limit = limit;
offsets.start = cursor;
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/NullTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.7 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.8 $
*
*****************************************************************************************
*/
@ -37,6 +37,6 @@ public class NullTransliterator extends Transliterator {
*/
protected void handleTransliterate(Replaceable text,
Position offsets, boolean incremental) {
offsets.start = offsets.contextLimit;
offsets.start = offsets.limit;
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/RuleBasedTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.34 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.35 $
*
*****************************************************************************************
*/
@ -252,7 +252,7 @@ import com.ibm.util.Utility;
* <p>Copyright (c) IBM Corporation 1999-2000. All rights reserved.</p>
*
* @author Alan Liu
* @version $RCSfile: RuleBasedTransliterator.java,v $ $Revision: 1.34 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: RuleBasedTransliterator.java,v $ $Revision: 1.35 $ $Date: 2000/06/28 20:49:54 $
*/
public class RuleBasedTransliterator extends Transliterator {
@ -325,7 +325,7 @@ public class RuleBasedTransliterator extends Transliterator {
* exzd| done
*/
int start = index.contextStart;
int limit = index.contextLimit;
int limit = index.limit;
int cursor = index.start;
if (DEBUG) {
@ -356,9 +356,9 @@ public class RuleBasedTransliterator extends Transliterator {
while (cursor < limit && loopCount <= loopLimit) {
TransliterationRule r = incremental ?
data.ruleSet.findIncrementalMatch(text, start, limit, cursor,
data.ruleSet.findIncrementalMatch(text, index.contextStart, limit, cursor,
data, partial, getFilter()) :
data.ruleSet.findMatch(text, start, limit,
data.ruleSet.findMatch(text, index.contextStart, limit,
cursor, data, getFilter());
/* If we match a rule then apply it by replacing the key
* with the rule output and repositioning the cursor
@ -391,7 +391,8 @@ public class RuleBasedTransliterator extends Transliterator {
Utility.escape(rsubstring(text, cursor, limit)) + "\"");
}
index.contextLimit = limit;
index.contextLimit += limit - index.limit;
index.limit = limit;
index.start = cursor;
}
@ -1328,6 +1329,9 @@ public class RuleBasedTransliterator extends Transliterator {
/**
* $Log: RuleBasedTransliterator.java,v $
* Revision 1.35 2000/06/28 20:49:54 alan4j
* Fix handling of Positions fields
*
* Revision 1.34 2000/06/28 20:36:32 alan4j
* Clean up Transliterator::Position - rename temporary names
*

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Transliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.18 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.19 $
*
*****************************************************************************************
*/
@ -210,7 +210,7 @@ import java.text.MessageFormat;
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: Transliterator.java,v $ $Revision: 1.18 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: Transliterator.java,v $ $Revision: 1.19 $ $Date: 2000/06/28 20:49:54 $
*/
public abstract class Transliterator {
/**
@ -536,7 +536,8 @@ public abstract class Transliterator {
int originalStart = index.contextStart;
if (insertion != null) {
text.replace(index.contextLimit, index.contextLimit, insertion);
text.replace(index.limit, index.limit, insertion);
index.limit += insertion.length();
index.contextLimit += insertion.length();
}
@ -593,19 +594,9 @@ public abstract class Transliterator {
*/
public final void finishTransliteration(Replaceable text,
Position index) {
if (index.contextStart < 0 ||
index.contextLimit > text.length() ||
index.start < index.contextStart ||
index.start > index.contextLimit) {
throw new IllegalArgumentException("Invalid index");
}
int originalStart = index.contextStart;
handleTransliterate(text, index, false);
index.contextStart = Math.max(index.start - getMaximumContextLength(),
originalStart);
int limit = transliterate(text, index.start, index.limit);
index.contextLimit += limit - index.limit;
index.start = index.limit = limit;
}
/**

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Attic/UnicodeToHexTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.8 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.9 $
*
*****************************************************************************************
*/
@ -32,7 +32,7 @@ import java.util.*;
* default is uppercase.
*
* @author Alan Liu
* @version $RCSfile: UnicodeToHexTransliterator.java,v $ $Revision: 1.8 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: UnicodeToHexTransliterator.java,v $ $Revision: 1.9 $ $Date: 2000/06/28 20:49:54 $
*/
public class UnicodeToHexTransliterator extends Transliterator {
@ -292,7 +292,7 @@ public class UnicodeToHexTransliterator extends Transliterator {
* assuming the prefix is "U+".
*/
int cursor = offsets.start;
int limit = offsets.contextLimit;
int limit = offsets.limit;
UnicodeFilter filter = getFilter();
StringBuffer hex = new StringBuffer(prefix);
@ -323,7 +323,8 @@ public class UnicodeToHexTransliterator extends Transliterator {
limit += len;
}
offsets.contextLimit = limit;
offsets.contextLimit += limit - offsets.limit;
offsets.limit = limit;
offsets.start = cursor;
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/CompoundTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.10 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.11 $
*
*****************************************************************************************
*/
@ -35,7 +35,7 @@ import java.util.Vector;
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: CompoundTransliterator.java,v $ $Revision: 1.10 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: CompoundTransliterator.java,v $ $Revision: 1.11 $ $Date: 2000/06/28 20:49:54 $
*/
public class CompoundTransliterator extends Transliterator {
@ -274,7 +274,7 @@ public class CompoundTransliterator extends Transliterator {
* S C L
*/
int cursor = index.start;
int limit = index.contextLimit;
int limit = index.limit;
int globalLimit = limit;
/* globalLimit is the overall limit. We keep track of this
* since we overwrite index.contextLimit with the previous
@ -284,7 +284,7 @@ public class CompoundTransliterator extends Transliterator {
for (int i=0; i<trans.length; ++i) {
index.start = cursor; // Reset cursor
index.contextLimit = limit;
index.limit = limit;
if (DEBUG) {
System.out.print(Utility.escape(i + ": \"" +
@ -303,13 +303,13 @@ public class CompoundTransliterator extends Transliterator {
}
// Adjust overall limit for insertions/deletions
globalLimit += index.contextLimit - limit;
globalLimit += index.limit - limit;
limit = index.start; // Move limit to end of committed text
}
// Cursor is good where it is -- where the last
// transliterator left it. Limit needs to be put back
// where it was, modulo adjustments for deletions/insertions.
index.contextLimit = globalLimit;
index.limit = globalLimit;
}
/**

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/HangulJamoTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.6 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.7 $
*
*****************************************************************************************
*/
@ -19,7 +19,7 @@ import java.util.*;
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Mark Davis
* @version $RCSfile: HangulJamoTransliterator.java,v $ $Revision: 1.6 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: HangulJamoTransliterator.java,v $ $Revision: 1.7 $ $Date: 2000/06/28 20:49:54 $
*/
public class HangulJamoTransliterator extends Transliterator {
private static final String COPYRIGHT =
@ -43,7 +43,7 @@ public class HangulJamoTransliterator extends Transliterator {
protected void handleTransliterate(Replaceable text,
Position offsets, boolean incremental) {
int cursor = offsets.start;
int limit = offsets.contextLimit;
int limit = offsets.limit;
StringBuffer replacement = new StringBuffer();
while (cursor < limit) {
@ -57,6 +57,7 @@ public class HangulJamoTransliterator extends Transliterator {
}
}
offsets.contextLimit += limit - offsets.limit;
offsets.contextLimit = limit;
offsets.start = cursor;
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/HexToUnicodeTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.7 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.8 $
*
*****************************************************************************************
*/
@ -23,7 +23,7 @@ import java.util.*;
* applyPattern() for details.
*
* @author Alan Liu
* @version $RCSfile: HexToUnicodeTransliterator.java,v $ $Revision: 1.7 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: HexToUnicodeTransliterator.java,v $ $Revision: 1.8 $ $Date: 2000/06/28 20:49:54 $
*/
public class HexToUnicodeTransliterator extends Transliterator {
private static final String COPYRIGHT =
@ -268,7 +268,7 @@ public class HexToUnicodeTransliterator extends Transliterator {
protected void handleTransliterate(Replaceable text,
Position offsets, boolean isIncremental) {
int cursor = offsets.start;
int limit = offsets.contextLimit;
int limit = offsets.limit;
int i, j, ipat;
loop:
@ -373,7 +373,8 @@ public class HexToUnicodeTransliterator extends Transliterator {
++cursor;
}
offsets.contextLimit = limit;
offsets.contextLimit += limit - offsets.limit;
offsets.limit = limit;
offsets.start = cursor;
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/JamoHangulTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.7 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.8 $
*
*****************************************************************************************
*/
@ -46,7 +46,7 @@ public class JamoHangulTransliterator extends Transliterator {
* Performs transliteration changing Jamo to Hangul
*/
int cursor = offsets.start;
int limit = offsets.contextLimit;
int limit = offsets.limit;
if (cursor >= limit) return;
int count[] = new int[1];
@ -68,7 +68,9 @@ public class JamoHangulTransliterator extends Transliterator {
}
}
offsets.contextLimit = limit + 1;
++limit;
offsets.contextLimit += limit - offsets.limit;
offsets.limit = limit;
offsets.start = cursor;
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/NullTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.7 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.8 $
*
*****************************************************************************************
*/
@ -37,6 +37,6 @@ public class NullTransliterator extends Transliterator {
*/
protected void handleTransliterate(Replaceable text,
Position offsets, boolean incremental) {
offsets.start = offsets.contextLimit;
offsets.start = offsets.limit;
}
}

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/RuleBasedTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.34 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.35 $
*
*****************************************************************************************
*/
@ -252,7 +252,7 @@ import com.ibm.util.Utility;
* <p>Copyright (c) IBM Corporation 1999-2000. All rights reserved.</p>
*
* @author Alan Liu
* @version $RCSfile: RuleBasedTransliterator.java,v $ $Revision: 1.34 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: RuleBasedTransliterator.java,v $ $Revision: 1.35 $ $Date: 2000/06/28 20:49:54 $
*/
public class RuleBasedTransliterator extends Transliterator {
@ -325,7 +325,7 @@ public class RuleBasedTransliterator extends Transliterator {
* exzd| done
*/
int start = index.contextStart;
int limit = index.contextLimit;
int limit = index.limit;
int cursor = index.start;
if (DEBUG) {
@ -356,9 +356,9 @@ public class RuleBasedTransliterator extends Transliterator {
while (cursor < limit && loopCount <= loopLimit) {
TransliterationRule r = incremental ?
data.ruleSet.findIncrementalMatch(text, start, limit, cursor,
data.ruleSet.findIncrementalMatch(text, index.contextStart, limit, cursor,
data, partial, getFilter()) :
data.ruleSet.findMatch(text, start, limit,
data.ruleSet.findMatch(text, index.contextStart, limit,
cursor, data, getFilter());
/* If we match a rule then apply it by replacing the key
* with the rule output and repositioning the cursor
@ -391,7 +391,8 @@ public class RuleBasedTransliterator extends Transliterator {
Utility.escape(rsubstring(text, cursor, limit)) + "\"");
}
index.contextLimit = limit;
index.contextLimit += limit - index.limit;
index.limit = limit;
index.start = cursor;
}
@ -1328,6 +1329,9 @@ public class RuleBasedTransliterator extends Transliterator {
/**
* $Log: RuleBasedTransliterator.java,v $
* Revision 1.35 2000/06/28 20:49:54 alan4j
* Fix handling of Positions fields
*
* Revision 1.34 2000/06/28 20:36:32 alan4j
* Clean up Transliterator::Position - rename temporary names
*

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/Transliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.18 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.19 $
*
*****************************************************************************************
*/
@ -210,7 +210,7 @@ import java.text.MessageFormat;
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: Transliterator.java,v $ $Revision: 1.18 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: Transliterator.java,v $ $Revision: 1.19 $ $Date: 2000/06/28 20:49:54 $
*/
public abstract class Transliterator {
/**
@ -536,7 +536,8 @@ public abstract class Transliterator {
int originalStart = index.contextStart;
if (insertion != null) {
text.replace(index.contextLimit, index.contextLimit, insertion);
text.replace(index.limit, index.limit, insertion);
index.limit += insertion.length();
index.contextLimit += insertion.length();
}
@ -593,19 +594,9 @@ public abstract class Transliterator {
*/
public final void finishTransliteration(Replaceable text,
Position index) {
if (index.contextStart < 0 ||
index.contextLimit > text.length() ||
index.start < index.contextStart ||
index.start > index.contextLimit) {
throw new IllegalArgumentException("Invalid index");
}
int originalStart = index.contextStart;
handleTransliterate(text, index, false);
index.contextStart = Math.max(index.start - getMaximumContextLength(),
originalStart);
int limit = transliterate(text, index.start, index.limit);
index.contextLimit += limit - index.limit;
index.start = index.limit = limit;
}
/**

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UnicodeToHexTransliterator.java,v $
* $Date: 2000/06/28 20:36:32 $
* $Revision: 1.8 $
* $Date: 2000/06/28 20:49:54 $
* $Revision: 1.9 $
*
*****************************************************************************************
*/
@ -32,7 +32,7 @@ import java.util.*;
* default is uppercase.
*
* @author Alan Liu
* @version $RCSfile: UnicodeToHexTransliterator.java,v $ $Revision: 1.8 $ $Date: 2000/06/28 20:36:32 $
* @version $RCSfile: UnicodeToHexTransliterator.java,v $ $Revision: 1.9 $ $Date: 2000/06/28 20:49:54 $
*/
public class UnicodeToHexTransliterator extends Transliterator {
@ -292,7 +292,7 @@ public class UnicodeToHexTransliterator extends Transliterator {
* assuming the prefix is "U+".
*/
int cursor = offsets.start;
int limit = offsets.contextLimit;
int limit = offsets.limit;
UnicodeFilter filter = getFilter();
StringBuffer hex = new StringBuffer(prefix);
@ -323,7 +323,8 @@ public class UnicodeToHexTransliterator extends Transliterator {
limit += len;
}
offsets.contextLimit = limit;
offsets.contextLimit += limit - offsets.limit;
offsets.limit = limit;
offsets.start = cursor;
}
}