Adding StringBuffer class and test case. This gives append functionality.
[IRC.git] / Robust / src / ClassLibrary / String.java
1 public class String {
2     char value[];
3     int count;
4     int offset;
5
6     public String(char str[]) {
7         char charstr[]=new char[str.length];
8         for(int i=0;i<str.length;i++)
9             charstr[i]=str[i];
10         this.value=charstr;
11         this.count=str.length;
12         this.offset=0;
13     }
14
15     public String(byte str[]) {
16         char charstr[]=new char[str.length];
17         for(int i=0;i<str.length;i++)
18             charstr[i]=(char)str[i];
19         this.value=charstr;
20         this.count=str.length;
21         this.offset=0;
22     }
23
24     public String(String str) {
25         this.value=str.value;
26         this.count=str.count;
27         this.offset=str.offset;
28     }
29
30     public String(StringBuffer strbuf) {
31         value=new char[strbuf.length()];
32         count=strbuf.length();
33         offset=0;
34         for(int i=0;i<count;i++)
35             value[i]=strbuf.value[i];
36     }
37
38     char[] toCharArray() {
39         char str[]=new char[count];
40         for(int i=0;i<count;i++)
41             str[i]=value[i+offset];
42         return str;
43     }
44
45     byte[] getBytes() {
46         byte str[]=new byte[count];
47         for(int i=0;i<value.length;i++)
48             str[i]=(byte)value[i+offset];
49         return str;
50     }
51
52     public int length() {
53         return count;
54     }
55
56     public char charAt(int i) {
57         return value[i+offset];
58     }
59
60     public static String valueOf(Object o) {
61         return o.toString();
62     }
63
64     public static String valueOf(int x) {
65         int length=0;
66         int tmp;
67         if (x<0)
68             tmp=-x;
69         else
70             tmp=x;
71         do {
72             tmp=tmp/10;
73             length=length+1;
74         } while(tmp!=0);
75         
76         char chararray[];
77         if (x<0)
78             chararray=new char[length+1];
79         else
80             chararray=new char[length];
81         int voffset;
82         if (x<0) {
83             chararray[0]='-';
84             voffset=1;
85             x=-x;
86         } else
87             voffset=0;
88         
89         do {
90             chararray[--length+voffset]=(char)(x%10+'0');
91             x=x/10;
92         } while (length!=0);
93         return new String(chararray);
94     }
95 }