Novell exteNd
Director 5.2 API

com.sssw.fw.util
Class EboEditBuffer

java.lang.Object
 |
 +--com.sssw.fw.util.EboEditBuffer

public class EboEditBuffer
extends Object

This is a utility class that is a variant of a string buffer optimized for text replacement operations


Constructor Summary
EboEditBuffer()
          Constructor of EboEditBuffer
EboEditBuffer(int len)
          Constructor of EditBuffer with an input parameter
EboEditBuffer(String str)
          Constructor of EboEditBuffer with an input parameter
 
Method Summary
 EboEditBuffer append(boolean b)
          Appends a specified boolean to the end of the edit buffer.
 EboEditBuffer append(char c)
          Appends a specified character to the end of the edit buffer.
 EboEditBuffer append(double d)
          Appends a specified double to the end of the edit buffer.
 EboEditBuffer append(float f)
          Appends a specified float to the end of the edit buffer.
 EboEditBuffer append(int i)
          Appends a specified int to the end of the edit buffer.
 EboEditBuffer append(long l)
          Appends a specified long to the end of the edit buffer.
 EboEditBuffer append(String str)
          Appends a specified string to the end of the edit buffer.
 char charAt(int index)
          Gets a character at the specified index from the text.
 EboEditBuffer delete(int offset, int count)
          Deletes the bytes from the buffer based on a specified index and lengh.
 void ensureCapacity(int minsize)
          Ensures that the edit buffer has enough space to provide text editing.
 void escape(String escapeCharacters)
          Escapes all characters in the list of escape characters with a backslash
 int fixLineTerminators(int startpos, int count)
          Scans a sequence of characters in the buffer and ensures that all line terminators are LF (\n).
 char[] getBuffer()
          Gets the actual text from this edit buffer instance.
 CharacterIterator getCharacterIterator(boolean codeeditor)
          Creates a Character Iterator for this edit buffer.
 void getChars(char[] tobuf, int tooffset, int fromoffset, int count)
          Copies specified number of chareacters from a specified index in the edit buffer to a specified index in the specified output character buffer.
 char[] getChars(int fromoffset, int count)
          Gets the specified number of characters from the edit buffer starting from a specified index.
 int indexOf(int ch, int fromIndex)
          Returns the index within this string of the first occurrence of the specified character, starting the search at fromIndex.
 int indexOf(String s, int fromIndex)
          Returns the index within this string of the first occurrence of the specified String, starting the search at fromIndex.
 int indexOf(String s, int fromIndex, boolean casesensitive)
          Returns the index within this string of the first occurrence of the specified String, starting the search at fromIndex.
 EboEditBuffer insert(int offset, boolean b)
          Inserts a boolean value into the edit buffer starting from a specified index.
 EboEditBuffer insert(int inspos, char c)
          Inserts a character to the edit buffer starting from a specified index.
 EboEditBuffer insert(int offset, double d)
          Inserts a specified double to the edit buffer starting from a specified index.
 EboEditBuffer insert(int offset, float f)
          Inserts a float to the edit buffer starting from a specified index.
 EboEditBuffer insert(int offset, int i)
          Inserts an int to the edit buffer starting from a specified index.
 EboEditBuffer insert(int offset, long l)
          Inserts a long to the edit buffer starting from a specified index.
 EboEditBuffer insert(int offset, String str)
          Inserts a specified string to the edit buffer starting from a specified index.
 int insertFromReader(Reader r, int inspos)
          Inserts the entire contents of the reader into the buffer.
 int lastIndexOf(String s, int fromIndex)
          Returns the index within this string of the last occurrence of the specified String, searching backward from fromIndex.
 int lastIndexOf(String s, int fromIndex, boolean casesensitive)
          Returns the index within this string of the last occurrence of the specified String, searching backward from fromIndex.
 int length()
          Gets the actual text size.
 EboEditBuffer munge(int inspos, int delcount, char[] bytes, int firstbytetoinsert, int inscount)
          Cuts and Pastes the edit buffer starting from specified index.
 EboEditBuffer munge(int offset, int delCount, EboEditBuffer srcbuffer, int firstbytetoinsert, int insCount)
          Cuts and Pastes the edit buffer starting from specified index.
 EboEditBuffer munge(int inspos, int delcount, String str)
          Cuts and Pastes the edit buffer starting from specified index.
 void replace(int start, int end, String replace)
          Replaces a substring specified by its start and end character locations with another string.
 void replace(String find, String replace)
          Replaces all occurrences of one string with another.
 void replace(String find, String replace, String wordChars)
          Replaces all occurrences of one a whole word string with another.
 void replaceIgnoreCase(String find, String replace)
          Replaces all occurrences of one string with another ignoring case when matching the 'find' string.
 EboEditBuffer reset(String str)
          Resets the edit buffer with provided text string.
 EboEditBuffer reverse()
          Reverses the characters in this buffer
 void setCharAt(int index, char c)
          Modifies the edit buffer by storing the input character at specified index.
 void setLength(int length)
          Sets the length of the text in edit buffer.
 String substring(int fromoffset)
          Gets a substring from the edit buffer starting from a specified index.
 String substring(int fromoffset, int endoffset)
          Gets a substring from the edit buffer starting and ending from specified indics.
 String toString()
          Gets the text String from the edit buffer.
 String toString(int start, int count)
          Gets the SubString from the edit buffer based on a starting index and a length.
 void translateBuffer(String[] args)
          Performs string substitution based on an array of supplied substitution strings.
 void translateBufferEx(Object[] args)
          This version of translate buffer translates Object arguments and has no limit on the number of substitutions.
 void unescape(String escapeCharacters)
          Undoes the effect of the 'escape' method
 void uniEscape(String escapeCharacters)
          No information available
 void uniEscape(String escapeCharacters, boolean toASCII)
          No information available
 void uniUnescape()
          The opposite of uniEscape - turns É into É, \\ into \, etc.
 void writeChars(Writer writer)
          Writes the characters from the edit buffer to a Writer object.
 void writeChars(Writer writer, int pos, int count)
          Writes the characters from the edit buffer to a Writer object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EboEditBuffer

