ICU-1544 add hasMetaData() to Replaceable
X-SVN-Rev: 9018
This commit is contained in:
parent
03b85b71e6
commit
8d14ce3a2e
@ -145,5 +145,9 @@ public class ReplaceableTest extends TestFmwk {
|
||||
chars.copy(start, limit, dest);
|
||||
styles.copy(start, limit, dest);
|
||||
}
|
||||
|
||||
public boolean hasMetaData() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Replaceable.java,v $
|
||||
* $Date: 2002/02/16 03:06:12 $
|
||||
* $Revision: 1.6 $
|
||||
* $Date: 2002/07/02 23:50:34 $
|
||||
* $Revision: 1.7 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -16,19 +16,24 @@ package com.ibm.icu.text;
|
||||
* <code>Replaceable</code> is an interface that supports the
|
||||
* operation of replacing a substring with another piece of text.
|
||||
* <code>Replaceable</code> is needed in order to change a piece of
|
||||
* text while retaining style attributes. For example, if the string
|
||||
* text while retaining metadata. Metadata is data other than the
|
||||
* Unicode characters returned by char32At(). One example of metadata
|
||||
* is style tags; another is an edit history, marking each character
|
||||
* with an author and revision number. For example, if the string
|
||||
* "the <b>bold</b> font" has range (4, 8) replaced with "strong",
|
||||
* then it becomes "the <b>strong</b> font".
|
||||
*
|
||||
* <p>If a subclass supports styles, then typically the behavior is the following:
|
||||
* <p>If a subclass supports metadata, then typically the behavior of
|
||||
* <code>replace()</code> is the following:
|
||||
* <ul>
|
||||
* <li>Set the styles to the style of the first character replaced</li>
|
||||
* <li>If no characters are replaced, use the style of the previous
|
||||
* character</li>
|
||||
* <li>If there is no previous character (i.e. start == 0), use the following
|
||||
* character</li>
|
||||
* <li>If there is no following character (i.e. the replaceable was empty), a
|
||||
* default style.<br>
|
||||
* <li>Set the metadata of the new text to the metadata of the first
|
||||
* character replaced</li>
|
||||
* <li>If no characters are replaced, use the metadata of the
|
||||
* previous character</li>
|
||||
* <li>If there is no previous character (i.e. start == 0), use the
|
||||
* following character</li>
|
||||
* <li>If there is no following character (i.e. the replaceable was
|
||||
* empty), use default metadata.<br>
|
||||
* </li>
|
||||
* </ul>
|
||||
* If this is not the behavior, the subclass should document any differences.
|
||||
@ -36,25 +41,25 @@ package com.ibm.icu.text;
|
||||
* <p>Copyright © IBM Corporation 1999. All rights reserved.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: Replaceable.java,v $ $Revision: 1.6 $ $Date: 2002/02/16 03:06:12 $
|
||||
* @version $RCSfile: Replaceable.java,v $ $Revision: 1.7 $ $Date: 2002/07/02 23:50:34 $
|
||||
*/
|
||||
public interface Replaceable {
|
||||
/**
|
||||
* Return the number of characters in the text.
|
||||
* @return number of characters in text
|
||||
* Returns the number of 16-bit code units in the text.
|
||||
* @return number of 16-bit code units in text
|
||||
*/
|
||||
int length();
|
||||
|
||||
/**
|
||||
* Return the character at the given offset into the text.
|
||||
* Returns the 16-bit code unit at the given offset into the text.
|
||||
* @param offset an integer between 0 and <code>length()</code>-1
|
||||
* inclusive
|
||||
* @return character of text at given offset
|
||||
* @return 16-bit code unit of text at given offset
|
||||
*/
|
||||
char charAt(int offset);
|
||||
|
||||
/**
|
||||
* Return the 32-bit code point at the given 16-bit offset into
|
||||
* Returns the 32-bit code point at the given 16-bit offset into
|
||||
* the text. This assumes the text is stored as 16-bit code units
|
||||
* with surrogate pairs intermixed. If the offset of a leading or
|
||||
* trailing code unit of a surrogate pair is given, return the
|
||||
@ -88,15 +93,15 @@ public interface Replaceable {
|
||||
void getChars(int srcStart, int srcLimit, char dst[], int dstStart);
|
||||
|
||||
/**
|
||||
* Replace a substring of this object with the given text.
|
||||
* Replaces a substring of this object with the given text.
|
||||
*
|
||||
* <p>Subclasses must ensure that if the text between start and
|
||||
* limit is equal to the replacement text, that replace has no
|
||||
* effect. That is, any out-of-band information such as styles
|
||||
* should be unaffected. In addition, subclasses are encourage to
|
||||
* effect. That is, any metadata
|
||||
* should be unaffected. In addition, subclasses are encouraged to
|
||||
* check for initial and trailing identical characters, and make a
|
||||
* smaller replacement if possible. This will preserve as much
|
||||
* style information as possible.
|
||||
* metadata as possible.
|
||||
* @param start the beginning index, inclusive; <code>0 <= start
|
||||
* <= limit</code>.
|
||||
* @param limit the ending index, exclusive; <code>start <= limit
|
||||
@ -107,15 +112,15 @@ public interface Replaceable {
|
||||
void replace(int start, int limit, String text);
|
||||
|
||||
/**
|
||||
* Replace a substring of this object with the given text.
|
||||
* Replaces a substring of this object with the given text.
|
||||
*
|
||||
* <p>Subclasses must ensure that if the text between start and
|
||||
* limit is equal to the replacement text, that replace has no
|
||||
* effect. That is, any out-of-band information such as styles
|
||||
* should be unaffected. In addition, subclasses are encourage to
|
||||
* effect. That is, any metadata
|
||||
* should be unaffected. In addition, subclasses are encouraged to
|
||||
* check for initial and trailing identical characters, and make a
|
||||
* smaller replacement if possible. This will preserve as much
|
||||
* style information as possible.
|
||||
* metadata as possible.
|
||||
* @param start the beginning index, inclusive; <code>0 <= start
|
||||
* <= limit</code>.
|
||||
* @param limit the ending index, exclusive; <code>start <= limit
|
||||
@ -132,12 +137,11 @@ public interface Replaceable {
|
||||
// and System.arraycopy.
|
||||
|
||||
/**
|
||||
* Copy a substring of this object, retaining attribute (out-of-band)
|
||||
* information. This method is used to duplicate or reorder substrings.
|
||||
* Copies a substring of this object, retaining metadata
|
||||
* This method is used to duplicate or reorder substrings.
|
||||
* The destination index must not overlap the source range.
|
||||
* Implementations that do not care about maintaining out-of-band
|
||||
* information or performance during copying may use the naive
|
||||
* implementation:
|
||||
* If <code>hasMetaData()</code> returns false, subclasses
|
||||
* may use the naive implementation:
|
||||
*
|
||||
* <pre> char[] text = new char[limit - start];
|
||||
* getChars(start, limit, text, 0);
|
||||
@ -153,4 +157,13 @@ public interface Replaceable {
|
||||
* dest >= limit</code>.
|
||||
*/
|
||||
void copy(int start, int limit, int dest);
|
||||
|
||||
/**
|
||||
* Returns true if this object contains metadata. If a
|
||||
* Replaceable object has metadata, calls to the Replaceable API
|
||||
* must be made so as to preserve metadata. If it does not, calls
|
||||
* to the Replaceable API may be optimized to improve performance.
|
||||
* @return true if this object contains metadata
|
||||
*/
|
||||
boolean hasMetaData();
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/ReplaceableString.java,v $
|
||||
* $Date: 2002/02/25 22:43:58 $
|
||||
* $Revision: 1.10 $
|
||||
* $Date: 2002/07/02 23:50:34 $
|
||||
* $Revision: 1.11 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
@ -26,7 +26,7 @@ import com.ibm.icu.impl.Utility;
|
||||
*
|
||||
* @see Replaceable
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: ReplaceableString.java,v $ $Revision: 1.10 $ $Date: 2002/02/25 22:43:58 $
|
||||
* @version $RCSfile: ReplaceableString.java,v $ $Revision: 1.11 $ $Date: 2002/07/02 23:50:34 $
|
||||
*/
|
||||
public class ReplaceableString implements Replaceable {
|
||||
private StringBuffer buf;
|
||||
@ -183,4 +183,11 @@ public class ReplaceableString implements Replaceable {
|
||||
getChars(start, limit, text, 0);
|
||||
replace(dest, dest, text, 0, limit - start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Replaceable
|
||||
*/
|
||||
public boolean hasMetaData() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user