org.clapper.util.text
Class XStringBufBase
- java.lang.Object
-
- org.clapper.util.text.XStringBufBase
-
- All Implemented Interfaces:
- java.lang.Appendable, java.lang.CharSequence
- Direct Known Subclasses:
- XStringBuffer, XStringBuilder
public abstract class XStringBufBase extends java.lang.Object implements java.lang.CharSequence, java.lang.AppendableAbstract base class for XStringBuffer and XStringBuilder. This class exists to share common functionality, pushing appropriate details to the underlying implementation.- See Also:
XStringBuffer,XStringBuilder,StringBuffer,StringBuilder
-
-
Field Summary
Fields Modifier and Type Field and Description static charMETACHAR_SEQUENCE_STARTThe character that denotes the start of a metacharacter sequence.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description XStringBufBaseappend(boolean val)Append the string representation of a boolean value to the buffer.XStringBufBaseappend(char c)Append the specified character to the buffer.XStringBufBaseappend(char[] chars)Append the specified array of characters to the buffer.XStringBufBaseappend(char[] chars, int offset, int len)Append the specified characters in a character array to the buffer.XStringBufBaseappend(java.lang.CharSequence csq)Append the entire contents of the specified CharSequence to the buffer.XStringBufBaseappend(java.lang.CharSequence csq, int start, int end)Append a subsequence of the specified CharSequence to the buffer.XStringBufBaseappend(double val)Append the string representation of a double value to the buffer.XStringBufBaseappend(float val)Append the string representation of a float value to the buffer.XStringBufBaseappend(int val)Append the string representation of a int value to the buffer.XStringBufBaseappend(long val)Append the string representation of a long value to the buffer.XStringBufBaseappend(java.lang.Object obj)Append the string representation of an object to the buffer.XStringBufBaseappend(short val)Append the string representation of a short value to the buffer.XStringBufBaseappend(java.lang.String s)Append the specified string to the buffer.charcharAt(int index)Return the character at a specified index in the buffer.voidclear()Removes all characters from the buffer leaving it empty.voiddecodeMetacharacters()A version ofdecodeMetacharactersthat processes the entire string buffer.voiddecodeMetacharacters(int start, int end)Replaces any metacharacter sequences in a portion of the string buffer (such as those produced byencodeMetacharacters()with their actual characters.XStringBufBasedelete(int start, int end)Remove the characters in a substring of this XStringBuffer.booleandelete(java.lang.String substring)Delete the first occurrence of a given substring in the buffer.voidencodeMetacharacters()A version ofencodeMetacharactersthat processes the entire string buffer.voidencodeMetacharacters(int start, int end)Replaces certain characters in the string buffer with Java metacharacter ("backslash") sequences.abstract voidgetChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)Copy the some or all of the contents of the buffer into a character array.intindexOf(int ch)Returns the index within this string of the first occurrence of the specified character.intindexOf(java.lang.String str)Returns the index within this string of the first occurrence of the specified substring in this sequence, starting at position 0.intindexOf(java.lang.String str, int start)Returns the index within this string of the first occurrence of the specified substring in this sequence, with the search starting at the specified position.XStringBufBaseinsert(int index, boolean val)Insert the string representation of a booleanvalue into the buffer at a specified position.XStringBufBaseinsert(int index, char ch)Insert a single character at a specified position in the buffer.XStringBufBaseinsert(int index, char[] chars)Insert the contents of a character array into the buffer at a specified position.XStringBufBaseinsert(int index, char[] chars, int offset, int len)Insert characters from a character array into the buffer at a specified position.XStringBufBaseinsert(int index, double val)Insert the string representation of a doublevalue into the buffer at a specified position.XStringBufBaseinsert(int index, float val)Insert the string representation of a floatvalue into the buffer at a specified position.XStringBufBaseinsert(int index, int val)Insert the string representation of a intvalue into the buffer at a specified position.XStringBufBaseinsert(int index, long val)Insert the string representation of a longvalue into the buffer at a specified position.XStringBufBaseinsert(int index, java.lang.Object obj)Insert the string representation of an arbitrary object into the buffer at a specified position.XStringBufBaseinsert(int index, short val)Insert the string representation of a shortvalue into the buffer at a specified position.XStringBufBaseinsert(int index, java.lang.String s)Insert the contents of a string into the buffer at a specified position.intlength()Return the number of characters currently in the buffer.XStringBufBasereplace(int start, int end, java.lang.String str)Replace the characters in a substring of this buffer with characters in the specified String.booleanreplace(java.lang.String substring, char replacement)Replace the first occurrence of a given substring in the buffer with a given characterbooleanreplace(java.lang.String substring, java.lang.String replacement)Replace the first occurrence of a given substring in the buffer with another substring.intreplaceAll(char ch, char replacement)Replace the all occurrences of a given character in the buffer with another character.intreplaceAll(char ch, java.lang.String replacement)Replace the all occurrences of a given character in the buffer with string.intreplaceAll(java.lang.String substring, java.lang.String replacement)Replace the all occurrences of a given substring in the buffer with another substring.voidreset(java.lang.String str)Removes all existing characters from the buffer and loads the string into the buffer.java.lang.String[]split()Split the contents of a buffer on white space, and return the resulting strings.java.lang.String[]split(char delim)Split the contents of a buffer on a delimiter, and return the resulting strings.intsplit(char delim, java.util.Collection<java.lang.String> collection)Split the contents of a buffer on a delimiter, and store the resulting strings in a specified Collection.java.lang.String[]split(java.lang.String delimSet)Split the contents of a buffer on a delimiter, and return the resulting strings.intsplit(java.lang.String delimSet, java.util.Collection<java.lang.String> collection)Split the contents of a buffer on a delimiter, and store the resulting strings in a specified Collection.java.lang.CharSequencesubSequence(int start, int end)Return a new CharSequence object (really, another XStringBuffer0 that contains a subsequence of characters currently contained in this buffer.java.lang.Stringsubstring(int index)Return a new String that contains a subsequence of characters currently contained in this buffer.java.lang.Stringsubstring(int start, int end)Return a new String that contains a subsequence of characters currently contained in this buffer.java.lang.StringtoString()Return the String representation of this buffer.
-
-
-
Field Detail
-
METACHAR_SEQUENCE_START
public static final char METACHAR_SEQUENCE_START
The character that denotes the start of a metacharacter sequence.- See Also:
- Constant Field Values
-
-
Method Detail
-
getChars
public abstract void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) throws java.lang.IndexOutOfBoundsExceptionCopy the some or all of the contents of the buffer into a character array. The first character to be copied is at index srcBegin; the last character to be copied is at index (srcEnd - 1). The total number of characters to be copied is (srcEnd - srcBegin). The characters are copied into the subarray of dst starting at index dstBegin and ending at index (dstBegin + (srcEnd - srcBegin) - 1).- Parameters:
srcBegin- Start copy from this offset in the string buffersrcEnd- Stop copy from this offset in the string bufferdst- Where to copy the characters.dstBegin- Offset into dst- Throws:
java.lang.IndexOutOfBoundsException- invalid index
-
append
public XStringBufBase append(boolean val)
Append the string representation of a boolean value to the buffer.- Parameters:
val- The boolean value.- Returns:
- a reference to this object
-
append
public XStringBufBase append(char c)
Append the specified character to the buffer. If the buffer is already at its maximum length, the character is silently ignored.- Specified by:
appendin interfacejava.lang.Appendable- Parameters:
c- The character to append.- Returns:
- a reference to this object
- Throws:
java.io.IOException- I/O error
-
append
public XStringBufBase append(char[] chars)
Append the specified array of characters to the buffer. This method appends only as much of the string as will fit without causing the buffer to exceed its maximum length.- Parameters:
chars- The characters to append.- Returns:
- a reference to this object
-
append
public XStringBufBase append(char[] chars, int offset, int len)
Append the specified characters in a character array to the buffer. This method appends only as much of the string as will fit without causing the buffer to exceed its maximum length.- Parameters:
chars- The characters to append.offset- The index of the first character to appendlen- The maximum number of characters to append- Returns:
- a reference to this object
-
append
public XStringBufBase append(double val)
Append the string representation of a double value to the buffer.- Parameters:
val- The double value.- Returns:
- a reference to this object
-
append
public XStringBufBase append(float val)
Append the string representation of a float value to the buffer.- Parameters:
val- The float value.- Returns:
- a reference to this object
-
append
public XStringBufBase append(int val)
Append the string representation of a int value to the buffer.- Parameters:
val- The int value.- Returns:
- a reference to this object
-
append
public XStringBufBase append(long val)
Append the string representation of a long value to the buffer.- Parameters:
val- The long value.- Returns:
- a reference to this object
-
append
public XStringBufBase append(java.lang.Object obj)
Append the string representation of an object to the buffer.- Parameters:
obj- The object whose string value is to be appended.- Returns:
- a reference to this object
-
append
public XStringBufBase append(short val)
Append the string representation of a short value to the buffer.- Parameters:
val- The short value.- Returns:
- a reference to this object
-
append
public XStringBufBase append(java.lang.String s)
Append the specified string to the buffer. This method appends only as much of the string as will fit without causing the buffer to exceed its maximum length.- Parameters:
s- The string to append.- Returns:
- a reference to this object
-
append
public XStringBufBase append(java.lang.CharSequence csq)
Append the entire contents of the specified CharSequence to the buffer. This method appends only as much of the CharSequence as will fit without causing the buffer to exceed its maximum length.- Specified by:
appendin interfacejava.lang.Appendable- Parameters:
csq- The CharSequence to append- Returns:
- a reference to this object
- See Also:
append(CharSequence,int,int)
-
append
public XStringBufBase append(java.lang.CharSequence csq, int start, int end)
Append a subsequence of the specified CharSequence to the buffer. This method appends only as much of the subsequence as will fit without causing the buffer to exceed its maximum length.- Specified by:
appendin interfacejava.lang.Appendable- Parameters:
csq- The CharSequence to appendstart- The starting index of the subsequenceend- One past the ending index of the subsequence- Returns:
- a reference to this object
- See Also:
append(CharSequence)
-
charAt
public char charAt(int index) throws java.lang.IndexOutOfBoundsExceptionReturn the character at a specified index in the buffer. Indexes begin at 0. (i.e., The first character in the buffer has index 0.)- Specified by:
charAtin interfacejava.lang.CharSequence- Parameters:
index- The index of the character to return- Returns:
- The character at the specified index.
- Throws:
java.lang.IndexOutOfBoundsException- if index is negative or greater than or equal to length()
-
delete
public boolean delete(java.lang.String substring)
Delete the first occurrence of a given substring in the buffer. with another substring.- Parameters:
substring- The substring to find and replace- Returns:
- true if the replacement succeeded, false otherwise.
-
clear
public void clear()
Removes all characters from the buffer leaving it empty.
-
delete
public XStringBufBase delete(int start, int end) throws java.lang.IndexOutOfBoundsException
Remove the characters in a substring of this XStringBuffer. The substring begins at the specified start and extends to the character at index end - 1, or to the end of the string, if no such character exists. If start is equal to end, no changes are made.- Parameters:
start- The beginning index, inclusiveend- The ending index, exclusive- Returns:
- This object
- Throws:
java.lang.IndexOutOfBoundsException- if start is negative, greater than length(), or greater than end
-
encodeMetacharacters
public void encodeMetacharacters(int start, int end) throws java.lang.IndexOutOfBoundsException, java.io.IOExceptionReplaces certain characters in the string buffer with Java metacharacter ("backslash") sequences.
- A horizontal tab is replaced with \t.
- A line feed is replaced with \n.
- A carriage return is replaced with \r.
- A form feed is replaced with \f.
- A backslash is replaced by two backslashes.
- Nonprintable characters are replaced with a \uxxxx sequence.
This method uses the same definition of "non-printable" as
TextUtil.isPrintable(char).- Parameters:
start- The beginning index, inclusiveend- The ending index, exclusive- Throws:
java.lang.StringIndexOutOfBoundsException- if start is negative, or greater than length(), or greater than endjava.io.IOException- I/O exceptionjava.lang.IndexOutOfBoundsException- See Also:
encodeMetacharacters(),decodeMetacharacters(int, int)
-
encodeMetacharacters
public void encodeMetacharacters()
A version ofencodeMetacharactersthat processes the entire string buffer. Calling this method is equivalent to:buf.encodeMetacharacters (0, buf.length())
-
decodeMetacharacters
public void decodeMetacharacters(int start, int end) throws java.lang.StringIndexOutOfBoundsExceptionReplaces any metacharacter sequences in a portion of the string buffer (such as those produced byencodeMetacharacters()with their actual characters.- Parameters:
start- The beginning index, inclusiveend- The ending index, exclusive- Throws:
java.lang.StringIndexOutOfBoundsException- if start is negative, or greater than length(), or greater than end- See Also:
decodeMetacharacters(),encodeMetacharacters(int,int)
-
decodeMetacharacters
public void decodeMetacharacters()
A version ofdecodeMetacharactersthat processes the entire string buffer. Calling this method is equivalent to:buf.decodeMetacharacters (0, buf.length())
-
indexOf
public int indexOf(int ch)
Returns the index within this string of the first occurrence of the specified character. If a character with value ch occurs in the character sequence represented by this object, then the index (in Unicode code units) of the first such occurrence is returned.- Parameters:
ch- the cahracter (Unicode code point)- Returns:
- the index of the first occurrence of the character, or -1 if not found
-
indexOf
public int indexOf(java.lang.String str)
Returns the index within this string of the first occurrence of the specified substring in this sequence, starting at position 0.- Parameters:
str- the string to find- Returns:
- the index of the first occurrence of the substring, or -1 if not found
-
indexOf
public int indexOf(java.lang.String str, int start)Returns the index within this string of the first occurrence of the specified substring in this sequence, with the search starting at the specified position.- Parameters:
str- the string to findstart- the index at which to start the search- Returns:
- the index of the first occurrence of the substring, or -1 if not found
-
insert
public XStringBufBase insert(int index, boolean val)
Insert the string representation of a booleanvalue into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferval- The boolean value
-
insert
public XStringBufBase insert(int index, char ch)
Insert a single character at a specified position in the buffer. Note that an insertion operation may push * characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferch- The character to insert.
-
insert
public XStringBufBase insert(int index, char[] chars)
Insert the contents of a character array into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferchars- The character array.
-
insert
public XStringBufBase insert(int index, char[] chars, int offset, int len)
Insert characters from a character array into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferchars- The character array.offset- The index of the first character to insertlen- The maximum number of characters to insert
-
insert
public XStringBufBase insert(int index, double val)
Insert the string representation of a doublevalue into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferval- The double value
-
insert
public XStringBufBase insert(int index, float val)
Insert the string representation of a floatvalue into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferval- The float value
-
insert
public XStringBufBase insert(int index, int val)
Insert the string representation of a intvalue into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferval- The int value
-
insert
public XStringBufBase insert(int index, long val)
Insert the string representation of a longvalue into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferval- The long value
-
insert
public XStringBufBase insert(int index, short val)
Insert the string representation of a shortvalue into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferval- The short value
-
insert
public XStringBufBase insert(int index, java.lang.Object obj)
Insert the string representation of an arbitrary object into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string bufferobj- The object whose string representation is to be inserted
-
insert
public XStringBufBase insert(int index, java.lang.String s)
Insert the contents of a string into the buffer at a specified position. Note that an insertion operation may push characters off the end of the buffer.- Parameters:
index- Where to start inserting in the string buffers- The string to insert
-
length
public int length()
Return the number of characters currently in the buffer.- Specified by:
lengthin interfacejava.lang.CharSequence- Returns:
- The number of characters in the buffer.
-
replace
public XStringBufBase replace(int start, int end, java.lang.String str) throws java.lang.StringIndexOutOfBoundsException
Replace the characters in a substring of this buffer with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1, or to the end of the XStringBuffer if no such character exists. First the characters in the substring are removed and then the specified String is inserted at start. (The XStringBuffer will be lengthened to accommodate the specified String if necessary.)- Parameters:
start- The beginning index, inclusiveend- The ending index, exclusivestr- The string that will replace the previous contents- Returns:
- This object
- Throws:
java.lang.StringIndexOutOfBoundsException- if start is negative, or greater than length(), or greater than end
-
replace
public boolean replace(java.lang.String substring, java.lang.String replacement)Replace the first occurrence of a given substring in the buffer with another substring.- Parameters:
substring- The substring to find and replacereplacement- The replacement string- Returns:
- true if the replacement succeeded, false otherwise.
-
replace
public boolean replace(java.lang.String substring, char replacement)Replace the first occurrence of a given substring in the buffer with a given character- Parameters:
substring- The substring to find and replacereplacement- The replacement char- Returns:
- true if the replacement succeeded, false otherwise.
-
replaceAll
public int replaceAll(java.lang.String substring, java.lang.String replacement)Replace the all occurrences of a given substring in the buffer with another substring. This method avoids recursion; that is, it's safe even if the replacement string contains the source string.- Parameters:
substring- The substring to find and replacereplacement- The replacement string- Returns:
- the number of replacements made
-
replaceAll
public int replaceAll(char ch, char replacement)Replace the all occurrences of a given character in the buffer with another character.- Parameters:
ch- The character to find and replacereplacement- The replacement character- Returns:
- the number of replacements made
-
replaceAll
public int replaceAll(char ch, java.lang.String replacement)Replace the all occurrences of a given character in the buffer with string. This method avoids recursion; that is, it's safe even if the replacement string contains the character being replaced.- Parameters:
ch- The character to find and replacereplacement- The replacement string- Returns:
- the number of replacements made
-
reset
public void reset(java.lang.String str)
Removes all existing characters from the buffer and loads the string into the buffer.- Parameters:
str- String object to be loaded into the cleared buffer.
-
split
public java.lang.String[] split()
Split the contents of a buffer on white space, and return the resulting strings. This method is a convenient front-end toTextUtil.split(String).- Returns:
- an array of String objects
- See Also:
split(String),TextUtil.split(String,char)
-
split
public java.lang.String[] split(char delim)
Split the contents of a buffer on a delimiter, and return the resulting strings. This method is a convenient front-end toTextUtil.split(String,char).- Parameters:
delim- the delimiter- Returns:
- an array of String objects
- See Also:
split(String),TextUtil.split(String,char)
-
split
public java.lang.String[] split(java.lang.String delimSet)
Split the contents of a buffer on a delimiter, and return the resulting strings. This method is a convenient front-end toTextUtil.split(String,String)- Parameters:
delimSet- the delimiter set- Returns:
- an array of String objects
- See Also:
split(char),TextUtil.split(String,String)
-
split
public int split(char delim, java.util.Collection<java.lang.String> collection)Split the contents of a buffer on a delimiter, and store the resulting strings in a specified Collection. This method is a convenient front-end forTextUtil.split(String,char,Collection).- Parameters:
delim- the delimitercollection- where to store the resulting strings- Returns:
- the number of strings added to the collection
- See Also:
split(String,Collection),split(char),TextUtil.split(String,char),TextUtil.split(String,String,Collection)
-
split
public int split(java.lang.String delimSet, java.util.Collection<java.lang.String> collection)Split the contents of a buffer on a delimiter, and store the resulting strings in a specified Collection. This method is a convenient front-end forTextUtil.split(String,char,Collection).- Parameters:
delimSet- the set of delimiterscollection- where to store the resulting strings- Returns:
- the number of strings added to the collection
- See Also:
split(char,Collection),split(String),TextUtil.split(String,String),TextUtil.split(String,char,Collection)
-
substring
public java.lang.String substring(int index) throws java.lang.StringIndexOutOfBoundsExceptionReturn a new String that contains a subsequence of characters currently contained in this buffer. The substring begins at the specified index and extends to the end of the StringBuffer.- Parameters:
index- The beginning index, inclusive- Returns:
- the substring
- Throws:
java.lang.StringIndexOutOfBoundsException- index out of range
-
substring
public java.lang.String substring(int start, int end) throws java.lang.StringIndexOutOfBoundsExceptionReturn a new String that contains a subsequence of characters currently contained in this buffer. The substring begins at the specified start and extends to the character at index end - 1.- Parameters:
start- The beginning index, inclusiveend- The beginning index, exclusive- Returns:
- the substring
- Throws:
java.lang.StringIndexOutOfBoundsException- if start is negative, greater than length(), or greater than end- See Also:
subSequence(int, int)
-
subSequence
public java.lang.CharSequence subSequence(int start, int end) throws java.lang.IndexOutOfBoundsExceptionReturn a new CharSequence object (really, another XStringBuffer0 that contains a subsequence of characters currently contained in this buffer. The substring begins at the specified start and extends to the character at index end - 1.- Specified by:
subSequencein interfacejava.lang.CharSequence- Parameters:
start- The beginning index, inclusiveend- The beginning index, exclusive- Returns:
- the subsequence
- Throws:
java.lang.IndexOutOfBoundsException- if start is negative, greater than length(), or greater than end
-
toString
public java.lang.String toString()
Return the String representation of this buffer.- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object- Returns:
- The string.
-
-
DMelt 3.0 © DataMelt by jWork.ORG