Bug fixes for allowing multiple task parameters
[IRC.git] / Robust / src / ClassLibrary / String.java
1 public class String {
2     char value[];
3     int count;
4     int offset;
5
6     private String() {
7     }
8
9     public String(char str[]) {
10         char charstr[]=new char[str.length];
11         for(int i=0;i<str.length;i++)
12             charstr[i]=str[i];
13         this.value=charstr;
14         this.count=str.length;
15         this.offset=0;
16     }
17
18     public String(byte str[]) {
19         char charstr[]=new char[str.length];
20         for(int i=0;i<str.length;i++)
21             charstr[i]=(char)str[i];
22         this.value=charstr;
23         this.count=str.length;
24         this.offset=0;
25     }
26
27     public String(String str) {
28         this.value=str.value;
29         this.count=str.count;
30         this.offset=str.offset;
31     }
32
33     public String(StringBuffer strbuf) {
34         value=new char[strbuf.length()];
35         count=strbuf.length();
36         offset=0;
37         for(int i=0;i<count;i++)
38             value[i]=strbuf.value[i];
39     }
40
41     public String subString(int beginIndex, int endIndex) {
42         String str=new String();
43         if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
44             // FIXME
45         }
46         str.value=this.value;
47         str.count=endIndex-beginIndex;
48         str.offset=this.offset+beginIndex;
49         return str;
50     }
51
52     public String subString(int beginIndex) {
53         return this.subString(beginIndex, this.count);
54     }
55
56     public int indexOf(int ch) {
57         return this.indexOf(ch, 0);
58     }
59
60     public int indexOf(int ch, int fromIndex) {
61         for(int i=fromIndex;i<count;i++)
62             if (this.charAt(i)==ch)
63                 return i;
64         return -1;
65     }
66
67     public int indexOf(String str) {
68         return this.indexOf(str, 0);
69     }
70
71     public int indexOf(String str, int fromIndex) {
72         if (fromIndex<0)
73             fromIndex=0;
74         for(int i=fromIndex;i<=(count-str.count);i++)
75             if (regionMatches(i, str, 0, str.count))
76                 return i;
77         return -1;
78     }
79
80     public boolean regionMatches(int toffset, String other, int ooffset, int len) {
81         if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
82             return false;
83         for(int i=0;i<len;i++)
84             if (other.value[i+other.offset+ooffset]!=
85                 this.value[i+this.offset+toffset])
86                 return false;
87         return true;
88     }
89
90     public char[] toCharArray() {
91         char str[]=new char[count];
92         for(int i=0;i<count;i++)
93             str[i]=value[i+offset];
94         return str;
95     }
96
97     public byte[] getBytes() {
98         byte str[]=new byte[count];
99         for(int i=0;i<count;i++)
100             str[i]=(byte)value[i+offset];
101         return str;
102     }
103
104     public int length() {
105         return count;
106     }
107
108     public char charAt(int i) {
109         return value[i+offset];
110     }
111
112     public String toString() {
113         return this;
114     }
115
116     public static String valueOf(Object o) {
117         return o.toString();
118     }
119
120     public static String valueOf(int x) {
121         int length=0;
122         int tmp;
123         if (x<0)
124             tmp=-x;
125         else
126             tmp=x;
127         do {
128             tmp=tmp/10;
129             length=length+1;
130         } while(tmp!=0);
131         
132         char chararray[];
133         if (x<0)
134             chararray=new char[length+1];
135         else
136             chararray=new char[length];
137         int voffset;
138         if (x<0) {
139             chararray[0]='-';
140             voffset=1;
141             x=-x;
142         } else
143             voffset=0;
144         
145         do {
146             chararray[--length+voffset]=(char)(x%10+'0');
147             x=x/10;
148         } while (length!=0);
149         return new String(chararray);
150     }
151 }