This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 public class StringBuffer {
2     char value[];
3     int count;
4     //    private static final int DEFAULTSIZE=16;
5
6     public StringBuffer(String str) {
7         value=new char[str.count+16];//16 is DEFAULTSIZE
8         count=str.count;
9         for(int i=0;i<count;i++)
10             value[i]=str.value[i+str.offset];
11     }
12
13     public StringBuffer() {
14         value=new char[16];//16 is DEFAULTSIZE
15         count=0;
16     }
17
18     public int length() {
19         return count;
20     }
21
22     public int capacity() {
23         return value.length;
24     }
25
26     public char charAt(int x) {
27         return value[x];
28     }
29
30     public void append(String s) {
31         if ((s.count+count)>value.length) {
32             // Need to allocate
33             char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE
34             for(int i=0;i<count;i++)
35                 newvalue[i]=value[i];
36             for(int i=0;i<s.count;i++)
37                 newvalue[i+count]=s.value[i+s.offset];
38             value=newvalue;
39             count+=s.count;
40         } else {
41             for(int i=0;i<s.count;i++) {
42                 value[i+count]=s.value[i+s.offset];
43             }
44             count+=s.count;
45         }
46     }
47
48     public void append(StringBuffer s) {
49         if ((s.count+count)>value.length) {
50             // Need to allocate
51             char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE
52             for(int i=0;i<count;i++)
53                 newvalue[i]=value[i];
54             for(int i=0;i<s.count;i++)
55                 newvalue[i+count]=s.value[i];
56             value=newvalue;
57             count+=s.count;
58         } else {
59             for(int i=0;i<s.count;i++) {
60                 value[i+count]=s.value[i];
61             }
62             count+=s.count;
63         }
64     }
65
66     public String toString() {
67         return new String(this);
68     }
69 }