public EboEditBuffer()
Constructor of EboEditBuffer

EboEditBuffer

public EboEditBuffer(String str)
Constructor of EboEditBuffer with an input parameter
Parameters:
str - a String to be used by this edit buffer

EboEditBuffer

public EboEditBuffer(int len)
Constructor of EditBuffer with an input parameter
Parameters:
len - a increment size that is used to expand the edit buffer when the buffer is full.
Method Detail

length

public int length()
Gets the actual text size.

toString

public String toString()
Gets the text String from the edit buffer.
Overrides:
toString in class Object

toString

public String toString(int start,
                       int count)
Gets the SubString from the edit buffer based on a starting index and a length.
Parameters:
start - a position to start
count - the size from starting position.

getCharacterIterator

public CharacterIterator getCharacterIterator(boolean codeeditor)
Creates a Character Iterator for this edit buffer.
Parameters:
codeeditor - if set to true it considers the text as Java code, treats the special characters '-' and '.' as word break characters.

charAt

public char charAt(int index)
Gets a character at the specified index from the text. May throw StringIndexOutofBoundsException if specified index is less than 0 or greater than the actual text size.
Parameters:
index -  

setCharAt

public void setCharAt(int index,
                      char c)
Modifies the edit buffer by storing the input character at specified index. May throw StringIndexOutOfBoundsException if the index is less than 0 or greater than the actual text size.
Parameters:
index - a specified index
c - a character need to be stored at the specified location

getChars

public void getChars(char[] tobuf,
                     int tooffset,
                     int fromoffset,
                     int count)
Copies specified number of chareacters from a specified index in the edit buffer to a specified index in the specified output character buffer.
Parameters:
tobuf - an output character buffer.
tooffset - a start index of the output character buffer where the characters are copied to.
fromoffset - a start index of the edit buffer where the characters start to be copied.
count - a number of characters to be copied.

