4 data<proc,proc<c,c<in,in*,c*,proc*,data*
7 @LOC("data") char value[];
8 @LOC("data") int count;
9 @LOC("data") int offset;
10 @LOC("data") private int cachedHashcode;
15 public String(@LOC("in") char c) {
16 @LOC("data") char[] str = new char[1];
21 public String(@LOC("in") char str[]) {
22 @LOC("in") char charstr[]=new char[str.length];
23 for(@LOC("c") int i=0; i<str.length; i++)
26 this.count=str.length;
30 public String(@LOC("in") byte str[]) {
31 @LOC("in") char charstr[]=new char[str.length];
32 for(@LOC("c") int i=0; i<str.length; i++)
33 charstr[i]=(char)str[i];
35 this.count=str.length;
39 public String(@LOC("in") byte str[], @LOC("in") int offset, @LOC("in") int length) {
40 if (length>(str.length-offset))
41 length=str.length-offset;
42 @LOC("in") char charstr[]=new char[length];
43 for(@LOC("c")int i=0; i<length; i++)
44 charstr[i]=(char)str[i+offset];
50 public String(@LOC("in") byte str[], @LOC("in") String encoding) {
51 @LOC("data") int length = this.count;
52 if (length>(str.length))
54 @LOC("data") char charstr[]=new char[length];
55 for(@LOC("c") int i=0; i<length; i++)
56 charstr[i]=(char)str[i];
62 public String(@LOC("in") char str[], @LOC("in") int offset, @LOC("in") int length) {
63 if (length>(str.length-offset))
64 length=str.length-offset;
65 @LOC("in") char charstr[]=new char[length];
66 for(@LOC("c") int i=0; i<length; i++)
67 charstr[i]=str[i+offset];
73 public String(@LOC("in") String str) {
76 this.offset=str.offset;
79 public String concat(@LOC("in") String str) {
80 @LOC("data") String newstr=new String();
81 newstr.count=this.count+str.count;
82 @LOC("data") char charstr[]=new char[newstr.count];
85 for(@LOC("c") int i=0; i<count; i++) {
86 charstr[i]=value[i+offset];
88 for(@LOC("c") int i=0; i<str.count; i++) {
89 charstr[i+count]=str.value[i+str.offset];
95 public String(StringBuffer strbuf) {
96 value=new char[strbuf.length()];
97 count=strbuf.length();
99 for(int i=0; i<count; i++)
100 value[i]=strbuf.value[i];
105 public boolean endsWith(@LOC("in") String suffix) {
106 return regionMatches(count - suffix.count, suffix, 0, suffix.count);
110 public String substring(@LOC("in") int beginIndex) {
111 return substring(beginIndex, this.count);
114 public String subString(@LOC("in") int beginIndex, @LOC("in") int endIndex) {
115 return substring(beginIndex, endIndex);
118 public String substring(@LOC("in") int beginIndex, @LOC("in") int endIndex) {
119 String str=new String();
120 if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
122 System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this);
124 str.value=this.value;
125 str.count=endIndex-beginIndex;
126 str.offset=this.offset+beginIndex;
130 public String subString(@LOC("in") int beginIndex) {
131 return this.subString(beginIndex, this.count);
134 public int lastindexOf(@LOC("in") int ch) {
135 return this.lastindexOf(ch, count - 1);
138 public int lastIndexOf(@LOC("in") char ch) {
139 return this.lastindexOf((int)ch, count - 1);
142 public static String concat2(@LOC("in") String s1, @LOC("in") String s2) {
144 return "null".concat(s2);
146 return s1.concat(s2);
149 public int lastindexOf(@LOC("in") int ch, @LOC("in") int fromIndex) {
150 for(int i=fromIndex; i>0; i--)
151 if (this.charAt(i)==ch)
156 public String replace(@LOC("in") char oldch, @LOC("in") char newch) {
157 char[] buffer=new char[count];
158 for(int i=0; i<count; i++) {
164 return new String(buffer);
167 public String toUpperCase() {
168 char[] buffer=new char[count];
169 for(int i=0; i<count; i++) {
171 if (x>='a'&&x<='z') {
172 x=(char) ((x-'a')+'A');
176 return new String(buffer);
179 public String toLowerCase() {
180 char[] buffer=new char[count];
181 for(int i=0; i<count; i++) {
183 if (x>='A'&&x<='Z') {
184 x=(char) ((x-'A')+'a');
188 return new String(buffer);
191 public int indexOf(@LOC("in") int ch) {
192 return this.indexOf(ch, 0);
195 public int indexOf(@LOC("in") int ch, @LOC("in") int fromIndex) {
196 for(int i=fromIndex; i<count; i++)
197 if (this.charAt(i)==ch)
202 public int indexOf(@LOC("in") String str) {
203 return this.indexOf(str, 0);
206 public int indexOf(@LOC("in") String str, @LOC("in") int fromIndex) {
209 for(int i=fromIndex; i<=(count-str.count); i++)
210 if (regionMatches(i, str, 0, str.count))
215 public int indexOfIgnoreCase(@LOC("in") String str, @LOC("in") int fromIndex) {
220 public int lastIndexOf(@LOC("in") String str, @LOC("in") int fromIndex) {
221 int k=count-str.count;
225 if (regionMatches(k, str, 0, str.count))
231 public int lastIndexOf(@LOC("in") String str) {
232 return lastIndexOf(str, count-str.count);
235 public boolean startsWith(@LOC("in") String str) {
236 return regionMatches(0, str, 0, str.count);
239 public boolean startsWith(@LOC("in") String str, @LOC("in") int toffset) {
240 return regionMatches(toffset, str, 0, str.count);
243 public boolean regionMatches(@LOC("in") int toffset, @LOC("in") String other, @LOC("in") int ooffset, @LOC("in") int len) {
244 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
246 for(int i=0; i<len; i++)
247 if (other.value[i+other.offset+ooffset]!=
248 this.value[i+this.offset+toffset])
253 public char[] toCharArray() {
254 @LOC("data") char str[]=new char[count];
255 for(@LOC("data") int i=0; i<count; i++)
256 str[i]=value[i+offset];
260 public byte[] getBytes() {
261 byte str[]=new byte[count];
262 for(int i=0; i<count; i++)
263 str[i]=(byte)value[i+offset];
267 public void getChars(@LOC("in") char dst[], @LOC("in") int dstBegin) {
268 getChars(0, count, dst, dstBegin);
271 public void getChars(@LOC("in") int srcBegin, @LOC("in") int srcEnd, @LOC("in") char dst[],@LOC("in") int dstBegin) {
272 if((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) {
274 System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this);
277 int len = srcEnd - srcBegin;
279 for(int i=srcBegin; i<srcEnd; i++)
280 dst[j++]=value[i+offset];
284 public int length() {
288 public char charAt(@LOC("in") int i) {
289 return value[i+offset];
292 public String toString() {
296 public static String valueOf(@LOC("in") Object o) {
303 public static String valueOf(@LOC("in") int x) {
304 @LOC("in") int length=0;
315 @LOC("in") char chararray[];
317 chararray=new char[length+1];
319 chararray=new char[length];
320 @LOC("in") int voffset;
329 chararray[--length+voffset]=(char)(x%10+'0');
332 return new String(chararray);
336 public static String valueOf(@LOC("in") boolean b) {
338 return new String("true");
340 return new String("false");
343 public static String valueOf(@LOC("in") char c) {
344 @LOC("data") char ar[]=new char[1];
346 return new String(ar);
351 public static String valueOf(@LOC("in") double val) {
352 char[] chararray=new char[20];
353 String s=new String();
355 s.count=convertdoubletochar(val, chararray);
360 public static native int convertdoubletochar(double val, char [] chararray);
362 public static String valueOf(@LOC("in") long x) {
376 chararray=new char[length+1];
378 chararray=new char[length];
388 chararray[--length+voffset]=(char)(x%10+'0');
391 return new String(chararray);
394 public int compareTo(@LOC("in") String s) {
395 int smallerlength=count<s.count?count:s.count;
397 for( int i = 0; i < smallerlength; i++ ) {
398 int valDiff = this.charAt(i) - s.charAt(i);
403 return count-s.count;
406 public int hashCode() {
407 if (cachedHashcode!=0)
408 return cachedHashcode;
409 @LOC("data") int hashcode=0;
410 for(@LOC("c") int i=0; i<count; i++)
411 hashcode=hashcode*31+value[i+offset];
412 cachedHashcode=hashcode;
416 public boolean equals(@LOC("in") Object o) {
417 if (o.getType()!=getType())
419 @LOC("in") String s=(String)o;
422 for(@LOC("c") int i=0; i<count; i++) {
423 if (s.value[i+s.offset]!=value[i+offset])
429 public boolean equalsIgnoreCase(@LOC("in") String s) {
432 for(int i=0; i<count; i++) {
433 char l=s.value[i+s.offset];
434 char r=value[i+offset];
436 l=(char)((l-'a')+'A');
438 r=(char)((r-'a')+'A');
445 public Vector split() {
446 Vector splitted = new Vector();
451 for(i = 0; i< count;i++) {
452 if(value[i+offset] != '\n' && value[i+offset] != '\t' && value[i+offset] != ' ')
459 if(value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ') {
460 String t=new String();
464 splitted.addElement(t);
467 while( i < count && ( value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ')) {
477 String t=new String();
481 splitted.addElement(t);
487 public boolean contains(@LOC("in") String str)
490 char[] strChar = str.toCharArray();
493 for(i = 0; i < count; i++) {
494 if(value[i] == strChar[0]) {
496 for(j=0; j < str.length() && i+j < count;j++) {
497 if(value[i+j] == strChar[j])
500 if(cnt == str.length())
509 public String trim() {
512 int off = offset; //avoid getfield opcode
513 char[] val = value; // avoid getfield opcode
515 while ((st < len) && (val[off + st] <= ' ')) {
518 while ((st < len) && (val[off + len - 1] <= ' ')) {
521 return ((st > 0) || (len < count)) ? substring(st, len) : this;
524 public boolean matches(@LOC("in") String regex) {
525 System.println("String.matches() is not fully supported");
526 return this.equals(regex);