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(String str) {
31 this.offset=str.offset;
34 public String(StringBuffer strbuf) {
35 value=new char[strbuf.length()];
36 count=strbuf.length();
38 for(int i=0;i<count;i++)
39 value[i]=strbuf.value[i];
42 public boolean endsWith(String suffix) {
43 return regionMatches(count - suffix.count, suffix, 0, suffix.count);
47 public String substring(int beginIndex) {
48 return substring(beginIndex, this.count);
51 public String subString(int beginIndex, int endIndex) {
52 return substring(beginIndex, endIndex);
55 public String substring(int beginIndex, int endIndex) {
56 String str=new String();
57 if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
59 System.printString("Index error: "+this+" "+beginIndex+" "+endIndex+"\n");
62 str.count=endIndex-beginIndex;
63 str.offset=this.offset+beginIndex;
67 public String subString(int beginIndex) {
68 return this.subString(beginIndex, this.count);
71 public int lastindexOf(int ch) {
72 return this.lastindexOf(ch, count - 1);
75 public static String concat2(String s1, String s2) {
77 return "null".concat(s2);
82 public String concat(String str) {
83 String newstr=new String();
84 newstr.count=this.count+str.count;
85 char charstr[]=new char[newstr.count];
88 for(int i=0;i<count;i++) {
89 charstr[i]=value[i+offset];
91 for(int i=0;i<str.count;i++) {
92 charstr[i+count]=str.value[i+str.offset];
97 public int lastindexOf(int ch, int fromIndex) {
98 for(int i=fromIndex;i>0;i--)
99 if (this.charAt(i)==ch)
104 public String replace(char oldch, char newch) {
105 char[] buffer=new char[count];
106 for(int i=0;i<count;i++) {
112 return new String(buffer);
115 public String toUpperCase() {
116 char[] buffer=new char[count];
117 for(int i=0;i<count;i++) {
119 if (x>='a'&&x<='z') {
120 x=(char) ((x-'a')+'A');
124 return new String(buffer);
127 public int indexOf(int ch) {
128 return this.indexOf(ch, 0);
131 public int indexOf(int ch, int fromIndex) {
132 for(int i=fromIndex;i<count;i++)
133 if (this.charAt(i)==ch)
138 public int indexOf(String str) {
139 return this.indexOf(str, 0);
142 public int indexOf(String str, int fromIndex) {
145 for(int i=fromIndex;i<=(count-str.count);i++)
146 if (regionMatches(i, str, 0, str.count))
151 public int lastIndexOf(String str, int fromIndex) {
152 int k=count-str.count;
156 if (regionMatches(k, str, 0, str.count))
162 public int lastIndexOf(String str) {
163 return lastIndexOf(str, count-str.count);
166 public boolean startsWith(String str) {
167 return regionMatches(0, str, 0, str.count);
170 public boolean startsWith(String str, int toffset) {
171 return regionMatches(toffset, str, 0, str.count);
174 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
175 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
177 for(int i=0;i<len;i++)
178 if (other.value[i+other.offset+ooffset]!=
179 this.value[i+this.offset+toffset])
184 public char[] toCharArray() {
185 char str[]=new char[count];
186 for(int i=0;i<count;i++)
187 str[i]=value[i+offset];
191 public byte[] getBytes() {
192 byte str[]=new byte[count];
193 for(int i=0;i<count;i++)
194 str[i]=(byte)value[i+offset];
198 public int length() {
202 public char charAt(int i) {
203 return value[i+offset];
206 public String toString() {
210 public static String valueOf(Object o) {
217 public static String valueOf(char c) {
218 char ar[]=new char[1];
220 return new String(ar);
223 public static String valueOf(int x) {
237 chararray=new char[length+1];
239 chararray=new char[length];
249 chararray[--length+voffset]=(char)(x%10+'0');
252 return new String(chararray);
255 public static String valueOf(long x) {
269 chararray=new char[length+1];
271 chararray=new char[length];
281 chararray[--length+voffset]=(char)(x%10+'0');
284 return new String(chararray);
287 public int hashCode() {
288 if (cachedHashcode!=0)
289 return cachedHashcode;
291 for(int i=0;i<count;i++)
292 hashcode=hashcode*31+value[i+offset];
293 cachedHashcode=hashcode;
297 public boolean equals(Object o) {
298 if (o.getType()!=getType())
303 for(int i=0;i<count;i++) {
304 if (s.value[i+s.offset]!=value[i+offset])
310 public boolean equalsIgnoreCase(String s) {
313 for(int i=0;i<count;i++) {
314 char l=s.value[i+s.offset];
315 char r=value[i+offset];
317 l=(char)((l-'a')+'A');
319 r=(char)((r-'a')+'A');