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( @DELEGATE @LOC("IN") String str) {
55 this.offset=str.offset;
58 public String(StringBuffer strbuf) {
59 value=new char[strbuf.length()];
60 count=strbuf.length();
62 for(int i=0; i<count; i++)
63 value[i]=strbuf.value[i];
66 public String(@LOC("IN") char c) {
67 @LOC("V") char[] str = new char[1];
72 public String(@LOC("IN") char str[]) {
73 @LOC("V") char charstr[]=new char[str.length];
74 for(@LOC("C") int i=0; i<str.length; i++)
78 this.count=str.length;
82 @LATTICE("O<V,V<C,C<IN,THISLOC=IN,C*")
84 public String concat(@LOC("IN") String str) {
85 @LOC("O") String newstr=new String(); // create new one, it has OUT location
86 @LOC("C") int newCount=this.count+str.count;
88 @LOC("V") char charstr[]=new char[newCount];
90 // here, for loop introduces indirect flow from [C] to [V]
91 for(@LOC("C") int i=0; i<count; i++) {
92 // value flows from GLB(THISLOC,C,THISLOC.V)=(THISLOC,TOP) to [V]
93 charstr[i]=value[i+offset];
95 for(@LOC("C") int i=0; i<str.count; i++) {
96 charstr[i+count]=str.value[i+str.offset];
101 // LOC(newstr.value)=[O,V]
109 public boolean equals(@LOC("IN") Object o) {
110 if (o.getType()!=getType()) // values are coming from [IN] and [THISLOC]
112 @LOC("V") String s=(String)o;
116 for(@LOC("C") int i=0; i<count; i++) {
117 if (s.value[i+s.offset]!=value[i+offset])
123 public void getChars(char dst[], int dstBegin) {
124 getChars(0, count, dst, dstBegin);
127 public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
128 if((srcBegin < 0) || (srcEnd > count) || (srcBegin > srcEnd)) {
130 System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this);
133 int len = srcEnd - srcBegin;
135 for(int i=srcBegin; i<srcEnd; i++)
136 dst[j++]=value[i+offset];
140 public int indexOf(String str, int fromIndex) {
143 for(int i=fromIndex; i<=(count-str.count); i++)
144 if (regionMatches(i, str, 0, str.count))
149 public boolean regionMatches(int toffset, String other, int ooffset, int len) {
150 if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count)
152 for(int i=0; i<len; i++)
153 if (other.value[i+other.offset+ooffset]!=
154 this.value[i+this.offset+toffset])
160 public static String valueOf(@LOC("IN") Object o) {
167 public static String valueOf(boolean b) {
169 return new String("true");
171 return new String("false");
174 public static String valueOf(char c) {
175 char ar[]=new char[1];
177 return new String(ar);
180 public static String valueOf(int x) {
194 chararray=new char[length+1];
196 chararray=new char[length];
206 chararray[--length+voffset]=(char)(x%10+'0');
209 return new String(chararray);
212 public static String valueOf(double val) {
213 char[] chararray=new char[20];
214 String s=new String();
216 s.count=convertdoubletochar(val, chararray);
221 public static native int convertdoubletochar(double val, char [] chararray);
224 public static String valueOf(long x) {
238 chararray=new char[length+1];
240 chararray=new char[length];
250 chararray[--length+voffset]=(char)(x%10+'0');
253 return new String(chararray);
256 @LATTICE("O<V,V<C,C<IN,THISLOC=IN,C*")
258 public byte[] getBytes() {
259 @LOC("V") byte str[]=new byte[count];
260 for(@LOC("C") int i=0; i<count; i++)
261 str[i]=(byte)value[i+offset];
268 public int length() {
273 public char charAt(@LOC("IN") int index){
277 //public static native int convertdoubletochar(double val, char [] chararray);