5 private int cachedHashcode;
10 public String(char str[]) {
11 char charstr[]=new char[str.length];
12 for(int i=0; i<str.length; i++)
15 this.count=str.length;
19 public String(byte str[]) {
20 char charstr[]=new char[str.length];
21 for(int i=0; i<str.length; i++)
22 charstr[i]=(char)str[i];
24 this.count=str.length;
28 public String(byte str[], int offset, int length) {
29 if (length>(str.length-offset))
30 length=str.length-offset;
31 char charstr[]=new char[length];
32 for(int i=0; i<length; i++)
33 charstr[i]=(char)str[i+offset];
39 public String(String str) {
42 this.offset=str.offset;
45 public String(StringBuffer strbuf) {
46 value=new char[strbuf.length()];
47 count=strbuf.length();
49 for(int i=0; i<count; i++)
50 value[i]=strbuf.value[i];
53 public boolean endsWith(String suffix) {
54 return regionMatches(count - suffix.count, suffix, 0, suffix.count);
58 public String substring(int beginIndex) {
59 return substring(beginIndex, this.count);
62 public String subString(int beginIndex, int endIndex) {
63 return substring(beginIndex, endIndex);
66 public String substring(int beginIndex, int endIndex) {
67 String str=new String();
68 if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
70 System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this);
73 str.count=endIndex-beginIndex;
74 str.offset=this.offset+beginIndex;
78 public String subString(int beginIndex) {
79 return this.subString(beginIndex, this.count);
82 public int lastindexOf(int ch) {
83 return this.lastindexOf(ch, count - 1);
86 public static String concat2(String s1, String s2) {
88 return "null".concat(s2);
93 public String concat(String str) {
94 String newstr=new String();
95 newstr.count=this.count+str.count;
96 char charstr[]=new char[newstr.count];
99 for(int i=0; i<count; i++) {
100 charstr[i]=value[i+offset];
102 for(int i=0; i<str.count; i++) {
103 charstr[i+count]=str.value[i+str.offset];
108 public int lastindexOf(int ch, int fromIndex) {
109 for(int i=fromIndex; i>0; i--)
110 if (this.charAt(i)==ch)
115 public String replace(char oldch, char newch) {
116 char[] buffer=new char[count];
117 for(int i=0; i<count; i++) {
123 return new String(buffer);
126 public String toUpperCase() {
127 char[] buffer=new char[count];
128 for(int i=0; i<count; i++) {
130 if (x>='a'&&x<='z') {
131 x=(char) ((x-'a')+'A');
135 return new String(buffer);
138 public int indexOf(int ch) {
139 return this.indexOf(ch, 0);
142 public int indexOf(int ch, int fromIndex) {
143 for(int i=fromIndex; i<count; i++)
144 if (this.charAt(i)==ch)
149 public int indexOf(String str) {
150 return this.indexOf(str, 0);
153 public int indexOf(String str, int fromIndex) {
156 for(int i=fromIndex; i<=(count-str.count); i++)
157 if (regionMatches(i, str, 0, str.count))
162 public int lastIndexOf(String str, int fromIndex) {
163 int k=count-str.count;
167 if (regionMatches(k, str, 0, str.count))
173 public int lastIndexOf(String str) {
174 return lastIndexOf(str, count-str.count);
177 public boolean startsWith(String str) {
178 return regionMatches(0, str, 0, str.count);
181 public boolean startsWith(String str, int toffset) {
182 return regionMatches(toffset, str, 0, str.count);
185 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
186 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
188 for(int i=0; i<len; i++)
189 if (other.value[i+other.offset+ooffset]!=
190 this.value[i+this.offset+toffset])
195 public char[] toCharArray() {
196 char str[]=new char[count];
197 for(int i=0; i<count; i++)
198 str[i]=value[i+offset];
202 public byte[] getBytes() {
203 byte str[]=new byte[count];
204 for(int i=0; i<count; i++)
205 str[i]=(byte)value[i+offset];
209 public int length() {
213 public char charAt(int i) {
214 return value[i+offset];
217 public String toString() {
221 public static String valueOf(Object o) {
228 public static String valueOf(boolean b) {
230 return new String("true");
232 return new String("false");
235 public static String valueOf(char c) {
236 char ar[]=new char[1];
238 return new String(ar);
241 public static String valueOf(int x) {
255 chararray=new char[length+1];
257 chararray=new char[length];
267 chararray[--length+voffset]=(char)(x%10+'0');
270 return new String(chararray);
273 public static String valueOf(double x) {
274 return valueOf((long)x);
277 public static String valueOf(long x) {
291 chararray=new char[length+1];
293 chararray=new char[length];
303 chararray[--length+voffset]=(char)(x%10+'0');
306 return new String(chararray);
309 public int compareTo( String s ) {
310 int lenDiff = this.length() - s.length();
314 for( int i = 0; i < this.length(); ++i ) {
315 int valDiff = this.charAt(i) - s.charAt(i);
323 public int hashCode() {
324 if (cachedHashcode!=0)
325 return cachedHashcode;
327 for(int i=0; i<count; i++)
328 hashcode=hashcode*31+value[i+offset];
329 cachedHashcode=hashcode;
333 public boolean equals(Object o) {
334 if (o.getType()!=getType())
339 for(int i=0; i<count; i++) {
340 if (s.value[i+s.offset]!=value[i+offset])
346 public boolean equalsIgnoreCase(String s) {
349 for(int i=0; i<count; i++) {
350 char l=s.value[i+s.offset];
351 char r=value[i+offset];
353 l=(char)((l-'a')+'A');
355 r=(char)((r-'a')+'A');