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(byte str[], String encoding) {
46 int length = this.count;
47 if (length>(str.length))
49 char charstr[]=new char[length];
50 for(int i=0; i<length; i++)
51 charstr[i]=(char)str[i];
57 public String(char str[], int offset, int length) {
58 if (length>(str.length-offset))
59 length=str.length-offset;
60 char charstr[]=new char[length];
61 for(int i=0; i<length; i++)
62 charstr[i]=str[i+offset];
68 public String(String str) {
71 this.offset=str.offset;
74 public String(StringBuffer strbuf) {
75 value=new char[strbuf.length()];
76 count=strbuf.length();
78 for(int i=0; i<count; i++)
79 value[i]=strbuf.value[i];
82 public boolean endsWith(String suffix) {
83 return regionMatches(count - suffix.count, suffix, 0, suffix.count);
87 public String substring(int beginIndex) {
88 return substring(beginIndex, this.count);
91 public String subString(int beginIndex, int endIndex) {
92 return substring(beginIndex, endIndex);
95 public String substring(int beginIndex, int endIndex) {
96 String str=new String();
97 if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
99 System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this);
101 str.value=this.value;
102 str.count=endIndex-beginIndex;
103 str.offset=this.offset+beginIndex;
107 public String subString(int beginIndex) {
108 return this.subString(beginIndex, this.count);
111 public int lastindexOf(int ch) {
112 return this.lastindexOf(ch, count - 1);
115 public static String concat2(String s1, String s2) {
117 return "null".concat(s2);
119 return s1.concat(s2);
122 public String concat(String str) {
123 String newstr=new String();
124 newstr.count=this.count+str.count;
125 char charstr[]=new char[newstr.count];
126 newstr.value=charstr;
128 for(int i=0; i<count; i++) {
129 charstr[i]=value[i+offset];
131 for(int i=0; i<str.count; i++) {
132 charstr[i+count]=str.value[i+str.offset];
137 public int lastindexOf(int ch, int fromIndex) {
138 for(int i=fromIndex; i>0; i--)
139 if (this.charAt(i)==ch)
144 public String replace(char oldch, char newch) {
145 char[] buffer=new char[count];
146 for(int i=0; i<count; i++) {
152 return new String(buffer);
155 public String toUpperCase() {
156 char[] buffer=new char[count];
157 for(int i=0; i<count; i++) {
159 if (x>='a'&&x<='z') {
160 x=(char) ((x-'a')+'A');
164 return new String(buffer);
167 public String toLowerCase() {
168 char[] buffer=new char[count];
169 for(int i=0; i<count; i++) {
171 if (x>='A'&&x<='Z') {
172 x=(char) ((x-'A')+'a');
176 return new String(buffer);
179 public int indexOf(int ch) {
180 return this.indexOf(ch, 0);
183 public int indexOf(int ch, int fromIndex) {
184 for(int i=fromIndex; i<count; i++)
185 if (this.charAt(i)==ch)
190 public int indexOf(String str) {
191 return this.indexOf(str, 0);
194 public int indexOf(String str, int fromIndex) {
197 for(int i=fromIndex; i<=(count-str.count); i++)
198 if (regionMatches(i, str, 0, str.count))
203 public int indexOfIgnoreCase(String str, int fromIndex) {
208 public int lastIndexOf(String str, int fromIndex) {
209 int k=count-str.count;
213 if (regionMatches(k, str, 0, str.count))
219 public int lastIndexOf(String str) {
220 return lastIndexOf(str, count-str.count);
223 public boolean startsWith(String str) {
224 return regionMatches(0, str, 0, str.count);
227 public boolean startsWith(String str, int toffset) {
228 return regionMatches(toffset, str, 0, str.count);
231 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
232 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
234 for(int i=0; i<len; i++)
235 if (other.value[i+other.offset+ooffset]!=
236 this.value[i+this.offset+toffset])
241 public char[] toCharArray() {
242 char str[]=new char[count];
243 for(int i=0; i<count; i++)
244 str[i]=value[i+offset];
248 public byte[] getBytes() {
249 byte str[]=new byte[count];
250 for(int i=0; i<count; i++)
251 str[i]=(byte)value[i+offset];
255 public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
256 if((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) {
258 System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this);
261 int len = srcEnd - srcBegin;
263 for(int i=srcBegin; i<srcEnd; i++)
264 dst[j++]=value[i+offset];
268 public int length() {
272 public char charAt(int i) {
273 return value[i+offset];
276 public String toString() {
280 public static String valueOf(Object o) {
287 public static String valueOf(boolean b) {
289 return new String("true");
291 return new String("false");
294 public static String valueOf(char c) {
295 char ar[]=new char[1];
297 return new String(ar);
300 public static String valueOf(int x) {
314 chararray=new char[length+1];
316 chararray=new char[length];
326 chararray[--length+voffset]=(char)(x%10+'0');
329 return new String(chararray);
332 public static String valueOf(double val) {
333 char[] chararray=new char[20];
334 String s=new String();
336 s.count=convertdoubletochar(val, chararray);
341 public static native int convertdoubletochar(double val, char [] chararray);
343 public static String valueOf(long x) {
357 chararray=new char[length+1];
359 chararray=new char[length];
369 chararray[--length+voffset]=(char)(x%10+'0');
372 return new String(chararray);
375 public int compareTo(String s) {
376 int smallerlength=count<s.count?count:s.count;
378 for( int i = 0; i < smallerlength; i++ ) {
379 int valDiff = this.charAt(i) - s.charAt(i);
384 return count-s.count;
387 public int hashCode() {
388 if (cachedHashcode!=0)
389 return cachedHashcode;
391 for(int i=0; i<count; i++)
392 hashcode=hashcode*31+value[i+offset];
393 cachedHashcode=hashcode;
397 public boolean equals(Object o) {
398 if (o.getType()!=getType())
403 for(int i=0; i<count; i++) {
404 if (s.value[i+s.offset]!=value[i+offset])
410 public boolean equalsIgnoreCase(String s) {
413 for(int i=0; i<count; i++) {
414 char l=s.value[i+s.offset];
415 char r=value[i+offset];
417 l=(char)((l-'a')+'A');
419 r=(char)((r-'a')+'A');
426 public Vector split() {
427 Vector splitted = new Vector();
432 for(i = 0; i< count;i++) {
433 if(value[i+offset] != '\n' && value[i+offset] != '\t' && value[i+offset] != ' ')
440 if(value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ') {
441 String t=new String();
445 splitted.addElement(t);
448 while( i < count && ( value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ')) {
458 String t=new String();
462 splitted.addElement(t);
468 public boolean contains(String str)
471 char[] strChar = str.toCharArray();
474 for(i = 0; i < count; i++) {
475 if(value[i] == strChar[0]) {
477 for(j=0; j < str.length() && i+j < count;j++) {
478 if(value[i+j] == strChar[j])
481 if(cnt == str.length())