borland Packages Class Hierarchy jb.util Package
java.lang.Object +----com.borland.jb.util.FastStringBuffer
Variables Constructors Properties MethodsUse the
FastStringBuffer
component to replace use of the StringBuffer
class in those instances when a buffer is not shared. It removes some of the complications of synchronization and sharing.
FastStringBuffer
methods are synchronized, these methods should not be used for objects which may be accessed simultaneously. FastStingBuffer
is intended for rapid processing on local objects.
public static final int NOT_A_CHAR = 0The given character is invalid.
public static final int NOTACHAR = 0A fetch has run out of bounds.
public FastStringBuffer()Constructs a
FastStringBuffer
object with a default length of 16 characters (char[16]). The offset and count are initialized to 0.
public FastStringBuffer(char c, int nChars)Constructs
FastStringBuffer
using the given number of repetitions and the given character. The initial capacity of the buffer is equal to the number of repetitions.
c
FastStringBuffer
with.
nChars
public FastStringBuffer(char[] cArray)Constructs
FastStringBuffer
with the given character. The initial capacity of the buffer is equal to the given character plus 16.
cArray
FastStringBuffer
with.
public FastStringBuffer(char[] cArray, int offset, int len)Constructs
FastStringBuffer
from the given character with the specified number of characters.
The initial capacity of the buffer is equal to the specified number of characters plus 16.
cArraay
FastStringBuffer
with.
offset
FastStringBuffer
.
len
public FastStringBuffer(int length)Constructs an empty
FastStringBuffer
of the given length.
length
public FastStringBuffer(String str)Constructs a new
FastStringBuffer
from the given string. The initial contents of the buffer are a copy of str
. The initial capacity of the buffer is equal to the length of the string plus 16.
str
FastStringBuffer
from.
public final int getLength() public final void setLength(int newLength)Number of characters in the
FastStringBuffer
.
public int getOffset() public void setOffset(int offset)Current position in
FastStringBuffer
. See nextChar()
for more information.
public char[] getValue()Returns the
char[]
storage used by FastStringBuffer
.
public final FastStringBuffer append(char c)Appends the string representation of the specified character to
FastStringBuffer
. The length of the buffer is increased by 1.
c
public final FastStringBuffer append(char c1, char c2, char c3, char c4)Appends the string representation of the specified characters to
FastStringBuffer
. The length of the buffer is increased by 4.
c1, c2, c3, c4
public final FastStringBuffer append(char c1, char c2, char c3, char c4, char c5)Appends the string representation of the specified characters to
FastStringBuffer
. The length of the buffer is increased by 5.
c1, c2, c3, c4, c5
public FastStringBuffer append(char c, int appendCount)Appends the given number of repetitions of the given character to
FastStringBuffer
. The length of the buffer is increased by appendCount
.
c
appendCount
public FastStringBuffer append(char[] str)Appends the string representation of the specified string to
FastStringBuffer
. The length of the buffer is increased by the number of characters in the string.
str
public FastStringBuffer append(char[] str, int offset, int len)Appends the string representation of the specified string at the given offset for the given count.
FastStringBuffer
is increased by the length of the string.
str
offset
len
public FastStringBuffer append(FastStringBuffer fsb)Apends one
FastStringBuffer
to another one. The original FastStringBuffer
is increased by the length of the new buffer.
fsb
public FastStringBuffer append(Object obj)Appends the given object to
FastStringBuffer
.
obj
public final FastStringBuffer append(String str)Appends the string representation of the specified string to
FastStringBuffer
.
str
public int capacity()Returns the current capacity of
FastStringBuffer
.
public char charAt(int index)Returns the character at the given position.
index
FastStringBuffer
.
public static char charFromString(String s)Returns the first "logical" char value from the given
String
. This means that it handles backslashes, Unicode escape sequences, and so on.
public static String charToUnicodeEscape(char ch)Returns a
String
containing a Unicode escape sequence representing the given character. For example, charToUnicodeEscape('1')
returns new String("\\u0031")
.
ch
public char currentChar()Returns the character at
offset
. Note that this method starts at the current offest.
This method returns NOTACHAR
if empty.
public void empty()Nulls the
FastStringBuffer
.
public static FastStringBuffer expandDelimiters(String sourceString, String delimiters)Creates a copy of the given
FastStringBuffer
, but translates any characters in the specified delimiter set into Unicode "escape" sequences. This allows the new FastStringBuffer
to use the normal StringTokenizer
for parsing. This method returns a new FastStringBuffer
containing all the characters of the source String
, but with all delimiters expanded to Unicode escape sequences.
sourceString
String
to be scanned and converted (this String
itself is not altered).
delimiters
String
consisting of the delimiters you don't want to see in the output StringBuffer
, for example,
new String("\t\r\n,")
Wherever these occur in the sourceString
, they are converted to a Unicode escape sequence.
public char firstChar()Sets
offset()
to 0 and returns to the first character in the buffer. This method is used for loops with lastChar()
.
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)Copies characters from
FastStringBuffer
into the destination character array.
The first character to be copied is at srcBegin
. The last character to be copied is at srcEnd
-1; making the total number of characters to be copied srcEnd
- srcBegin
. The characters are copied into the subarray of dst
starting at dstBegin
and ending at index:
dstbegin + (srcEnd-srcBegin) - 1This method throws a
StringIndexOutOfBoundsException
if:
srcBegin
is negative.
srcBegin
is greater than srcEnd
.
srcEnd
is greater than the length of this string.
dstBegin
is negative.
dstBegin+(srcEnd-srcBegin)
is larger than dst.length
.
srcBegin
srcEnd
dst
dstBegin
public int indexOf(FastStringBuffer subStr, int fromIndex)Returns the index within
FastStringBuffer
of the first occurrence of subStr
, starting at the specified index.
There is no restriction on the value of fromIndex
:
subString
fromIndex
public int IndexOfSubString(FastStringBuffer subStr, int fromIndex)Finds the index in the given
FastStringBuffer
where the specified sub-string begins. Returns -1 if the string is not found.
subStr
fromIndex
public FastStringBuffer insert(int offset, boolean b)Inserts the string representation of the given boolean into
FastStringBuffer
at the given offset position.
The length of the buffer is increased by the length of b
.
offset
b
public FastStringBuffer insert(int offset, char c)Inserts the string representation of the given character into
FastStringBuffer
at the given position.
The length of the buffer is increased by 1.
offset
c
public FastStringBuffer insert(int offset, char[] str)Inserts the string representation of the specified character string into
FastStringBuffer
at the given offset position.
The length of the buffer increases by the length of the string.
offset
str
public FastStringBuffer insert(int offset, Object obj)Inserts the string representation of the given object into
FastStringBuffer
at the given offset position.
The length of the buffer increases by the length of the object.
offset
obj
public FastStringBuffer insert(int offset, String str)Inserts the string representation of the given string into
FastStringBuffer
at the given offset position.
The length of the buffer increases by the length of the string.
offset
str
public char lastChar()Moves the
offset()
to the last character in FastStringBuffer
and returns that character.
Meant to be used as lastChar()/priorChar()
loop.
This method returns NOTACHAR
if empty.
public int lastIndexOf(FastStringBuffer subStr, int fromIndex)Returns the index within
FastStringBuffer
of the last occurrence of subStr
. The returned index indicates the start of the substring, and it must be equal to or less than fromIndex
.
There is no restriction on the value of fromIndex
:
subStr
fromIndex
public final int length()Returns the number of actual characters in
FastStringBuffer
.
public final void makeroom(int needed)Increases the size of the
FastStringBuffer
so that it will hold at least the given number of characters.
minimumCapacity
public char nextChar()Moves the
offset()
to the next sequential character in FastStringBuffer
and returns that character.
public FastStringBuffer normalizeDelimiters(String delimiters)Turns any Unicode escape sequences that would result in one of the given delimiter characters into the displayable form of that delimiter. This method is the opposite of
expandDelimiters
.
delimeters
public int offset()Internal current position in
FastStringBuffer
used by the following methods:
public char parseBackSlash()Given a
FastStringBuffer
where charAt()
, nextChar()
or priorChar()
have just returned the backslash character (in other words, where value[offset] == '\\')
, this routine parses the rest as a single character backslash value (for example, "?") and advances the offset. It returns that character and leaves the FastStringBuffer
pointing at the next character after the value.
public FastStringBuffer parseLiteral()Given a
String
which needs to be parsed as a literal String
(including backslash characters), and assuming that value[offset]
is currently pointing at the starting delimiter of this String
, this routine buffers everything up to (but not including) another delimiter like the first. It advances the offset past that delimiter so that subsequent string processing can continue. It returns a new FastStringBuffer
containing the literal.
public FastStringBuffer parseLiteral(char delimiter, boolean allowDouble)Given a string which needs to be parsed as a literal string (including backslash characters), and assuming
value[offset]
is currently pointing at the starting delimiter of this string, this routine buffers everything up to (but not including) another delimiter like the first. It advances the offset past that delimiter so subsequent string processing can continue. It returns a new FastStringBuffer
containing the literal.
delimiter
allowDouble
public char peekNextChar()Peeks at the next character
without
advancing any pointers. Used in a firstChar()/nextChar()
type loop.
public char priorChar()Moves the
offset()
to the previous sequential character in FastStringBuffer
and returns that character. Meant to be used as lastChar()/priorChar()
loop. This method returns NOTACHAR
if empty.
public void removeChar()Removes the "current" character from the buffer, where "current" is defined by 'offset'. It is intended to be used in a
firstChar()/nextChar()
loop. It adjusts 'offset' so that the next nextChar()
method call functions properly.
public void removeCharAt(int index)Removes the character from the buffer at
index
. It adjusts index
so a nextChar()
loop finds the character immediately following the one removed.
index
public void removeChars(int removeCount)Removes the specified number of characters from the current position (where "current" is defined as
value[offset]
). It adjusts 'offset' so that the next nextChar()
method call encounters the next character in the buffer.
removeCount
public void removeCharsAt(int index, int removeCount)Removes the specified number of characters from the buffer at the specified buffer at
index
. It adjusts index
so a nextChar()
loop finds the character immediately following the one removed.
index
removeCount
public void replaceCharAt(int index, char c)Replaces the character at the given position with the given character.
index
c
public void setCharAt(int index, char ch)Sets the character at the given index position to the given character.
index
FastStringBuffer
.
c
public static FastStringBuffer sourceToText(String source)Translates a
String
which is compatible with source code (including leading and trailing quote, expands backslash charaters, and so on) into its actual String
representation. For example, the literal "\n" becomes the real linefeed character.
source
String
to translate.
public static String stringFromChar(char c)Returns a
String
which best represents the given character. This means that it expands it into a Unicode escape sequence if needed. This method is the opposite of charFromString()
.
c
public FastStringBuffer substring(int startPos, int endPos)Returns a new string that is a substring of this string. The substring begins at the specified
startPos
and extends to the character at
endPos
- 1. Thus the length of the substring is startPos
- endPos
.
startPos
endPos
public static FastStringBuffer textToSource(String text, boolean hasEscapes)Converts a
String
into a form that compiles, translating special characters into their backslash-combination equivalents, and adding leading and trailing quotes.
public static FastStringBuffer textToSource(String text, boolean hasEscapes, String indentString)Converts a
String
into a form that compiles, translating special characters into their backslash-combination equivalents, and adding leading and trailing quotes. Adds the specified number of indent spaces to the beginning of the string.
public String toString()Converts
FastStringBuffer
to a string.
public char[] value()Returns the internal character string used by
FastStringBuffer
.