7 @METHODDEFAULT("O<V,V<C,C<IN,THISLOC=O,C*")
10 @LOC("V") char value[];
13 @LOC("V") private int cachedHashcode;
18 public String(byte str[]) {
19 char charstr[]=new char[str.length];
20 for(int i=0; i<str.length; i++)
21 charstr[i]=(char)str[i];
23 this.count=str.length;
27 public String(char str[], int offset, int length) {
28 if (length>(str.length-offset))
29 length=str.length-offset;
30 char charstr[]=new char[length];
31 for(int i=0; i<length; i++)
32 charstr[i]=str[i+offset];
39 public String(byte str[], String encoding) {
40 int length = this.count;
41 if (length>(str.length))
43 char charstr[]=new char[length];
44 for(int i=0; i<length; i++)
45 charstr[i]=(char)str[i];
51 public String(@LOC("IN") String str) {
54 this.offset=str.offset;
57 public String(StringBuffer strbuf) {
58 value=new char[strbuf.length()];
59 count=strbuf.length();
61 for(int i=0; i<count; i++)
62 value[i]=strbuf.value[i];
65 public String(@LOC("IN") char c) {
66 @LOC("V") char[] str = new char[1];
71 public String(@LOC("IN") char str[]) {
72 @LOC("V") char charstr[]=new char[str.length];
73 for(@LOC("C") int i=0; i<str.length; i++)
77 this.count=str.length;
81 public String(String str) {
84 this.offset=str.offset;
87 @LATTICE("O<V,V<C,C<IN,THISLOC=IN,C*")
89 public String concat(@LOC("IN") String str) {
90 @LOC("O") String newstr=new String(); // create new one, it has OUT location
91 @LOC("C") int newCount=this.count+str.count;
93 @LOC("V") char charstr[]=new char[newCount];
95 // here, for loop introduces indirect flow from [C] to [V]
96 for(@LOC("C") int i=0; i<count; i++) {
97 // value flows from GLB(THISLOC,C,THISLOC.V)=(THISLOC,TOP) to [V]
98 charstr[i]=value[i+offset];
100 for(@LOC("C") int i=0; i<str.count; i++) {
101 charstr[i+count]=str.value[i+str.offset];
104 newstr.value=charstr;
106 // LOC(newstr.value)=[O,V]
114 public boolean equals(@LOC("IN") Object o) {
115 if (o.getType()!=getType()) // values are coming from [IN] and [THISLOC]
117 @LOC("V") String s=(String)o;
121 for(@LOC("C") int i=0; i<count; i++) {
122 if (s.value[i+s.offset]!=value[i+offset])
128 public void getChars(char dst[], int dstBegin) {
129 getChars(0, count, dst, dstBegin);
132 public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
133 if((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) {
135 System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this);
138 int len = srcEnd - srcBegin;
140 for(int i=srcBegin; i<srcEnd; i++)
141 dst[j++]=value[i+offset];
145 public int indexOf(String str, int fromIndex) {
148 for(int i=fromIndex; i<=(count-str.count); i++)
149 if (regionMatches(i, str, 0, str.count))
154 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
155 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
157 for(int i=0; i<len; i++)
158 if (other.value[i+other.offset+ooffset]!=
159 this.value[i+this.offset+toffset])
165 public static String valueOf(@LOC("IN") Object o) {
172 public static String valueOf(boolean b) {
174 return new String("true");
176 return new String("false");
179 public static String valueOf(char c) {
180 char ar[]=new char[1];
182 return new String(ar);
185 public static String valueOf(int x) {
199 chararray=new char[length+1];
201 chararray=new char[length];
211 chararray[--length+voffset]=(char)(x%10+'0');
214 return new String(chararray);
217 public static String valueOf(double val) {
218 char[] chararray=new char[20];
219 String s=new String();
221 s.count=convertdoubletochar(val, chararray);
226 public static native int convertdoubletochar(double val, char [] chararray);
229 public static String valueOf(long x) {
243 chararray=new char[length+1];
245 chararray=new char[length];
255 chararray[--length+voffset]=(char)(x%10+'0');
258 return new String(chararray);
261 @LATTICE("O<V,V<C,C<IN,THISLOC=IN,C*")
263 public byte[] getBytes() {
264 @LOC("V") byte str[]=new byte[count];
265 for(@LOC("C") int i=0; i<count; i++)
266 str[i]=(byte)value[i+offset];
273 public int length() {
278 public char charAt(@LOC("IN") int index){
282 //public static native int convertdoubletochar(double val, char [] chararray);