start of new file
[IRC.git] / Robust / src / ClassLibrary / String.java
index d6f23e5fb21d829bf20f581a8b7ab7b146a3d073..f1ec9d53c2cc76fd5f17c3cab0a3ae6b8fcc0c30 100644 (file)
@@ -25,6 +25,17 @@ public class String {
        this.offset=0;
     }
 
+    public String(byte str[], int offset, int length) {
+       if (length>(str.length-offset))
+           length=str.length-offset;
+       char charstr[]=new char[length];
+       for(int i=0;i<length;i++)
+           charstr[i]=(char)str[i+offset];
+       this.value=charstr;
+       this.count=length;
+       this.offset=0;
+    }
+
     public String(String str) {
        this.value=str.value;
        this.count=str.count;
@@ -56,6 +67,7 @@ public class String {
        String str=new String();
        if (beginIndex>this.count||endIndex>this.count||beginIndex>endIndex) {
            // FIXME
+           System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this);
        }
        str.value=this.value;
        str.count=endIndex-beginIndex;
@@ -71,6 +83,13 @@ public class String {
        return this.lastindexOf(ch, count - 1);
     }
 
+    public static String concat2(String s1, String s2) {
+       if (s1==null)
+           return "null".concat(s2);
+       else
+           return s1.concat(s2);
+    }
+
     public String concat(String str) {
        String newstr=new String();
        newstr.count=this.count+str.count;
@@ -104,6 +123,18 @@ public class String {
        return new String(buffer);
     }
 
+    public String toUpperCase() {
+       char[] buffer=new char[count];
+       for(int i=0;i<count;i++) {
+           char x=charAt(i);
+           if (x>='a'&&x<='z') {
+               x=(char) ((x-'a')+'A');
+           }
+           buffer[i]=x;
+       }
+       return new String(buffer);
+    }
+
     public int indexOf(int ch) {
        return this.indexOf(ch, 0);
     }
@@ -133,7 +164,7 @@ public class String {
        if (k>fromIndex)
            k=fromIndex;
        for(;k>=0;k--) {
-           if (regionMatches(fromIndex, str, 0, str.count))
+           if (regionMatches(k, str, 0, str.count))
                return k;
        }
        return -1;
@@ -194,6 +225,13 @@ public class String {
            return o.toString();
     }
 
+    public static String valueOf(boolean b) {
+       if (b)
+           return new String("true");
+       else
+           return new String("false");
+    }
+
     public static String valueOf(char c) {
        char ar[]=new char[1];
        ar[0]=c;
@@ -232,6 +270,38 @@ public class String {
        return new String(chararray);
     }
 
+    public static String valueOf(long x) {
+       int length=0;
+       long tmp;
+       if (x<0)
+           tmp=-x;
+       else
+           tmp=x;
+       do {
+           tmp=tmp/10;
+           length=length+1;
+       } while(tmp!=0);
+       
+       char chararray[];
+       if (x<0)
+           chararray=new char[length+1];
+       else
+           chararray=new char[length];
+       int voffset;
+       if (x<0) {
+           chararray[0]='-';
+           voffset=1;
+           x=-x;
+       } else
+           voffset=0;
+               
+       do {
+           chararray[--length+voffset]=(char)(x%10+'0');
+           x=x/10;
+       } while (length!=0);
+       return new String(chararray);
+    }
+
     public int hashCode() {
        if (cachedHashcode!=0)
            return cachedHashcode;
@@ -262,9 +332,9 @@ public class String {
            char l=s.value[i+s.offset];
            char r=value[i+offset];
            if (l>='a'&&l<='z')
-               l+='A'-'a';
+               l=(char)((l-'a')+'A');
            if (r>='a'&&r<='z')
-               r+='A'-'a';
+               r=(char)((r-'a')+'A');
            if (l!=r)
                return false;
        }