1 |
/* StringBuffer.java -- Growable strings |
/* StringBuffer.java -- Growable strings |
2 |
Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
41 |
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 |
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 |
42 |
* Updated using online JDK 1.2 docs. |
* Updated using online JDK 1.2 docs. |
43 |
* Believed complete and correct to JDK 1.2. |
* Believed complete and correct to JDK 1.2. |
44 |
|
* 1.4 compatibility August 22, 2001 - Isaac Jones |
45 |
* Merged with Classpath. |
* Merged with Classpath. |
46 |
*/ |
*/ |
47 |
|
|
152 |
{ |
{ |
153 |
return append (String.valueOf(dnum)); |
return append (String.valueOf(dnum)); |
154 |
} |
} |
155 |
|
|
156 |
|
/** Append the <code>StringBuffer</code> value of the argument to this |
157 |
|
* <code>StringBuffer</code>. |
158 |
|
* Uses <code>StringBuffer.toString()</code> to convert to |
159 |
|
* <code>String</code>. |
160 |
|
* |
161 |
|
* @param stringBuffer the <code>StringBuffer</code> to convert and append. |
162 |
|
* @return this <code>StringBuffer</code>. |
163 |
|
* @see java.lang.StringBuffer.toString() |
164 |
|
* @since 1.4 |
165 |
|
*/ |
166 |
|
public StringBuffer append (StringBuffer stringBuffer) |
167 |
|
{ |
168 |
|
return append (stringBuffer.toString()); |
169 |
|
} |
170 |
|
|
171 |
/** Append the <code>String</code> value of the argument to this <code>StringBuffer</code>. |
/** Append the <code>String</code> value of the argument to this <code>StringBuffer</code>. |
172 |
* Uses <code>String.valueOf()</code> to convert to |
* Uses <code>String.valueOf()</code> to convert to |
707 |
* |
* |
708 |
* @return new String which is a substring of this StringBuffer |
* @return new String which is a substring of this StringBuffer |
709 |
* |
* |
710 |
* @exception StringIndexOutOfBoundsException |
* @exception IndexOutOfBoundsException |
711 |
* if (beginIndex < 0 || endIndex > this.length() || beginIndex > endIndex) |
* if (beginIndex < 0 || endIndex > this.length() || beginIndex > endIndex) |
712 |
|
* |
713 |
|
* @since 1.4 |
714 |
*/ |
*/ |
715 |
public CharSequence subSequence (int beginIndex, int endIndex) |
public CharSequence subSequence (int beginIndex, int endIndex) |
716 |
{ |
{ |
717 |
return substring(beginIndex, endIndex); |
return substring(beginIndex, endIndex); |
718 |
} |
} |
719 |
|
|
|
|
|
720 |
/** Convert this <code>StringBuffer</code> to a <code>String</code>. |
/** Convert this <code>StringBuffer</code> to a <code>String</code>. |
721 |
* @return the characters in this StringBuffer |
* @return the characters in this StringBuffer |
722 |
*/ |
*/ |
727 |
return new String (this); |
return new String (this); |
728 |
} |
} |
729 |
|
|
730 |
|
/** Finds the first instance of a String in this StringBuffer. |
731 |
|
* |
732 |
|
* @param str String to find |
733 |
|
* |
734 |
|
* @return location (base 0) of the String, or -1 if not found |
735 |
|
* |
736 |
|
* @exception NullPointerException if `str' is null |
737 |
|
* |
738 |
|
* @since 1.4 |
739 |
|
*/ |
740 |
|
public int indexOf (String string) |
741 |
|
{ |
742 |
|
return this.toString().indexOf(string, 0); |
743 |
|
//save a call in String.java by passing second argument |
744 |
|
} |
745 |
|
|
746 |
|
/** Finds the first instance of a String in this StringBuffer, |
747 |
|
* starting at a given index. If starting index is less than 0, |
748 |
|
* the search starts at the beginning of this String. If the |
749 |
|
* starting index is greater than the length of this String, -1 is |
750 |
|
* returned. |
751 |
|
* |
752 |
|
* @param str String to find |
753 |
|
* @param fromIndex index to start the search |
754 |
|
* |
755 |
|
* @return location (base 0) of the String, or -1 if not found |
756 |
|
* |
757 |
|
* @exception NullPointerException if `str' is null |
758 |
|
* |
759 |
|
* @since 1.4 |
760 |
|
*/ |
761 |
|
public int indexOf (String string, |
762 |
|
int fromIndex) |
763 |
|
{ |
764 |
|
return this.toString().indexOf(string, fromIndex); |
765 |
|
} |
766 |
|
|
767 |
|
/** Finds the last instance of a String in this StringBuffer. |
768 |
|
* |
769 |
|
* @param str String to find |
770 |
|
* |
771 |
|
* @return location (base 0) of the String, or -1 if not found |
772 |
|
* |
773 |
|
* @exception NullPointerException if `str' is null |
774 |
|
* |
775 |
|
* @since 1.4 |
776 |
|
*/ |
777 |
|
public int lastIndexOf(String str) throws NullPointerException |
778 |
|
{ |
779 |
|
return this.toString().lastIndexOf(str, count-str.count); |
780 |
|
} |
781 |
|
|
782 |
|
/** Finds the last instance of a String in this StringBuffer, |
783 |
|
* starting at a given index. If starting index is greater than the |
784 |
|
* maximum valid index, then the search begins at the end of this |
785 |
|
* String. If the starting index is less than zero, -1 is returned. |
786 |
|
* |
787 |
|
* @param str String to find |
788 |
|
* @param fromIndex index to start the search |
789 |
|
* |
790 |
|
* @return location (base 0) of the String, or -1 if not found |
791 |
|
* |
792 |
|
* @exception NullPointerException if `str' is null |
793 |
|
* |
794 |
|
* @since 1.4 |
795 |
|
*/ |
796 |
|
public int lastIndexOf(String str, int fromIndex) |
797 |
|
throws NullPointerException |
798 |
|
{ |
799 |
|
return this.toString().lastIndexOf(str, fromIndex); |
800 |
|
} |
801 |
|
|
802 |
// Index of next available character. Note that this has |
// Index of next available character. Note that this has |
803 |
// permissions set this way so that String can get the value. |
// permissions set this way so that String can get the value. |
804 |
int count; |
int count; |