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 lastIndexOf(String str, int fromIndex) {
181 int k=count-str.count;
185 if (regionMatches(k, str, 0, str.count))
191 public int lastIndexOf(String str) {
192 return lastIndexOf(str, count-str.count);
195 public boolean startsWith(String str) {
196 return regionMatches(0, str, 0, str.count);
199 public boolean startsWith(String str, int toffset) {
200 return regionMatches(toffset, str, 0, str.count);
203 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
204 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
206 for(int i=0; i<len; i++)
207 if (other.value[i+other.offset+ooffset]!=
208 this.value[i+this.offset+toffset])
213 public char[] toCharArray() {
214 char str[]=new char[count];
215 for(int i=0; i<count; i++)
216 str[i]=value[i+offset];
220 public byte[] getBytes() {
221 byte str[]=new byte[count];
222 for(int i=0; i<count; i++)
223 str[i]=(byte)value[i+offset];
227 public int length() {
231 public char charAt(int i) {
232 return value[i+offset];
235 public String toString() {
239 public static String valueOf(Object o) {
246 public static String valueOf(boolean b) {
248 return new String("true");
250 return new String("false");
253 public static String valueOf(char c) {
254 char ar[]=new char[1];
256 return new String(ar);
259 public static String valueOf(int x) {
273 chararray=new char[length+1];
275 chararray=new char[length];
285 chararray[--length+voffset]=(char)(x%10+'0');
288 return new String(chararray);
291 public static String valueOf(double val) {
292 char[] chararray=new char[10];
293 String s=new String();
295 s.count=convertdoubletochar(val, chararray);
300 public static native int convertdoubletochar(double val, char [] chararray);
302 public static String valueOf(long x) {
316 chararray=new char[length+1];
318 chararray=new char[length];
328 chararray[--length+voffset]=(char)(x%10+'0');
331 return new String(chararray);
334 public int compareTo(String s) {
335 int smallerlength=count<s.count?count:s.count;
337 for( int i = 0; i < smallerlength; i++ ) {
338 int valDiff = this.charAt(i) - s.charAt(i);
343 return count-s.count;
346 public int hashCode() {
347 if (cachedHashcode!=0)
348 return cachedHashcode;
350 for(int i=0; i<count; i++)
351 hashcode=hashcode*31+value[i+offset];
352 cachedHashcode=hashcode;
356 public boolean equals(Object o) {
357 if (o.getType()!=getType())
362 for(int i=0; i<count; i++) {
363 if (s.value[i+s.offset]!=value[i+offset])
369 public boolean equalsIgnoreCase(String s) {
372 for(int i=0; i<count; i++) {
373 char l=s.value[i+s.offset];
374 char r=value[i+offset];
376 l=(char)((l-'a')+'A');
378 r=(char)((r-'a')+'A');