4 @METHODDEFAULT("O<V,V<C,C<IN,C*,THISLOC=O,RETURNLOC=O")
17 private int cachedHashcode;
22 public String(char c) {
23 char[] str = new char[1];
28 public String(char str[]) {
29 char charstr[] = new char[str.length];
30 for (int i = 0; i < str.length; i++)
33 this.count = str.length;
37 public String(byte str[]) {
38 char charstr[] = new char[str.length];
39 for (int i = 0; i < str.length; i++)
40 charstr[i] = (char) str[i];
42 this.count = str.length;
46 public String(byte str[], int offset, int length) {
47 if (length > (str.length - offset))
48 length = str.length - offset;
49 char charstr[] = new char[length];
50 for (int i = 0; i < length; i++)
51 charstr[i] = (char) str[i + offset];
57 public String(byte str[], String encoding) {
58 int length = this.count;
59 if (length > (str.length))
61 char charstr[] = new char[length];
62 for (int i = 0; i < length; i++)
63 charstr[i] = (char) str[i];
69 public String(char str[], int offset, int length) {
70 if (length > (str.length - offset))
71 length = str.length - offset;
72 char charstr[] = new char[length];
73 for (int i = 0; i < length; i++)
74 charstr[i] = str[i + offset];
80 public String(String str) {
81 this.value = str.value;
82 this.count = str.count;
83 this.offset = str.offset;
86 public String(StringBuffer strbuf) {
87 value = new char[strbuf.length()];
88 count = strbuf.length();
90 for (int i = 0; i < count; i++)
91 value[i] = strbuf.value[i];
94 public boolean endsWith(String suffix) {
95 return regionMatches(count - suffix.count, suffix, 0, suffix.count);
98 public String substring(int beginIndex) {
99 return substring(beginIndex, this.count);
102 public String subString(int beginIndex, int endIndex) {
103 return substring(beginIndex, endIndex);
106 public String substring(int beginIndex, int endIndex) {
107 String str = new String();
108 if (beginIndex > this.count || endIndex > this.count || beginIndex > endIndex) {
110 System.printString("Index error: " + beginIndex + " " + endIndex + " " + count + "\n" + this);
112 str.value = this.value;
113 str.count = endIndex - beginIndex;
114 str.offset = this.offset + beginIndex;
118 public String subString(int beginIndex) {
119 return this.subString(beginIndex, this.count);
122 public int lastindexOf(int ch) {
123 return this.lastindexOf(ch, count - 1);
126 public int lastIndexOf(char ch) {
127 return this.lastindexOf((int) ch, count - 1);
130 public static String concat2(String s1, String s2) {
132 return "null".concat(s2);
134 return s1.concat(s2);
137 public String concat(String str) {
138 String newstr = new String();
139 newstr.count = this.count + str.count;
140 char charstr[] = new char[newstr.count];
142 for (int i = 0; i < count; i++) {
143 charstr[i] = value[i + offset];
145 for (int i = 0; i < str.count; i++) {
146 charstr[i + count] = str.value[i + str.offset];
148 newstr.value = charstr;
152 public int lastindexOf(int ch, int fromIndex) {
153 for (int i = fromIndex; i > 0; i--)
154 if (this.charAt(i) == ch)
159 public String replace(char oldch, char newch) {
160 char[] buffer = new char[count];
161 for (int i = 0; i < count; i++) {
167 return new String(buffer);
170 public String toUpperCase() {
171 char[] buffer = new char[count];
172 for (int i = 0; i < count; i++) {
174 if (x >= 'a' && x <= 'z') {
175 x = (char) ((x - 'a') + 'A');
179 return new String(buffer);
182 public String toLowerCase() {
183 char[] buffer = new char[count];
184 for (int i = 0; i < count; i++) {
186 if (x >= 'A' && x <= 'Z') {
187 x = (char) ((x - 'A') + 'a');
191 return new String(buffer);
194 public int indexOf(int ch) {
195 return this.indexOf(ch, 0);
198 public int indexOf(int ch, int fromIndex) {
199 for (int i = fromIndex; i < count; i++)
200 if (this.charAt(i) == ch)
205 public int indexOf(String str) {
206 return this.indexOf(str, 0);
209 public int indexOf(String str, int fromIndex) {
212 for (int i = fromIndex; i <= (count - str.count); i++)
213 if (regionMatches(i, str, 0, str.count))
218 public int indexOfIgnoreCase(String str, int fromIndex) {
223 public int lastIndexOf(String str, int fromIndex) {
224 int k = count - str.count;
227 for (; k >= 0; k--) {
228 if (regionMatches(k, str, 0, str.count))
234 public int lastIndexOf(String str) {
235 return lastIndexOf(str, count - str.count);
238 public boolean startsWith(String str) {
239 return regionMatches(0, str, 0, str.count);
242 public boolean startsWith(String str, int toffset) {
243 return regionMatches(toffset, str, 0, str.count);
246 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
247 if (toffset < 0 || ooffset < 0 || (toffset + len) > count || (ooffset + len) > other.count)
249 for (int i = 0; i < len; i++)
250 if (other.value[i + other.offset + ooffset] != this.value[i + this.offset + toffset])
255 public char[] toCharArray() {
256 char str[] = new char[count];
257 for (int i = 0; i < count; i++)
258 str[i] = value[i + offset];
262 public byte[] getBytes() {
263 byte str[] = new byte[count];
264 for (int i = 0; i < count; i++)
265 str[i] = (byte) value[i + offset];
269 public void getChars(char dst[], int dstBegin) {
270 getChars(0, count, dst, dstBegin);
273 public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
274 if ((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) {
276 System.printString("Index error: " + srcBegin + " " + srcEnd + " " + count + "\n" + this);
279 int len = srcEnd - srcBegin;
281 for (int i = srcBegin; i < srcEnd; i++)
282 dst[j++] = value[i + offset];
286 public int length() {
290 public char charAt(int i) {
291 return value[i + offset];
294 public String toString() {
298 public static String valueOf(@LOC("IN") Object o) {
305 public static String valueOf(boolean b) {
307 return new String("true");
309 return new String("false");
312 public static String valueOf(@LOC("IN") char c) {
313 @LOC("C") char ar[] = new char[1];
315 return new String(ar);
318 public static String valueOf(@LOC("IN") int x) {
319 @LOC("C") int length = 0;
330 @LOC("C") char chararray[];
332 chararray = new char[length + 1];
334 chararray = new char[length];
335 @LOC("C") int voffset;
344 chararray[--length + voffset] = (char) (x % 10 + '0');
346 } while (length != 0);
347 return new String(chararray);
350 public static String valueOf(double val) {
351 char[] chararray = new char[20];
352 String s = new String();
354 s.count = convertdoubletochar(val, chararray);
359 public static native int convertdoubletochar(double val, char[] chararray);
361 public static String valueOf(@LOC("IN") long x) {
362 @LOC("C") int length = 0;
373 @LOC("C") char chararray[];
375 chararray = new char[length + 1];
377 chararray = new char[length];
378 @LOC("C") int voffset;
387 chararray[--length + voffset] = (char) (x % 10 + '0');
389 } while (length != 0);
390 return new String(chararray);
393 public int compareTo(String s) {
394 int smallerlength = count < s.count ? count : s.count;
396 for (int i = 0; i < smallerlength; i++) {
397 int valDiff = this.charAt(i) - s.charAt(i);
402 return count - s.count;
405 public int hashCode() {
406 if (cachedHashcode != 0)
407 return cachedHashcode;
408 @LOC("C") int hashcode = 0;
409 for (@LOC("C") int i = 0; i < count; i++)
410 hashcode = hashcode * 31 + value[i + offset];
411 cachedHashcode = hashcode;
415 public boolean equals(Object o) {
416 if (o.getType() != getType())
418 String s = (String) o;
419 if (s.count != count)
421 for (int i = 0; i < count; i++) {
422 if (s.value[i + s.offset] != value[i + offset])
428 public boolean equalsIgnoreCase(String s) {
429 if (s.count != count)
431 for (int i = 0; i < count; i++) {
432 char l = s.value[i + s.offset];
433 char r = value[i + offset];
434 if (l >= 'a' && l <= 'z')
435 l = (char) ((l - 'a') + 'A');
436 if (r >= 'a' && r <= 'z')
437 r = (char) ((r - 'a') + 'A');
444 public Vector split() {
445 Vector splitted = new Vector();
450 for (i = 0; i < count; i++) {
451 if (value[i + offset] != '\n' && value[i + offset] != '\t' && value[i + offset] != ' ')
458 if (value[i + offset] == '\n' || value[i + offset] == '\t' || value[i + offset] == ' ') {
459 String t = new String();
463 splitted.addElement(t);
467 && (value[i + offset] == '\n' || value[i + offset] == '\t' || value[i + offset] == ' ')) {
477 String t = new String();
481 splitted.addElement(t);
487 public boolean contains(String str) {
489 char[] strChar = str.toCharArray();
492 for (i = 0; i < count; i++) {
493 if (value[i] == strChar[0]) {
495 for (j = 0; j < str.length() && i + j < count; j++) {
496 if (value[i + j] == strChar[j])
499 if (cnt == str.length())
508 public String trim() {
511 int off = offset; /* avoid getfield opcode */
512 char[] val = value; /* avoid getfield opcode */
514 while ((st < len) && (val[off + st] <= ' ')) {
517 while ((st < len) && (val[off + len - 1] <= ' ')) {
520 return ((st > 0) || (len < count)) ? substring(st, len) : this;
523 public boolean matches(String regex) {
524 System.println("String.matches() is not fully supported");
525 return this.equals(regex);