Delegate replace operation to rule object

X-SVN-Rev: 1119
This commit is contained in:
Alan Liu 2000-04-12 20:17:45 +00:00
parent 9188757ce0
commit c6a96e7684
4 changed files with 66 additions and 48 deletions

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/RuleBasedTransliterator.java,v $
* $Date: 2000/03/10 04:07:23 $
* $Revision: 1.17 $
* $Date: 2000/04/12 20:17:45 $
* $Revision: 1.18 $
*
*****************************************************************************************
*/
@ -209,9 +209,12 @@ 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.17 $ $Date: 2000/03/10 04:07:23 $
* @version $RCSfile: RuleBasedTransliterator.java,v $ $Revision: 1.18 $ $Date: 2000/04/12 20:17:45 $
*
* $Log: RuleBasedTransliterator.java,v $
* Revision 1.18 2000/04/12 20:17:45 alan
* Delegate replace operation to rule object
*
* Revision 1.17 2000/03/10 04:07:23 johnf
* Copyright update
*
@ -375,8 +378,10 @@ public class RuleBasedTransliterator extends Transliterator {
++cursor;
}
} else {
text.replace(cursor, cursor + r.getKeyLength(), r.getOutput());
limit += r.getOutput().length() - r.getKeyLength();
// Delegate replacement to TransliterationRule object
limit += r.replace(text, cursor);
// text.replace(cursor, cursor + r.getKeyLength(), r.getOutput());
// limit += r.getOutput().length() - r.getKeyLength();
cursor += r.getCursorPos();
++loopCount;
}

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/TransliterationRule.java,v $
* $Date: 2000/03/10 04:07:24 $
* $Revision: 1.14 $
* $Date: 2000/04/12 20:17:45 $
* $Revision: 1.15 $
*
*****************************************************************************************
*/
@ -33,9 +33,12 @@ import com.ibm.util.Utility;
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: TransliterationRule.java,v $ $Revision: 1.14 $ $Date: 2000/03/10 04:07:24 $
* @version $RCSfile: TransliterationRule.java,v $ $Revision: 1.15 $ $Date: 2000/04/12 20:17:45 $
*
* $Log: TransliterationRule.java,v $
* Revision 1.15 2000/04/12 20:17:45 alan
* Delegate replace operation to rule object
*
* Revision 1.14 2000/03/10 04:07:24 johnf
* Copyright update
*
@ -192,22 +195,6 @@ class TransliterationRule {
this.output = output;
}
/**
* Return the length of the key. Equivalent to <code>getKey().length()</code>.
* @return the length of the match key.
*/
public int getKeyLength() {
return keyLength;
}
/**
* Return the output string.
* @return the output string.
*/
public String getOutput() {
return output;
}
/**
* Return the position of the cursor within the output string.
* @return a value from 0 to <code>getOutput().length()</code>, inclusive.
@ -241,6 +228,23 @@ class TransliterationRule {
return variables.lookup(c) == null ? (c & 0xFF) : -1;
}
/**
* Do a replacement of the input pattern with the output text in
* the given string, at the given offset. This method assumes
* that a match has already been found in the given text at the
* given position.
* @param text the text containing the substring to be replaced
* @param offset the offset into the text at which the pattern
* matches. This is the offset to the point after the ante
* context, if any, and before the match string and any post
* context.
* @return the change in the length of the text
*/
int replace(Replaceable text, int offset) {
text.replace(offset, offset + keyLength, output);
return output.length() - keyLength;
}
/**
* Internal method. Returns true if this rule matches the given
* index value. The index value is an 8-bit integer, 0..255,

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/RuleBasedTransliterator.java,v $
* $Date: 2000/03/10 04:07:23 $
* $Revision: 1.17 $
* $Date: 2000/04/12 20:17:45 $
* $Revision: 1.18 $
*
*****************************************************************************************
*/
@ -209,9 +209,12 @@ 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.17 $ $Date: 2000/03/10 04:07:23 $
* @version $RCSfile: RuleBasedTransliterator.java,v $ $Revision: 1.18 $ $Date: 2000/04/12 20:17:45 $
*
* $Log: RuleBasedTransliterator.java,v $
* Revision 1.18 2000/04/12 20:17:45 alan
* Delegate replace operation to rule object
*
* Revision 1.17 2000/03/10 04:07:23 johnf
* Copyright update
*
@ -375,8 +378,10 @@ public class RuleBasedTransliterator extends Transliterator {
++cursor;
}
} else {
text.replace(cursor, cursor + r.getKeyLength(), r.getOutput());
limit += r.getOutput().length() - r.getKeyLength();
// Delegate replacement to TransliterationRule object
limit += r.replace(text, cursor);
// text.replace(cursor, cursor + r.getKeyLength(), r.getOutput());
// limit += r.getOutput().length() - r.getKeyLength();
cursor += r.getCursorPos();
++loopCount;
}

View file

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/TransliterationRule.java,v $
* $Date: 2000/03/10 04:07:24 $
* $Revision: 1.14 $
* $Date: 2000/04/12 20:17:45 $
* $Revision: 1.15 $
*
*****************************************************************************************
*/
@ -33,9 +33,12 @@ import com.ibm.util.Utility;
* <p>Copyright &copy; IBM Corporation 1999. All rights reserved.
*
* @author Alan Liu
* @version $RCSfile: TransliterationRule.java,v $ $Revision: 1.14 $ $Date: 2000/03/10 04:07:24 $
* @version $RCSfile: TransliterationRule.java,v $ $Revision: 1.15 $ $Date: 2000/04/12 20:17:45 $
*
* $Log: TransliterationRule.java,v $
* Revision 1.15 2000/04/12 20:17:45 alan
* Delegate replace operation to rule object
*
* Revision 1.14 2000/03/10 04:07:24 johnf
* Copyright update
*
@ -192,22 +195,6 @@ class TransliterationRule {
this.output = output;
}
/**
* Return the length of the key. Equivalent to <code>getKey().length()</code>.
* @return the length of the match key.
*/
public int getKeyLength() {
return keyLength;
}
/**
* Return the output string.
* @return the output string.
*/
public String getOutput() {
return output;
}
/**
* Return the position of the cursor within the output string.
* @return a value from 0 to <code>getOutput().length()</code>, inclusive.
@ -241,6 +228,23 @@ class TransliterationRule {
return variables.lookup(c) == null ? (c & 0xFF) : -1;
}
/**
* Do a replacement of the input pattern with the output text in
* the given string, at the given offset. This method assumes
* that a match has already been found in the given text at the
* given position.
* @param text the text containing the substring to be replaced
* @param offset the offset into the text at which the pattern
* matches. This is the offset to the point after the ante
* context, if any, and before the match string and any post
* context.
* @return the change in the length of the text
*/
int replace(Replaceable text, int offset) {
text.replace(offset, offset + keyLength, output);
return output.length() - keyLength;
}
/**
* Internal method. Returns true if this rule matches the given
* index value. The index value is an 8-bit integer, 0..255,