Replaceable
is an abstract base class representing a string of characters that supports the replacement of a range of itself with a new string of characters.
More...
#include <rep.h>
Inheritance diagram for Replaceable:
Public Methods | |
virtual | ~Replaceable () |
Destructor. More... | |
int32_t | length () const |
Return the number of characters in the text. More... | |
UChar | charAt (UTextOffset offset) const |
Return the Unicode code unit at the given offset into the text. More... | |
UChar32 | char32At (UTextOffset offset) const |
Return the Unicode code point that contains the code unit at the given offset into the text. More... | |
virtual void | extractBetween (UTextOffset start, UTextOffset limit, UnicodeString &target) const=0 |
Copy the characters in the range [start , limit ) into the UnicodeString target . More... | |
virtual void | handleReplaceBetween (UTextOffset start, UTextOffset limit, const UnicodeString &text)=0 |
Replace a substring of this object with the given text. More... | |
virtual void | copy (int32_t start, int32_t limit, int32_t dest)=0 |
Copy a substring of this object, retaining attribute (out-of-band) information. More... | |
Protected Methods | |
Replaceable () | |
Default constructor. | |
virtual int32_t | getLength () const=0 |
Virtual version of length(). | |
virtual UChar | getCharAt (UTextOffset offset) const=0 |
Virtual version of charAt(). | |
virtual UChar32 | getChar32At (UTextOffset offset) const=0 |
Virtual version of char32At(). |
Replaceable
is an abstract base class representing a string of characters that supports the replacement of a range of itself with a new string of characters.
It is used by APIs that change a piece of text while retaining style attributes. In other words, an implicit aspect of the Replaceable
API is that during a replace operation, new characters take on the attributes, if any, of the old characters. For example, if the string "the bold font" has range (4, 8) replaced with "strong", then it becomes "the strong font".
Replaceable
specifies ranges using an initial offset and a limit offset. The range of characters thus specified includes the characters at offset initial..limit-1. That is, the start offset is inclusive, and the limit offset is exclusive.
Replaceable
also includes API to access characters in the string: length()
, charAt()
, and extractBetween()
.
If a subclass supports styles, then typically the behavior is the following:
|
Destructor. @stable |
|
Return the Unicode code point that contains the code unit at the given offset into the text.
Reimplemented in UnicodeString. |
|
Return the Unicode code unit at the given offset into the text.
Reimplemented in UnicodeString. |
|
Copy a substring of this object, retaining attribute (out-of-band) information. 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:
char[] text = new char[limit - start]; getChars(start, limit, text, 0); replace(dest, dest, text, 0, limit - start);
Implemented in UnicodeString. |
|
Copy the characters in the range [
Implemented in UnicodeString. |
|
Replace a substring of this object with the given text. If the characters being replaced have attributes, the new characters that replace them should be given the same attributes.
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 check for initial and trailing identical characters, and make a smaller replacement if possible. This will preserve as much style information as possible.
Implemented in UnicodeString. |
|
Return the number of characters in the text.
Reimplemented in UnicodeString. |