3 @LATTICE("V<C, V<O,V*")
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 @LATTICE("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT,GLOBALLOC=THIS")
299 public static String valueOf(@LOC("THIS") Object o) {
306 public static String valueOf(@LOC("IN") boolean b) {
308 return new String("true");
310 return new String("false");
313 public static String valueOf(@LOC("IN") char c) {
314 @LOC("C") char ar[] = new char[1];
316 return new String(ar);
319 public static String valueOf(@LOC("C") int x) {
320 @LOC("C") int length = 0;
332 @LOC("C") char chararray[];
334 chararray = new char[length + 1];
336 chararray = new char[length];
337 @LOC("C") int voffset;
347 chararray[--length + voffset] = (char) (x % 10 + '0');
349 } while (length != 0);
350 return new String(chararray);
353 public static String valueOf(@LOC("IN") double val) {
354 @LOC("C") char[] chararray = new char[20];
355 @LOC("V") String s = new String();
357 s.count = convertdoubletochar(val, chararray);
362 public static native int convertdoubletochar(double val, char[] chararray);
364 public static String valueOf(@LOC("C") long x) {
365 @LOC("C") int length = 0;
378 @LOC("C") char chararray[];
380 chararray = new char[length + 1];
382 chararray = new char[length];
383 @LOC("C") int voffset;
393 chararray[--length + voffset] = (char) (x % 10 + '0');
395 } while (length != 0);
396 return new String(chararray);
399 public int compareTo(String s) {
400 int smallerlength = count < s.count ? count : s.count;
402 for (int i = 0; i < smallerlength; i++) {
403 int valDiff = this.charAt(i) - s.charAt(i);
408 return count - s.count;
411 @LATTICE("OUT<THIS,THIS<C,C*,THISLOC=THIS")
413 public int hashCode() {
414 if (cachedHashcode != 0)
415 return cachedHashcode;
416 @LOC("THIS,String.V") int hashcode = 0;
417 for (@LOC("THIS,String.V") int i = 0; i < count; i++)
418 hashcode = hashcode * 31 + value[i + offset];
419 cachedHashcode = hashcode;
423 public boolean equals(Object o) {
424 if (o.getType() != getType())
426 String s = (String) o;
427 if (s.count != count)
429 for (int i = 0; i < count; i++) {
430 if (s.value[i + s.offset] != value[i + offset])
436 public boolean equalsIgnoreCase(String s) {
437 if (s.count != count)
439 for (int i = 0; i < count; i++) {
440 char l = s.value[i + s.offset];
441 char r = value[i + offset];
442 if (l >= 'a' && l <= 'z')
443 l = (char) ((l - 'a') + 'A');
444 if (r >= 'a' && r <= 'z')
445 r = (char) ((r - 'a') + 'A');
452 public Vector split() {
453 Vector splitted = new Vector();
458 for (i = 0; i < count; i++) {
459 if (value[i + offset] != '\n' && value[i + offset] != '\t' && value[i + offset] != ' ')
466 if (value[i + offset] == '\n' || value[i + offset] == '\t' || value[i + offset] == ' ') {
467 String t = new String();
471 splitted.addElement(t);
475 && (value[i + offset] == '\n' || value[i + offset] == '\t' || value[i + offset] == ' ')) {
485 String t = new String();
489 splitted.addElement(t);
495 public boolean contains(String str) {
497 char[] strChar = str.toCharArray();
500 for (i = 0; i < count; i++) {
501 if (value[i] == strChar[0]) {
503 for (j = 0; j < str.length() && i + j < count; j++) {
504 if (value[i + j] == strChar[j])
507 if (cnt == str.length())
516 public String trim() {
519 int off = offset; /* avoid getfield opcode */
520 char[] val = value; /* avoid getfield opcode */
522 while ((st < len) && (val[off + st] <= ' ')) {
525 while ((st < len) && (val[off + len - 1] <= ' ')) {
528 return ((st > 0) || (len < count)) ? substring(st, len) : this;
531 public boolean matches(String regex) {
532 System.println("String.matches() is not fully supported");
533 return this.equals(regex);