2 @METHODDEFAULT("O<V,V<C,C<IN,C*,THISLOC=O,RETURNLOC=O")
3 public class StringBuffer {
9 // private static final int DEFAULTSIZE=16;
11 public StringBuffer(String str) {
12 value = new char[str.count + 16]; // 16 is DEFAULTSIZE
14 for (int i = 0; i < count; i++)
15 value[i] = str.value[i + str.offset];
18 public StringBuffer() {
19 value = new char[16]; // 16 is DEFAULTSIZE
23 public StringBuffer(int i) {
32 public int capacity() {
36 public char charAt(int x) {
40 public StringBuffer append(@LOC("IN") char c) {
41 return append(String.valueOf(c));
44 public StringBuffer append(@LOC("IN") String s) {
45 if ((s.count + count) > value.length) {
47 @LOC("C") char newvalue[] = new char[s.count + count + 16]; // 16 is
49 for (@LOC("C") int i = 0; i < count; i++)
50 newvalue[i] = value[i];
51 for (@LOC("C") int i = 0; i < s.count; i++)
52 newvalue[i + count] = s.value[i + s.offset];
56 for (@LOC("C") int i = 0; i < s.count; i++) {
57 value[i + count] = s.value[i + s.offset];
64 public void ensureCapacity(int i) {
68 if (i > value.length) {
69 char newvalue[] = new char[i];
70 for (int ii = 0; ii < count; ii++)
71 newvalue[ii] = value[ii];
76 public StringBuffer append(StringBuffer s) {
77 if ((s.count + count) > value.length) {
79 char newvalue[] = new char[s.count + count + 16]; // 16 is DEFAULTSIZE
80 for (int i = 0; i < count; i++)
81 newvalue[i] = value[i];
82 for (int i = 0; i < s.count; i++)
83 newvalue[i + count] = s.value[i];
87 for (int i = 0; i < s.count; i++) {
88 value[i + count] = s.value[i];
95 public int indexOf(String str) {
96 return indexOf(str, 0);
99 public synchronized int indexOf(String str, int fromIndex) {
100 String vstr = new String(value, 0, count);
101 return vstr.indexOf(str, fromIndex);
104 public String toString() {
105 return new String(this);
108 public synchronized StringBuffer replace(int start, int end, String str) {
111 System.printString("StringIndexOutOfBoundsException: " + start + "\n");
115 System.printString("StringIndexOutOfBoundsException: start > length()\n");
119 System.printString("StringIndexOutOfBoundsException: start > end\n");
126 int len = str.length();
127 int newCount = count + len - (end - start);
128 if (newCount > value.length)
129 expandCapacity(newCount);
131 System.arraycopy(value, end, value, start + len, count - end);
132 str.getChars(value, start);
137 void expandCapacity(int minimumCapacity) {
138 int newCapacity = (value.length + 1) * 2;
139 if (newCapacity < 0) {
140 newCapacity = 0x7fffffff /* Integer.MAX_VALUE */;
141 } else if (minimumCapacity > newCapacity) {
142 newCapacity = minimumCapacity;
144 char newValue[] = new char[newCapacity];
145 System.arraycopy(value, 0, newValue, 0, count);