5 private int cachedHashcode;
10 public String(char c) {
11 char[] str = new char[1];
16 public String(char str[]) {
17 char charstr[]=new char[str.length];
18 for(int i=0; i<str.length; i++)
21 this.count=str.length;
25 public String(byte str[]) {
26 char charstr[]=new char[str.length];
27 for(int i=0; i<str.length; i++)
28 charstr[i]=(char)str[i];
30 this.count=str.length;
34 public String(byte str[], int offset, int length) {
35 if (length>(str.length-offset))
36 length=str.length-offset;
37 char charstr[]=new char[length];
38 for(int i=0; i<length; i++)
39 charstr[i]=(char)str[i+offset];
45 public String(String str) {
48 this.offset=str.offset;
51 public String(StringBuffer strbuf) {
52 value=new char[strbuf.length()];
53 count=strbuf.length();
55 for(int i=0; i<count; i++)
56 value[i]=strbuf.value[i];
59 public boolean endsWith(String suffix) {
60 return regionMatches(count - suffix.count, suffix, 0, suffix.count);
64 public String substring(int beginIndex) {
65 return substring(beginIndex, this.count);
68 public String subString(int beginIndex, int endIndex) {
69 return substring(beginIndex, endIndex);
72 public String substring(int beginIndex, int endIndex) {
73 String str=new String();
74 if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
76 System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this);
79 str.count=endIndex-beginIndex;
80 str.offset=this.offset+beginIndex;
84 public String subString(int beginIndex) {
85 return this.subString(beginIndex, this.count);
88 public int lastindexOf(int ch) {
89 return this.lastindexOf(ch, count - 1);
92 public static String concat2(String s1, String s2) {
94 return "null".concat(s2);
99 public String concat(String str) {
100 String newstr=new String();
101 newstr.count=this.count+str.count;
102 char charstr[]=new char[newstr.count];
103 newstr.value=charstr;
105 for(int i=0; i<count; i++) {
106 charstr[i]=value[i+offset];
108 for(int i=0; i<str.count; i++) {
109 charstr[i+count]=str.value[i+str.offset];
114 public int lastindexOf(int ch, int fromIndex) {
115 for(int i=fromIndex; i>0; i--)
116 if (this.charAt(i)==ch)
121 public String replace(char oldch, char newch) {
122 char[] buffer=new char[count];
123 for(int i=0; i<count; i++) {
129 return new String(buffer);
132 public String toUpperCase() {
133 char[] buffer=new char[count];
134 for(int i=0; i<count; i++) {
136 if (x>='a'&&x<='z') {
137 x=(char) ((x-'a')+'A');
141 return new String(buffer);
144 public String toLowerCase() {
145 char[] buffer=new char[count];
146 for(int i=0; i<count; i++) {
148 if (x>='A'&&x<='Z') {
149 x=(char) ((x-'A')+'a');
153 return new String(buffer);
156 public int indexOf(int ch) {
157 return this.indexOf(ch, 0);
160 public int indexOf(int ch, int fromIndex) {
161 for(int i=fromIndex; i<count; i++)
162 if (this.charAt(i)==ch)
167 public int indexOf(String str) {
168 return this.indexOf(str, 0);
171 public int indexOf(String str, int fromIndex) {
174 for(int i=fromIndex; i<=(count-str.count); i++)
175 if (regionMatches(i, str, 0, str.count))
180 public int indexOfIgnoreCase(String str, int fromIndex) {
185 public int lastIndexOf(String str, int fromIndex) {
186 int k=count-str.count;
190 if (regionMatches(k, str, 0, str.count))
196 public int lastIndexOf(String str) {
197 return lastIndexOf(str, count-str.count);
200 public boolean startsWith(String str) {
201 return regionMatches(0, str, 0, str.count);
204 public boolean startsWith(String str, int toffset) {
205 return regionMatches(toffset, str, 0, str.count);
208 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
209 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
211 for(int i=0; i<len; i++)
212 if (other.value[i+other.offset+ooffset]!=
213 this.value[i+this.offset+toffset])
218 public char[] toCharArray() {
219 char str[]=new char[count];
220 for(int i=0; i<count; i++)
221 str[i]=value[i+offset];
225 public byte[] getBytes() {
226 byte str[]=new byte[count];
227 for(int i=0; i<count; i++)
228 str[i]=(byte)value[i+offset];
232 public int length() {
236 public char charAt(int i) {
237 return value[i+offset];
240 public String toString() {
244 public static String valueOf(Object o) {
251 public static String valueOf(boolean b) {
253 return new String("true");
255 return new String("false");
258 public static String valueOf(char c) {
259 char ar[]=new char[1];
261 return new String(ar);
264 public static String valueOf(int x) {
278 chararray=new char[length+1];
280 chararray=new char[length];
290 chararray[--length+voffset]=(char)(x%10+'0');
293 return new String(chararray);
296 public static String valueOf(double val) {
297 char[] chararray=new char[20];
298 String s=new String();
300 s.count=convertdoubletochar(val, chararray);
305 public static native int convertdoubletochar(double val, char [] chararray);
307 public static String valueOf(long x) {
321 chararray=new char[length+1];
323 chararray=new char[length];
333 chararray[--length+voffset]=(char)(x%10+'0');
336 return new String(chararray);
339 public int compareTo(String s) {
340 int smallerlength=count<s.count?count:s.count;
342 for( int i = 0; i < smallerlength; i++ ) {
343 int valDiff = this.charAt(i) - s.charAt(i);
348 return count-s.count;
351 public int hashCode() {
352 if (cachedHashcode!=0)
353 return cachedHashcode;
355 for(int i=0; i<count; i++)
356 hashcode=hashcode*31+value[i+offset];
357 cachedHashcode=hashcode;
361 public boolean equals(Object o) {
362 if (o.getType()!=getType())
367 for(int i=0; i<count; i++) {
368 if (s.value[i+s.offset]!=value[i+offset])
374 public boolean equalsIgnoreCase(String s) {
377 for(int i=0; i<count; i++) {
378 char l=s.value[i+s.offset];
379 char r=value[i+offset];
381 l=(char)((l-'a')+'A');
383 r=(char)((r-'a')+'A');
390 public Vector split() {
391 Vector splitted = new Vector();
396 for(i = 0; i< count;i++) {
397 if(value[i+offset] != '\n' && value[i+offset] != '\t' && value[i+offset] != ' ')
404 if(value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ') {
405 String t=new String();
409 splitted.addElement(t);
412 while( i < count && ( value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ')) {
422 String t=new String();
426 splitted.addElement(t);
432 public boolean contains(String str)
435 char[] strChar = str.toCharArray();
438 for(i = 0; i < count; i++) {
439 if(value[i] == strChar[0]) {
441 for(j=0; j < str.length() && i+j < count;j++) {
442 if(value[i+j] == strChar[j])
445 if(cnt == str.length())