From 9cfdff2e7d7b6e7a7b31992e1d2cc405783d468c Mon Sep 17 00:00:00 2001 From: jjenista Date: Thu, 13 Oct 2011 15:28:12 +0000 Subject: [PATCH] Forgot to add the OoOJava-specific class directory --- Robust/src/ClassLibrary/OoOJava/String.java | 513 ++++++++++++++++++++ 1 file changed, 513 insertions(+) create mode 100644 Robust/src/ClassLibrary/OoOJava/String.java diff --git a/Robust/src/ClassLibrary/OoOJava/String.java b/Robust/src/ClassLibrary/OoOJava/String.java new file mode 100644 index 00000000..e082aaa3 --- /dev/null +++ b/Robust/src/ClassLibrary/OoOJava/String.java @@ -0,0 +1,513 @@ +public class String { + char value[]; + int count; + int offset; + private int cachedHashcode; + + private String() { + } + + public String(char c) { + char[] str = new char[1]; + str[0] = c; + String(str); + } + + public String(char str[]) { + char charstr[]=new char[str.length]; + for(int i=0; i(str.length-offset)) + length=str.length-offset; + char charstr[]=new char[length]; + for(int i=0; i(str.length)) + length=str.length; + char charstr[]=new char[length]; + for(int i=0; i(str.length-offset)) + length=str.length-offset; + char charstr[]=new char[length]; + for(int i=0; ithis.count||endIndex>this.count||beginIndex>endIndex) { + // FIXME + System.printString("Index error: "+beginIndex+" "+endIndex+" "+count+"\n"+this); + } + str.value=this.value; + str.count=endIndex-beginIndex; + str.offset=this.offset+beginIndex; + return str; + } + + public String subString(int beginIndex) { + return this.subString(beginIndex, this.count); + } + + public int lastindexOf(int ch) { + return this.lastindexOf(ch, count - 1); + } + + public int lastIndexOf(char ch) { + return this.lastindexOf((int)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; + char charstr[]=new char[newstr.count]; + newstr.value=charstr; + newstr.offset=0; + for(int i=0; i0; i--) + if (this.charAt(i)==ch) + return i; + return -1; + } + + public String replace(char oldch, char newch) { + char[] buffer=new char[count]; + for(int i=0; i='a'&&x<='z') { + x=(char) ((x-'a')+'A'); + } + buffer[i]=x; + } + return new String(buffer); + } + + public String toLowerCase() { + char[] buffer=new char[count]; + for(int i=0; i='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); + } + + public int indexOf(int ch, int fromIndex) { + for(int i=fromIndex; ifromIndex) + k=fromIndex; + for(; k>=0; k--) { + if (regionMatches(k, str, 0, str.count)) + return k; + } + return -1; + } + + public int lastIndexOf(String str) { + return lastIndexOf(str, count-str.count); + } + + public boolean startsWith(String str) { + return regionMatches(0, str, 0, str.count); + } + + public boolean startsWith(String str, int toffset) { + return regionMatches(toffset, str, 0, str.count); + } + + public boolean regionMatches(int toffset, String other, int ooffset, int len) { + if (toffset<0 || ooffset <0 || (toffset+len)>count || (ooffset+len)>other.count) + return false; + for(int i=0; i count) || (srcBegin > srcEnd)) { + // FIXME + System.printString("Index error: "+srcBegin+" "+srcEnd+" "+count+"\n"+this); + System.exit(-1); + } + int len = srcEnd - srcBegin; + int j = dstBegin; + for(int i=srcBegin; i='a'&&l<='z') + l=(char)((l-'a')+'A'); + if (r>='a'&&r<='z') + r=(char)((r-'a')+'A'); + if (l!=r) + return false; + } + return true; + } + + public Vector split() { + Vector splitted = new Vector(); + int i; + int cnt =0; + + // skip first spaces + for(i = 0; i< count; i++) { + if(value[i+offset] != '\n' && value[i+offset] != '\t' && value[i+offset] != ' ') + break; + } + + int oldi=i; + + while(i 0) || (len < count))?substring(st, len):this; + } + + public boolean matches(String regex) { + System.println("String.matches() is not fully supported"); + return this.equals(regex); + } +} -- 2.34.1