Package com.ibm.icu.text
Class ReplaceableString
java.lang.Object
com.ibm.icu.text.ReplaceableString
- All Implemented Interfaces:
Replaceable
ReplaceableString
is an adapter class that implements the
Replaceable
API around an ordinary StringBuffer
.
Note: This class does not support attributes and is not
intended for general use. Most clients will need to implement
Replaceable
in their text representation class.
- Author:
- Alan Liu
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new empty object.ReplaceableString
(String str) Construct a new object with the given initial contents.Construct a new object usingbuf
for internal storage. -
Method Summary
Modifier and TypeMethodDescriptionint
char32At
(int offset) Return the 32-bit code point at the given 16-bit offset into the text.char
charAt
(int offset) Return the character at the given position in this object.void
copy
(int start, int limit, int dest) Copy a substring of this object, retaining attribute (out-of-band) information.void
getChars
(int srcStart, int srcLimit, char[] dst, int dstStart) Copies characters from this object into the destination character array.boolean
Implements Replaceableint
length()
Return the number of characters contained in this object.void
replace
(int start, int limit, char[] chars, int charsStart, int charsLen) Replace a substring of this object with the given text.void
Replace zero or more characters with new characters.substring
(int start, int limit) Return a substring of the given string.toString()
Return the contents of this object as aString
.
-
Constructor Details
-
ReplaceableString
Construct a new object with the given initial contents.- Parameters:
str
- initial contents
-
ReplaceableString
Construct a new object usingbuf
for internal storage. The contents ofbuf
at the time of construction are used as the initial contents. Note! Modifications tobuf
will modify this object, and vice versa.- Parameters:
buf
- object to be used as internal storage
-
ReplaceableString
public ReplaceableString()Construct a new empty object.
-
-
Method Details
-
toString
Return the contents of this object as aString
. -
substring
Return a substring of the given string. -
length
public int length()Return the number of characters contained in this object.Replaceable
API.- Specified by:
length
in interfaceReplaceable
- Returns:
- number of 16-bit code units in text
-
charAt
public char charAt(int offset) Return the character at the given position in this object.Replaceable
API.- Specified by:
charAt
in interfaceReplaceable
- Parameters:
offset
- offset into the contents, from 0 tolength()
- 1- Returns:
- 16-bit code unit of text at given offset
-
char32At
public int char32At(int offset) Return 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 code point of the surrogate pair.- Specified by:
char32At
in interfaceReplaceable
- Parameters:
offset
- an integer between 0 andlength()
-1 inclusive- Returns:
- 32-bit code point of text at given offset
-
getChars
public void getChars(int srcStart, int srcLimit, char[] dst, int dstStart) Copies characters from this object into the destination character array. The first character to be copied is at indexsrcStart
; the last character to be copied is at indexsrcLimit-1
(thus the total number of characters to be copied issrcLimit-srcStart
). The characters are copied into the subarray ofdst
starting at indexdstStart
and ending at indexdstStart + (srcLimit-srcStart) - 1
.- Specified by:
getChars
in interfaceReplaceable
- Parameters:
srcStart
- the beginning index to copy, inclusive;0 <= start <= limit
.srcLimit
- the ending index to copy, exclusive;start <= limit <= length()
.dst
- the destination array.dstStart
- the start offset in the destination array.
-
replace
Replace zero or more characters with new characters.Replaceable
API.- Specified by:
replace
in interfaceReplaceable
- Parameters:
start
- the beginning index, inclusive;0 <= start <= limit
.limit
- the ending index, exclusive;start <= limit <= length()
.text
- new text to replace charactersstart
tolimit - 1
-
replace
public void replace(int start, int limit, char[] chars, int charsStart, int charsLen) Replace a substring of this object with the given text.- Specified by:
replace
in interfaceReplaceable
- Parameters:
start
- the beginning index, inclusive;0 <= start <= limit
.limit
- the ending index, exclusive;start <= limit <= length()
.chars
- the text to replace charactersstart
tolimit - 1
charsStart
- the beginning index intochars
, inclusive;0 <= start <= limit
.charsLen
- the number of characters ofchars
.
-
copy
public void copy(int start, int limit, int dest) 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.- Specified by:
copy
in interfaceReplaceable
- Parameters:
start
- the beginning index, inclusive;0 <= start <= limit
.limit
- the ending index, exclusive;start <= limit <= length()
.dest
- the destination index. The characters fromstart..limit-1
will be copied todest
. Implementations of this method may assume thatdest <= start || dest >= limit
.
-
hasMetaData
public boolean hasMetaData()Implements Replaceable- Specified by:
hasMetaData
in interfaceReplaceable
- Returns:
- true if this object contains metadata
-