getChars

public char[] getChars(int fromoffset,
                       int count)
Gets the specified number of characters from the edit buffer starting from a specified index.
Parameters:
fromoffset - a start index of the edit buffer that the characters start to be copied.
count - a number of charactered to be copied.
Returns:
a character array with the copied characters.

substring

public String substring(int fromoffset)
Gets a substring from the edit buffer starting from a specified index.
Parameters:
fromoffset - a start index of the edit buffer where the substring starts to be copied.
Returns:
the specified substring.

substring

public String substring(int fromoffset,
                        int endoffset)
Gets a substring from the edit buffer starting and ending from specified indics.
Parameters:
fromoffset - a start index of the edit buffer where the substring starts to be copied.
endoffset - an end index of the edit buffer where the substring ends.
Returns:
the specified substring.

reset

public EboEditBuffer reset(String str)
Resets the edit buffer with provided text string.
Parameters:
str - a text String to be replaced in the edit buffer.
Returns:
the modified EboEditBuffer object with the replaced text String.

setLength

public void setLength(int length)
Sets the length of the text in edit buffer. If the actual text length in the edit buffer is less than specified length, nulls (0s) will be filled to expand the actual text. If provided length is less than 0, nothing happens.
Parameters:
length - a specified length

insert

public EboEditBuffer insert(int offset,
                            String str)
Inserts a specified string to the edit buffer starting from a specified index.
Parameters:
offset - a start index of the edit buffer where the input string is copied to.
str - a specified string to be inserted into the edit buffer.
Returns:
the modified EboEditBuffer object with string inserted.

insert

public EboEditBuffer insert(int offset,
                            boolean b)
Inserts a boolean value into the edit buffer starting from a specified index.
Parameters:
offset - a start index to insert the boolean value
b - a boolean value to be inserted.
Returns:
the modified EboEditBuffer object with inserted character.

insert

public EboEditBuffer insert(int inspos,
                            char c)
Inserts a character to the edit buffer starting from a specified index.
Parameters:
inspos - an insert index
c - a specified character
Returns:
the modified EboEditBuffer object after inserting the character.

insert

public EboEditBuffer insert(int offset,
                            int i)
Inserts an int to the edit buffer starting from a specified index.
Parameters:
offset - a start index
i - a specified int
Returns:
the modified EboEditBuffer object after inserting the int.

insert

public EboEditBuffer insert(int offset,
                            long l)
Inserts a long to the edit buffer starting from a specified index.
Parameters:
offset - a start index
l - a specified long
Returns:
the modified EboEditBuffer object after inserting the long.

insert

public EboEditBuffer insert(int offset,
                            float f)
Inserts a float to the edit buffer starting from a specified index.
Parameters:
offset - a start index
f - a specified float
Returns:
the modified EboEditBuffer object after inserting the float.

insert

public EboEditBuffer insert(int offset,
                            double d)
Inserts a specified double to the edit buffer starting from a specified index.
Parameters:
offset - a start index
d - a specified double
Returns:
the modified EboEditBuffer object with inserted double

append

public EboEditBuffer append(String str)
Appends a specified string to the end of the edit buffer.
Parameters:
str - a specified string to be appended into the edit buffer.
Returns:
the modified EboEditBuffer object with the string appended.

append

public EboEditBuffer append(boolean b)
Appends a specified boolean to the end of the edit buffer.
Parameters:
b - a specified boolean to be appended into the edit buffer.
Returns:
the modified EboEditBuffer object with the boolean appended.

append

public EboEditBuffer append(char c)
Appends a specified character to the end of the edit buffer.
Parameters:
c - a specified character to be appended into the edit buffer.
Returns:
the modified EboEditBuffer object with the character appended.

append

public EboEditBuffer append(int i)
Appends a specified int to the end of the edit buffer.
Parameters:
i - a specified int to be appended into the edit buffer.
Returns:
the modified EboEditBuffer object with the int appended.

append

