This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 public class String {
2     char value[];
3     int count;
4     int offset;
5     private int cachedHashcode;
6
7     private String() {
8     }
9
10     public String(char str[]) {
11         char charstr[]=new char[str.length];
12         for(int i=0;i<str.length;i++)
13             charstr[i]=str[i];
14         this.value=charstr;
15         this.count=str.length;
16         this.offset=0;
17     }
18
19     public String(byte str[]) {
20         char charstr[]=new char[str.length];
21         for(int i=0;i<str.length;i++)
22             charstr[i]=(char)str[i];
23         this.value=charstr;
24         this.count=str.length;
25         this.offset=0;
26     }
27
28     public String(String str) {
29         this.value=str.value;
30         this.count=str.count;
31         this.offset=str.offset;
32     }
33
34     public String(StringBuffer strbuf) {
35         value=new char[strbuf.length()];
36         count=strbuf.length();
37         offset=0;
38         for(int i=0;i<count;i++)
39             value[i]=strbuf.value[i];
40     }
41
42     public String subString(int beginIndex, int endIndex) {
43         String str=new String();
44         if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
45             // FIXME
46         }
47         str.value=this.value;
48         str.count=endIndex-beginIndex;
49         str.offset=this.offset+beginIndex;
50         return str;
51     }
52
53     public String subString(int beginIndex) {
54         return this.subString(beginIndex, this.count);
55     }
56
57     public int lastindexOf(int ch) {
58         return this.lastindexOf(ch, count - 1);
59     }
60
61     public int lastindexOf(int ch, int fromIndex) {
62         for(int i=fromIndex;i>0;i--)
63             if (this.charAt(i)==ch)
64                 return i;
65         return -1;
66     }
67
68     public String replace(char oldch, char newch) {
69         char[] buffer=new char[count];
70         for(int i=0;i<count;i++) {
71             char x=charAt(i);
72             if (x==oldch)
73                 x=newch;
74             buffer[i]=x;
75         }
76         return new String(buffer);
77     }
78
79     public int indexOf(int ch) {
80         return this.indexOf(ch, 0);
81     }
82
83     public int indexOf(int ch, int fromIndex) {
84         for(int i=fromIndex;i<count;i++)
85             if (this.charAt(i)==ch)
86                 return i;
87         return -1;
88     }
89
90     public int indexOf(String str) {
91         return this.indexOf(str, 0);
92     }
93
94     public int indexOf(String str, int fromIndex) {
95         if (fromIndex<0)
96             fromIndex=0;
97         for(int i=fromIndex;i<=(count-str.count);i++)
98             if (regionMatches(i, str, 0, str.count))
99                 return i;
100         return -1;
101     }
102
103     public boolean startsWith(String str) {
104         return regionMatches(0, str, 0, str.count);
105     }
106
107     public boolean regionMatches(int toffset, String other, int ooffset, int len) {
108         if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
109             return false;
110         for(int i=0;i<len;i++)
111             if (other.value[i+other.offset+ooffset]!=
112                 this.value[i+this.offset+toffset])
113                 return false;
114         return true;
115     }
116
117     public char[] toCharArray() {
118         char str[]=new char[count];
119         for(int i=0;i<count;i++)
120             str[i]=value[i+offset];
121         return str;
122     }
123
124     public byte[] getBytes() {
125         byte str[]=new byte[count];
126         for(int i=0;i<count;i++)
127             str[i]=(byte)value[i+offset];
128         return str;
129     }
130
131     public int length() {
132         return count;
133     }
134
135     public char charAt(int i) {
136         return value[i+offset];
137     }
138
139     public String toString() {
140         return this;
141     }
142
143     public static String valueOf(Object o) {
144         return o.toString();
145     }
146
147     public static String valueOf(int x) {
148         int length=0;
149         int tmp;
150         if (x<0)
151             tmp=-x;
152         else
153             tmp=x;
154         do {
155             tmp=tmp/10;
156             length=length+1;
157         } while(tmp!=0);
158         
159         char chararray[];
160         if (x<0)
161             chararray=new char[length+1];
162         else
163             chararray=new char[length];
164         int voffset;
165         if (x<0) {
166             chararray[0]='-';
167             voffset=1;
168             x=-x;
169         } else
170             voffset=0;
171         
172         do {
173             chararray[--length+voffset]=(char)(x%10+'0');
174             x=x/10;
175         } while (length!=0);
176         return new String(chararray);
177     }
178
179     public int hashCode() {
180         if (cachedHashcode!=0)
181             return cachedHashcode;
182         int hashcode=0;
183         for(int i=0;i<count;i++)
184             hashcode=hashcode*31+value[i+offset];
185         cachedHashcode=hashcode;
186         return hashcode;
187     }
188
189     public boolean equals(Object o) {
190         if (o.getType()!=getType())
191             return false;
192         String s=(String)o;
193         if (s.count!=count)
194             return false;
195         for(int i=0;i<count;i++) {
196             if (s.value[i+s.offset]!=value[i+offset])
197                 return false;
198         }
199         return true;
200     }
201 }