1 @LATTICE("V<C, V<O,V*")
2 @METHODDEFAULT("G<O,O<V,V<C,C<IN,C*,THISLOC=O,RETURNLOC=O,GLOBALLOC=G")
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 @LATTICE("OUT<THIS,THIS<VAR,VAR<G,G<IN,THISLOC=THIS,GLOBALLOC=G,RETURNLOC=OUT")
41 public StringBuffer append(@LOC("IN") char c) {
42 @LOC("VAR") String str = String.valueOf(c);
46 public StringBuffer append(@LOC("IN") String s) {
47 if ((s.count + count) > value.length) {
49 @LOC("O,StringBuffer.V") char newvalue[] = new char[s.count + count + 16]; // 16
52 for (@LOC("O,StringBuffer.V") int i = 0; i < count; i++)
53 newvalue[i] = value[i];
54 for (@LOC("O,StringBuffer.V") int i = 0; i < s.count; i++)
55 newvalue[i + count] = s.value[i + s.offset];
59 for (@LOC("O,StringBuffer.V") int i = 0; i < s.count; i++) {
60 value[i + count] = s.value[i + s.offset];
67 public void ensureCapacity(int i) {
71 if (i > value.length) {
72 char newvalue[] = new char[i];
73 for (int ii = 0; ii < count; ii++)
74 newvalue[ii] = value[ii];
79 public StringBuffer append(StringBuffer s) {
80 if ((s.count + count) > value.length) {
82 char newvalue[] = new char[s.count + count + 16]; // 16 is DEFAULTSIZE
83 for (int i = 0; i < count; i++)
84 newvalue[i] = value[i];
85 for (int i = 0; i < s.count; i++)
86 newvalue[i + count] = s.value[i];
90 for (int i = 0; i < s.count; i++) {
91 value[i + count] = s.value[i];
98 public int indexOf(String str) {
99 return indexOf(str, 0);
102 public synchronized int indexOf(String str, int fromIndex) {
103 String vstr = new String(value, 0, count);
104 return vstr.indexOf(str, fromIndex);
107 public String toString() {
108 return new String(this);
111 public synchronized StringBuffer replace(int start, int end, String str) {
114 System.printString("StringIndexOutOfBoundsException: " + start + "\n");
118 System.printString("StringIndexOutOfBoundsException: start > length()\n");
122 System.printString("StringIndexOutOfBoundsException: start > end\n");
129 int len = str.length();
130 int newCount = count + len - (end - start);
131 if (newCount > value.length)
132 expandCapacity(newCount);
134 System.arraycopy(value, end, value, start + len, count - end);
135 str.getChars(value, start);
140 void expandCapacity(int minimumCapacity) {
141 int newCapacity = (value.length + 1) * 2;
142 if (newCapacity < 0) {
143 newCapacity = 0x7fffffff /* Integer.MAX_VALUE */;
144 } else if (minimumCapacity > newCapacity) {
145 newCapacity = minimumCapacity;
147 char newValue[] = new char[newCapacity];
148 System.arraycopy(value, 0, newValue, 0, count);