public EboEditBuffer append(long l)
Appends a specified long to the end of the edit buffer.
Parameters:
l - a specified long to be appended into the edit buffer.
Returns:
the modified EboEditBuffer object with the long appended.

append

public EboEditBuffer append(float f)
Appends a specified float to the end of the edit buffer.
Parameters:
f - a specified float to be appended into the edit buffer.
Returns:
the modified EboEditBuffer object with the float appended.

append

public EboEditBuffer append(double d)
Appends a specified double to the end of the edit buffer.
Parameters:
d - a specified double to be appended into the edit buffer.
Returns:
the modified EboEditBuffer object with the double appended.

delete

public EboEditBuffer delete(int offset,
                            int count)
Deletes the bytes from the buffer based on a specified index and lengh.
Parameters:
offset - an index where to start the delete operation.
count - a anumber of bytes to be deleted.
Returns:
the modified EboEditBuffer object after completing the delete operation.

writeChars

public void writeChars(Writer writer)
                throws IOException
Writes the characters from the edit buffer to a Writer object.
Parameters:
writer - a Writer object.

writeChars

public void writeChars(Writer writer,
                       int pos,
                       int count)
                throws IOException
Writes the characters from the edit buffer to a Writer object.
Parameters:
writer - a Writer object.
pos - a start index of the edit buffer where to start copying the text.
count - a number of bytes to be copied to the writer.

insertFromReader

public int insertFromReader(Reader r,
                            int inspos)
                     throws IOException
Inserts the entire contents of the reader into the buffer.
Parameters:
r - a Reader object.
inspos - a specified insert index where to start copy the contents.
Returns:
an integer that indicates how many characters are actually read from the input Reader object.

fixLineTerminators

public int fixLineTerminators(int startpos,
                              int count)
Scans a sequence of characters in the buffer and ensures that all line terminators are LF (\n). The return value is the modified count of characters following the start position.

munge

public EboEditBuffer munge(int inspos,
                           int delcount,
                           String str)
Cuts and Pastes the edit buffer starting from specified index. That is, starting from specified index, first cut the characters by specified count (delcount), and then substitute with the input string.
Parameters:
inspos - an insert index to starting this cut and paste operation.
delcount - number of characters to be removed from edit buffer starting from the specified insert index.
str - a string to be replaced starting from the specified insert index. if str is null, only cut operation is performed.
Returns:
the modified EboEditBuffer object after completing the cut and paste operation.

munge

public EboEditBuffer munge(int inspos,
                           int delcount,
                           char[] bytes,
                           int firstbytetoinsert,
                           int inscount)
Cuts and Pastes the edit buffer starting from specified index. That is, starting from specified index, first cut the characters by specified count (delcount), and then substitute with the input character array.
Parameters:
inspos - an insert index to starting this cut and paste operation.
delcount - number of characters to be removed from edit buffer starting from the specified insert index.
bytes - a character array to be replaced starting from the specified insert index.
firstbytetoinsert - a specified offset in the byte array for the bytes to be copied.
inscount - a number of bytes to be copied from the byte array to the edit buffer.
Returns:
the modified EboEditBuffer object after completing the cut and paste operation.

munge

public EboEditBuffer munge(int offset,
                           int delCount,
                           EboEditBuffer srcbuffer,
                           int firstbytetoinsert,
                           int insCount)
Cuts and Pastes the edit buffer starting from specified index. That is, starting from specified index, first cut the characters by specified count (delcount), and then substitute with the text from another edit buffer object.
Parameters:
inspos - an insert index to starting this cut and paste operation.
delcount - number of characters to be removed from edit buffer starting from the specified insert index.
srcbuffer - an edit buffer where the text will be copied into this edit buffer.
firstbytetoinsert - a specified offset in the edit buffer for the characters to be copied.
inscount - a number of bytes to be copied from the provided edit buffer to this edit buffer instance.
Returns:
the modified EboEditBuffer object after completing the cut and paste operation.

getBuffer

public char[] getBuffer()
Gets the actual text from this edit buffer instance.
Returns:
a character array of the actual text.

ensureCapacity

