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 int lastIndexOf(char ch) {
116 return this.lastindexOf((int)ch, count - 1);
119 public static String concat2(String s1, String s2) {
121 return "null".concat(s2);
123 return s1.concat(s2);
126 public String concat(String str) {
127 String newstr=new String();
128 newstr.count=this.count+str.count;
129 char charstr[]=new char[newstr.count];
130 newstr.value=charstr;
132 for(int i=0; i<count; i++) {
133 charstr[i]=value[i+offset];
135 for(int i=0; i<str.count; i++) {
136 charstr[i+count]=str.value[i+str.offset];
141 public int lastindexOf(int ch, int fromIndex) {
142 for(int i=fromIndex; i>0; i--)
143 if (this.charAt(i)==ch)
148 public String replace(char oldch, char newch) {
149 char[] buffer=new char[count];
150 for(int i=0; i<count; i++) {
156 return new String(buffer);
159 public String toUpperCase() {
160 char[] buffer=new char[count];
161 for(int i=0; i<count; i++) {
163 if (x>='a'&&x<='z') {
164 x=(char) ((x-'a')+'A');
168 return new String(buffer);
171 public String toLowerCase() {
172 char[] buffer=new char[count];
173 for(int i=0; i<count; i++) {
175 if (x>='A'&&x<='Z') {
176 x=(char) ((x-'A')+'a');
180 return new String(buffer);
183 public int indexOf(int ch) {
184 return this.indexOf(ch, 0);
187 public int indexOf(int ch, int fromIndex) {
188 for(int i=fromIndex; i<count; i++)
189 if (this.charAt(i)==ch)
194 public int indexOf(String str) {
195 return this.indexOf(str, 0);
198 public int indexOf(String str, int fromIndex) {
201 for(int i=fromIndex; i<=(count-str.count); i++)
202 if (regionMatches(i, str, 0, str.count))
207 public int indexOfIgnoreCase(String str, int fromIndex) {
212 public int lastIndexOf(String str, int fromIndex) {
213 int k=count-str.count;
217 if (regionMatches(k, str, 0, str.count))
223 public int lastIndexOf(String str) {
224 return lastIndexOf(str, count-str.count);
227 public boolean startsWith(String str) {
228 return regionMatches(0, str, 0, str.count);
231 public boolean startsWith(String str, int toffset) {
232 return regionMatches(toffset, str, 0, str.count);
235 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
236 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
238 for(int i=0; i<len; i++)
239 if (other.value[i+other.offset+ooffset]!=
240 this.value[i+this.offset+toffset])
245 public char[] toCharArray() {
246 char str[]=new char[count];
247 for(int i=0; i<count; i++)
248 str[i]=value[i+offset];
252 public byte[] getBytes() {
253 byte str[]=new byte[count];
254 for(int i=0; i<count; i++)
255 str[i]=(byte)value[i+offset];
259 public void getChars(char dst[], int dstBegin) {
260 getChars(0, count, dst, dstBegin);
263 public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
264 if((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) {
266 System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this);
269 int len = srcEnd - srcBegin;
271 for(int i=srcBegin; i<srcEnd; i++)
272 dst[j++]=value[i+offset];
276 public int length() {
280 public char charAt(int i) {
281 return value[i+offset];
284 public String toString() {
288 public static String valueOf(Object o) {
295 public static String valueOf(boolean b) {
297 return new String("true");
299 return new String("false");
302 public static String valueOf(char c) {
303 char ar[]=new char[1];
305 return new String(ar);
308 public static String valueOf(int x) {
322 chararray=new char[length+1];
324 chararray=new char[length];
334 chararray[--length+voffset]=(char)(x%10+'0');
337 return new String(chararray);
340 public static String valueOf(double val) {
341 char[] chararray=new char[20];
342 String s=new String();
344 s.count=convertdoubletochar(val, chararray);
349 public static native int convertdoubletochar(double val, char [] chararray);
351 public static String valueOf(long x) {
365 chararray=new char[length+1];
367 chararray=new char[length];
377 chararray[--length+voffset]=(char)(x%10+'0');
380 return new String(chararray);
383 public int compareTo(String s) {
384 int smallerlength=count<s.count?count:s.count;
386 for( int i = 0; i < smallerlength; i++ ) {
387 int valDiff = this.charAt(i) - s.charAt(i);
392 return count-s.count;
395 public int hashCode() {
396 if (cachedHashcode!=0)
397 return cachedHashcode;
399 for(int i=0; i<count; i++)
400 hashcode=hashcode*31+value[i+offset];
401 cachedHashcode=hashcode;
405 public boolean equals(Object o) {
406 if (o.getType()!=getType())
411 for(int i=0; i<count; i++) {
412 if (s.value[i+s.offset]!=value[i+offset])
418 public boolean equalsIgnoreCase(String s) {
421 for(int i=0; i<count; i++) {
422 char l=s.value[i+s.offset];
423 char r=value[i+offset];
425 l=(char)((l-'a')+'A');
427 r=(char)((r-'a')+'A');
434 public Vector split() {
435 Vector splitted = new Vector();
440 for(i = 0; i< count; i++) {
441 if(value[i+offset] != '\n' && value[i+offset] != '\t' && value[i+offset] != ' ')
448 if(value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ') {
449 String t=new String();
453 splitted.addElement(t);
456 while( i < count && ( value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ')) {
466 String t=new String();
470 splitted.addElement(t);
476 public boolean contains(String str) {
478 char[] strChar = str.toCharArray();
481 for(i = 0; i < count; i++) {
482 if(value[i] == strChar[0]) {
484 for(j=0; j < str.length() && i+j < count; j++) {
485 if(value[i+j] == strChar[j])
488 if(cnt == str.length())
497 public String trim() {
500 int off = offset; /* avoid getfield opcode */
501 char[] val = value; /* avoid getfield opcode */
503 while ((st < len) && (val[off + st] <= ' ')) {
506 while ((st < len) && (val[off + len - 1] <= ' ')) {
509 return ((st > 0) || (len < count))?substring(st, len):this;
512 public boolean matches(String regex) {
513 System.println("String.matches() is not fully supported");
514 return this.equals(regex);