7 private int cachedHashcode;
12 public String(char c) {
13 char[] str = new char[1];
18 public String(char str[]) {
19 char charstr[]=new char[str.length];
20 for(int i=0; i<str.length; i++)
23 this.count=str.length;
27 public String(byte str[]) {
28 char charstr[]=new char[str.length];
29 for(int i=0; i<str.length; i++)
30 charstr[i]=(char)str[i];
32 this.count=str.length;
36 public String(byte str[], int offset, int length) {
37 if (length>(str.length-offset))
38 length=str.length-offset;
39 char charstr[]=new char[length];
40 for(int i=0; i<length; i++)
41 charstr[i]=(char)str[i+offset];
47 public String(byte str[], String encoding) {
48 int length = this.count;
49 if (length>(str.length))
51 char charstr[]=new char[length];
52 for(int i=0; i<length; i++)
53 charstr[i]=(char)str[i];
59 public String(char str[], int offset, int length) {
60 if (length>(str.length-offset))
61 length=str.length-offset;
62 char charstr[]=new char[length];
63 for(int i=0; i<length; i++)
64 charstr[i]=str[i+offset];
70 public String(String str) {
73 this.offset=str.offset;
76 public String(StringBuffer strbuf) {
77 value=new char[strbuf.length()];
78 count=strbuf.length();
80 for(int i=0; i<count; i++)
81 value[i]=strbuf.value[i];
84 public boolean endsWith(String suffix) {
85 return regionMatches(count - suffix.count, suffix, 0, suffix.count);
89 public String substring(int beginIndex) {
90 return substring(beginIndex, this.count);
93 public String subString(int beginIndex, int endIndex) {
94 return substring(beginIndex, endIndex);
97 public String substring(int beginIndex, int endIndex) {
98 String str=new String();
99 if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
101 System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this);
103 str.value=this.value;
104 str.count=endIndex-beginIndex;
105 str.offset=this.offset+beginIndex;
109 public String subString(int beginIndex) {
110 return this.subString(beginIndex, this.count);
113 public int lastindexOf(int ch) {
114 return this.lastindexOf(ch, count - 1);
117 public int lastIndexOf(char ch) {
118 return this.lastindexOf((int)ch, count - 1);
121 public static String concat2(String s1, String s2) {
123 return "null".concat(s2);
125 return s1.concat(s2);
128 public String concat(String str) {
129 String newstr=new String();
130 newstr.count=this.count+str.count;
131 char charstr[]=new char[newstr.count];
132 newstr.value=charstr;
134 for(int i=0; i<count; i++) {
135 charstr[i]=value[i+offset];
137 for(int i=0; i<str.count; i++) {
138 charstr[i+count]=str.value[i+str.offset];
143 public int lastindexOf(int ch, int fromIndex) {
144 for(int i=fromIndex; i>0; i--)
145 if (this.charAt(i)==ch)
150 public String replace(char oldch, char newch) {
151 char[] buffer=new char[count];
152 for(int i=0; i<count; i++) {
158 return new String(buffer);
161 public String toUpperCase() {
162 char[] buffer=new char[count];
163 for(int i=0; i<count; i++) {
165 if (x>='a'&&x<='z') {
166 x=(char) ((x-'a')+'A');
170 return new String(buffer);
173 public String toLowerCase() {
174 char[] buffer=new char[count];
175 for(int i=0; i<count; i++) {
177 if (x>='A'&&x<='Z') {
178 x=(char) ((x-'A')+'a');
182 return new String(buffer);
185 public int indexOf(int ch) {
186 return this.indexOf(ch, 0);
189 public int indexOf(int ch, int fromIndex) {
190 for(int i=fromIndex; i<count; i++)
191 if (this.charAt(i)==ch)
196 public int indexOf(String str) {
197 return this.indexOf(str, 0);
200 public int indexOf(String str, int fromIndex) {
203 for(int i=fromIndex; i<=(count-str.count); i++)
204 if (regionMatches(i, str, 0, str.count))
209 public int indexOfIgnoreCase(String str, int fromIndex) {
214 public int lastIndexOf(String str, int fromIndex) {
215 int k=count-str.count;
219 if (regionMatches(k, str, 0, str.count))
225 public int lastIndexOf(String str) {
226 return lastIndexOf(str, count-str.count);
229 public boolean startsWith(String str) {
230 return regionMatches(0, str, 0, str.count);
233 public boolean startsWith(String str, int toffset) {
234 return regionMatches(toffset, str, 0, str.count);
237 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
238 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
240 for(int i=0; i<len; i++)
241 if (other.value[i+other.offset+ooffset]!=
242 this.value[i+this.offset+toffset])
247 public char[] toCharArray() {
248 char str[]=new char[count];
249 for(int i=0; i<count; i++)
250 str[i]=value[i+offset];
254 public byte[] getBytes() {
255 byte str[]=new byte[count];
256 for(int i=0; i<count; i++)
257 str[i]=(byte)value[i+offset];
261 public void getChars(char dst[], int dstBegin) {
262 getChars(0, count, dst, dstBegin);
265 public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
266 if((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) {
268 System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this);
271 int len = srcEnd - srcBegin;
273 for(int i=srcBegin; i<srcEnd; i++)
274 dst[j++]=value[i+offset];
278 public int length() {
282 public char charAt(int i) {
283 return value[i+offset];
286 public String toString() {
290 public static String valueOf(Object o) {
297 public static String valueOf(boolean b) {
299 return new String("true");
301 return new String("false");
304 public static String valueOf(char c) {
305 char ar[]=new char[1];
307 return new String(ar);
310 public static String valueOf(int x) {
324 chararray=new char[length+1];
326 chararray=new char[length];
336 chararray[--length+voffset]=(char)(x%10+'0');
339 return new String(chararray);
342 public static String valueOf(double val) {
343 char[] chararray=new char[20];
344 String s=new String();
346 s.count=convertdoubletochar(val, chararray);
351 public static native int convertdoubletochar(double val, char [] chararray);
353 public static String valueOf(long x) {
367 chararray=new char[length+1];
369 chararray=new char[length];
379 chararray[--length+voffset]=(char)(x%10+'0');
382 return new String(chararray);
385 public int compareTo(String s) {
386 int smallerlength=count<s.count?count:s.count;
388 for( int i = 0; i < smallerlength; i++ ) {
389 int valDiff = this.charAt(i) - s.charAt(i);
394 return count-s.count;
397 public int hashCode() {
398 if (cachedHashcode!=0)
399 return cachedHashcode;
401 for(int i=0; i<count; i++)
402 hashcode=hashcode*31+value[i+offset];
403 cachedHashcode=hashcode;
407 public boolean equals(Object o) {
408 if (o.getType()!=getType())
413 for(int i=0; i<count; i++) {
414 if (s.value[i+s.offset]!=value[i+offset])
420 public boolean equalsIgnoreCase(String s) {
423 for(int i=0; i<count; i++) {
424 char l=s.value[i+s.offset];
425 char r=value[i+offset];
427 l=(char)((l-'a')+'A');
429 r=(char)((r-'a')+'A');
436 public Vector split() {
437 Vector splitted = new Vector();
442 for(i = 0; i< count; i++) {
443 if(value[i+offset] != '\n' && value[i+offset] != '\t' && value[i+offset] != ' ')
450 if(value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ') {
451 String t=new String();
455 splitted.addElement(t);
458 while( i < count && ( value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ')) {
468 String t=new String();
472 splitted.addElement(t);
478 public boolean contains(String str) {
480 char[] strChar = str.toCharArray();
483 for(i = 0; i < count; i++) {
484 if(value[i] == strChar[0]) {
486 for(j=0; j < str.length() && i+j < count; j++) {
487 if(value[i+j] == strChar[j])
490 if(cnt == str.length())
499 public String trim() {
502 int off = offset; /* avoid getfield opcode */
503 char[] val = value; /* avoid getfield opcode */
505 while ((st < len) && (val[off + st] <= ' ')) {
508 while ((st < len) && (val[off + len - 1] <= ' ')) {
511 return ((st > 0) || (len < count))?substring(st, len):this;
514 public boolean matches(String regex) {
515 System.println("String.matches() is not fully supported");
516 return this.equals(regex);