public void ensureCapacity(int minsize)
Ensures that the edit buffer has enough space to provide text editing.
Parameters:
minsize - a minimum size that the edit buffer should have. If not, it will expand the buffer to meet this criteria.

indexOf

public int indexOf(int ch,
                   int fromIndex)
Returns the index within this string of the first occurrence of the specified character, starting the search at fromIndex. This method returns -1 if the index is not found.
Parameters:
ch - the character to search for
fromIndex - the index to start the search from

indexOf

public int indexOf(String s,
                   int fromIndex)
Returns the index within this string of the first occurrence of the specified String, starting the search at fromIndex. This method returns -1 if the index is not found.
Parameters:
s - the string to search for
fromIndex - the index to start the search from

indexOf

public int indexOf(String s,
                   int fromIndex,
                   boolean casesensitive)
Returns the index within this string of the first occurrence of the specified String, starting the search at fromIndex. This method returns -1 if the index is not found.
Parameters:
s - the string to search for
fromIndex - the index to start the search from
casesensitive - if false, performs a case-insensitive match of the search string

lastIndexOf

public int lastIndexOf(String s,
                       int fromIndex)
Returns the index within this string of the last occurrence of the specified String, searching backward from fromIndex. This method returns -1 if the index is not found.
Parameters:
s - the string to search for
fromIndex - the index to start the search from

lastIndexOf

public int lastIndexOf(String s,
                       int fromIndex,
                       boolean casesensitive)
Returns the index within this string of the last occurrence of the specified String, searching backward from fromIndex. This method returns -1 if the index is not found.
Parameters:
s - the string to search for
fromIndex - the index to start the search from
casesensitive - if false, performs a case-insensitive match of the search string

replace

public void replace(int start,
                    int end,
                    String replace)
Replaces a substring specified by its start and end character locations with another string.
Parameters:
start - the start character location (inclusive)
end - the end character location (exclusive, same as substring): may be -1 to indicate insert
replace - the string to replace it with: may be null to indicate delete

replace

public void replace(String find,
                    String replace)
Replaces all occurrences of one string with another.
Parameters:
find - the string to find
replace - the string to replace it with

replaceIgnoreCase

public void replaceIgnoreCase(String find,
                              String replace)
Replaces all occurrences of one string with another ignoring case when matching the 'find' string.
Parameters:
find - the string to find
replace - the string to replace it with

replace

public void replace(String find,
                    String replace,
                    String wordChars)
Replaces all occurrences of one a whole word string with another.
Parameters:
find - the string to find
replace - the string to replace it with
wordChars - the characters outside of the alphabetic characters that can also be part of the word.

reverse

public EboEditBuffer reverse()
Reverses the characters in this buffer

escape

public void escape(String escapeCharacters)
Escapes all characters in the list of escape characters with a backslash

unescape

public void unescape(String escapeCharacters)
Undoes the effect of the 'escape' method

uniEscape

public void uniEscape(String escapeCharacters)
No information available

uniEscape

public void uniEscape(String escapeCharacters,
                      boolean toASCII)
No information available

uniUnescape

public void uniUnescape()
The opposite of uniEscape - turns É into É, \\ into \, etc. May throw an IndexOutOfBoundsException or NumberFormatException if the text is invalid or corrupt.

translateBuffer

public void translateBuffer(String[] args)
Performs string substitution based on an array of supplied substitution strings. The character string "%n" (where n is the a character 1-9), is replaced with the n-th element of the substitution array. If index is beyond the end of the array, or the array element is null, then an empty string is substituted.
The character sequence %% may be used if it is necessary to "escape" a percent sign character (only necessary if followed by a digit -- for example: "%a" will not be translated, "%%1" will translate to "%1").

translateBufferEx

public void translateBufferEx(Object[] args)
This version of translate buffer translates Object arguments and has no limit on the number of substitutions. The input string syntax is slightly different. Rather than %x, this method requires that strings have replacement tokens in the com.sssw.rt.form of %xxx%

Novell exteNd
Director 5.2 API