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) {
297 @LOC("proc") String rValue;
305 public static String valueOf(@LOC("in") int x) {
306 @LOC("in") int length=0;
317 @LOC("in") char chararray[];
319 chararray=new char[length+1];
321 chararray=new char[length];
322 @LOC("in") int voffset;
331 chararray[--length+voffset]=(char)(x%10+'0');
334 return new String(chararray);
338 public static String valueOf(@LOC("in") boolean b) {
340 return new String("true");
342 return new String("false");
345 public static String valueOf(@LOC("in") char c) {
346 @LOC("data") char ar[]=new char[1];
348 return new String(ar);
353 public static String valueOf(@LOC("in") double val) {
354 char[] chararray=new char[20];
355 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("in") long x) {
378 chararray=new char[length+1];
380 chararray=new char[length];
390 chararray[--length+voffset]=(char)(x%10+'0');
393 return new String(chararray);
396 public int compareTo(@LOC("in") String s) {
397 int smallerlength=count<s.count?count:s.count;
399 for( int i = 0; i < smallerlength; i++ ) {
400 int valDiff = this.charAt(i) - s.charAt(i);
405 return count-s.count;
408 public int hashCode() {
409 if (cachedHashcode!=0)
410 return cachedHashcode;
411 @LOC("data") int hashcode=0;
412 for(@LOC("c") int i=0; i<count; i++)
413 hashcode=hashcode*31+value[i+offset];
414 cachedHashcode=hashcode;
418 public boolean equals(@LOC("in") Object o) {
419 if (o.getType()!=getType())
421 @LOC("in") String s=(String)o;
424 for(@LOC("c") int i=0; i<count; i++) {
425 if (s.value[i+s.offset]!=value[i+offset])
431 public boolean equalsIgnoreCase(@LOC("in") String s) {
434 for(int i=0; i<count; i++) {
435 char l=s.value[i+s.offset];
436 char r=value[i+offset];
438 l=(char)((l-'a')+'A');
440 r=(char)((r-'a')+'A');
447 public Vector split() {
448 Vector splitted = new Vector();
453 for(i = 0; i< count;i++) {
454 if(value[i+offset] != '\n' && value[i+offset] != '\t' && value[i+offset] != ' ')
461 if(value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ') {
462 String t=new String();
466 splitted.addElement(t);
469 while( i < count && ( value[i+offset] == '\n' || value[i+offset] == '\t' || value[i+offset] == ' ')) {
479 String t=new String();
483 splitted.addElement(t);
489 public boolean contains(@LOC("in") String str)
492 char[] strChar = str.toCharArray();
495 for(i = 0; i < count; i++) {
496 if(value[i] == strChar[0]) {
498 for(j=0; j < str.length() && i+j < count;j++) {
499 if(value[i+j] == strChar[j])
502 if(cnt == str.length())
511 public String trim() {
514 int off = offset; //avoid getfield opcode
515 char[] val = value; // avoid getfield opcode
517 while ((st < len) && (val[off + st] <= ' ')) {
520 while ((st < len) && (val[off + len - 1] <= ' ')) {
523 return ((st > 0) || (len < count)) ? substring(st, len) : this;
526 public boolean matches(@LOC("in") String regex) {
527 System.println("String.matches() is not fully supported");
528 return this.equals(regex);