home *** CD-ROM | disk | FTP | other *** search
- package java.lang;
-
- import java.util.Hashtable;
-
- public final class String {
- private char[] value;
- private int offset;
- private int count;
- private static Hashtable InternSet;
-
- public String() {
- this.value = new char[0];
- }
-
- public String(String value) {
- this.count = value.length();
- this.value = new char[this.count];
- value.getChars(0, this.count, this.value, 0);
- }
-
- public String(char[] value) {
- this.count = value.length;
- this.value = new char[this.count];
- System.arraycopy(value, 0, this.value, 0, this.count);
- }
-
- public String(char[] value, int offset, int count) {
- if (offset < 0) {
- throw new StringIndexOutOfBoundsException(offset);
- } else if (count < 0) {
- throw new StringIndexOutOfBoundsException(count);
- } else if (offset + count > value.length) {
- throw new StringIndexOutOfBoundsException(offset + count);
- } else {
- this.value = new char[count];
- this.count = count;
- System.arraycopy(value, offset, this.value, 0, count);
- }
- }
-
- public String(byte[] ascii, int hibyte, int offset, int count) {
- if (offset < 0) {
- throw new StringIndexOutOfBoundsException(offset);
- } else if (count < 0) {
- throw new StringIndexOutOfBoundsException(count);
- } else if (offset + count > ascii.length) {
- throw new StringIndexOutOfBoundsException(offset + count);
- } else {
- char[] value = new char[count];
- this.count = count;
- this.value = value;
- if (hibyte == 0) {
- for(int i = count; i-- > 0; value[i] = (char)(ascii[i + offset] & 255)) {
- }
-
- } else {
- hibyte <<= 8;
-
- for(int i = count; i-- > 0; value[i] = (char)(hibyte | ascii[i + offset] & 255)) {
- }
-
- }
- }
- }
-
- public String(byte[] ascii, int hibyte) {
- this(ascii, hibyte, 0, ascii.length);
- }
-
- public String(StringBuffer buffer) {
- synchronized(buffer){}
-
- try {
- buffer.setShared();
- this.value = buffer.getValue();
- this.offset = 0;
- this.count = buffer.length();
- } catch (Throwable var4) {
- throw var4;
- }
-
- }
-
- private String(int offset, int count, char[] value) {
- this.value = value;
- this.offset = offset;
- this.count = count;
- }
-
- public int length() {
- return this.count;
- }
-
- public char charAt(int index) {
- if (index >= 0 && index < this.count) {
- return this.value[index + this.offset];
- } else {
- throw new StringIndexOutOfBoundsException(index);
- }
- }
-
- public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
- System.arraycopy(this.value, this.offset + srcBegin, dst, dstBegin, srcEnd - srcBegin);
- }
-
- public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) {
- int j = dstBegin;
- int n = this.offset + srcEnd;
-
- for(int i = this.offset + srcBegin; i < n; dst[j++] = (byte)this.value[i++]) {
- }
-
- }
-
- public boolean equals(Object anObject) {
- if (anObject != null && anObject instanceof String) {
- String anotherString = (String)anObject;
- int n = this.count;
- if (n == anotherString.count) {
- char[] v1 = this.value;
- char[] v2 = anotherString.value;
- int i = this.offset;
- int j = anotherString.offset;
-
- while(n-- != 0) {
- if (v1[i++] != v2[j++]) {
- return false;
- }
- }
-
- return true;
- }
- }
-
- return false;
- }
-
- public boolean equalsIgnoreCase(String anotherString) {
- return anotherString != null && anotherString.count == this.count && this.regionMatches(true, 0, anotherString, 0, this.count);
- }
-
- public int compareTo(String anotherString) {
- int len1 = this.count;
- int len2 = anotherString.count;
- int n = Math.min(len1, len2);
- char[] v1 = this.value;
- char[] v2 = anotherString.value;
- int i = this.offset;
- int j = anotherString.offset;
-
- while(n-- != 0) {
- char c1 = v1[i++];
- char c2 = v2[j++];
- if (c1 != c2) {
- return c1 - c2;
- }
- }
-
- return len1 - len2;
- }
-
- public boolean regionMatches(int toffset, String other, int ooffset, int len) {
- char[] ta = this.value;
- int to = this.offset + toffset;
- int tlim = this.offset + this.count;
- char[] pa = other.value;
- int po = other.offset + ooffset;
- int plim = po + other.count;
- if (ooffset >= 0 && toffset >= 0 && to + len <= tlim && po + len <= plim) {
- while(len-- > 0) {
- if (ta[to++] != pa[po++]) {
- return false;
- }
- }
-
- return true;
- } else {
- return false;
- }
- }
-
- public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) {
- char[] ta = this.value;
- int to = this.offset + toffset;
- int tlim = this.offset + this.count;
- char[] pa = other.value;
- int po = other.offset + ooffset;
- int plim = po + other.count;
- if (ooffset >= 0 && toffset >= 0 && to + len <= tlim && po + len <= plim) {
- while(true) {
- if (len-- <= 0) {
- return true;
- }
-
- char c1 = ta[to++];
- char c2 = pa[po++];
- if (c1 != c2) {
- if (!ignoreCase) {
- break;
- }
-
- char u1 = Character.toUpperCase(c1);
- char u2 = Character.toUpperCase(c2);
- if (u1 != u2 && Character.toLowerCase(u1) != Character.toLowerCase(u2)) {
- break;
- }
- }
- }
-
- return false;
- } else {
- return false;
- }
- }
-
- public boolean startsWith(String prefix, int toffset) {
- char[] ta = this.value;
- int to = this.offset + toffset;
- int tlim = this.offset + this.count;
- char[] pa = prefix.value;
- int po = prefix.offset;
- int pc = prefix.count;
- if (toffset >= 0 && to + pc <= tlim) {
- do {
- --pc;
- if (pc < 0) {
- return true;
- }
- } while(ta[to++] == pa[po++]);
-
- return false;
- } else {
- return false;
- }
- }
-
- public boolean startsWith(String prefix) {
- return this.startsWith(prefix, 0);
- }
-
- public boolean endsWith(String suffix) {
- return this.startsWith(suffix, this.count - suffix.count);
- }
-
- public int hashCode() {
- int h = 0;
- int off = this.offset;
- char[] val = this.value;
- int len = this.count;
- if (len < 16) {
- for(int i = len; i > 0; --i) {
- h = h * 37 + val[off++];
- }
- } else {
- int skip = len / 8;
-
- for(int i = len; i > 0; off += skip) {
- h = h * 39 + val[off];
- i -= skip;
- }
- }
-
- return h;
- }
-
- public int indexOf(int ch) {
- return this.indexOf(ch, 0);
- }
-
- public int indexOf(int ch, int fromIndex) {
- int max = this.offset + this.count;
- char[] v = this.value;
-
- for(int i = this.offset + fromIndex; i < max; ++i) {
- if (v[i] == ch) {
- return i - this.offset;
- }
- }
-
- return -1;
- }
-
- public int lastIndexOf(int ch) {
- return this.lastIndexOf(ch, this.count - 1);
- }
-
- public int lastIndexOf(int ch, int fromIndex) {
- int min = this.offset;
- char[] v = this.value;
-
- for(int i = this.offset + (fromIndex >= this.count ? this.count - 1 : fromIndex); i >= min; --i) {
- if (v[i] == ch) {
- return i - this.offset;
- }
- }
-
- return -1;
- }
-
- public int indexOf(String str) {
- return this.indexOf(str, 0);
- }
-
- public int indexOf(String str, int fromIndex) {
- char[] v1 = this.value;
- char[] v2 = str.value;
- int max = this.offset + (this.count - str.count);
- int i = this.offset + (fromIndex < 0 ? 0 : fromIndex);
-
- label27:
- while(i <= max) {
- int n = str.count;
- int j = i;
- int k = str.offset;
-
- while(n-- != 0) {
- if (v1[j++] != v2[k++]) {
- ++i;
- continue label27;
- }
- }
-
- return i - this.offset;
- }
-
- return -1;
- }
-
- public int lastIndexOf(String str) {
- return this.lastIndexOf(str, this.count);
- }
-
- public int lastIndexOf(String str, int fromIndex) {
- if (fromIndex < 0) {
- return -1;
- } else {
- if (fromIndex > this.count - str.count) {
- fromIndex = this.count - str.count;
- }
-
- if (str.count == 0) {
- return fromIndex;
- } else {
- char[] v1 = this.value;
- char[] v2 = str.value;
-
- for(int i = this.offset + fromIndex; i >= this.offset; --i) {
- int n = str.count;
- int thisIndex = i;
- int strIndex = str.offset;
-
- while(v1[thisIndex++] == v2[strIndex++]) {
- --n;
- if (n <= 0) {
- return i - this.offset;
- }
- }
- }
-
- return -1;
- }
- }
- }
-
- public String substring(int beginIndex) {
- return this.substring(beginIndex, this.length());
- }
-
- public String substring(int beginIndex, int endIndex) {
- if (beginIndex > endIndex) {
- int tmp = beginIndex;
- beginIndex = endIndex;
- endIndex = tmp;
- }
-
- if (beginIndex < 0) {
- throw new StringIndexOutOfBoundsException(beginIndex);
- } else if (endIndex > this.count) {
- throw new StringIndexOutOfBoundsException(endIndex);
- } else {
- return beginIndex == 0 && endIndex == this.count ? this : new String(this.offset + beginIndex, endIndex - beginIndex, this.value);
- }
- }
-
- public String concat(String str) {
- int otherLen = str.length();
- if (otherLen == 0) {
- return this;
- } else {
- char[] buf = new char[this.count + otherLen];
- this.getChars(0, this.count, buf, 0);
- str.getChars(0, otherLen, buf, this.count);
- return new String(0, this.count + otherLen, buf);
- }
- }
-
- public String replace(char oldChar, char newChar) {
- if (oldChar != newChar) {
- int len = this.count;
- int i = -1;
-
- do {
- ++i;
- } while(i < len && this.value[this.offset + i] != oldChar);
-
- if (i < len) {
- char[] buf = new char[len];
-
- for(int j = 0; j < i; ++j) {
- buf[j] = this.value[this.offset + j];
- }
-
- while(i < len) {
- char c = this.value[this.offset + i];
- buf[i] = c == oldChar ? newChar : c;
- ++i;
- }
-
- return new String(0, len, buf);
- }
- }
-
- return this;
- }
-
- public String toLowerCase() {
- int len = this.count;
-
- for(int i = 0; i < len; ++i) {
- char c = this.value[this.offset + i];
- char z = Character.toLowerCase(c);
- if (c != z) {
- char[] buf = new char[len];
-
- int j;
- for(j = 0; j < i; ++j) {
- buf[j] = this.value[this.offset + j];
- }
-
- for(buf[j++] = z; j < len; ++j) {
- buf[j] = Character.toLowerCase(this.value[this.offset + j]);
- }
-
- return new String(0, len, buf);
- }
- }
-
- return this;
- }
-
- public String toUpperCase() {
- int len = this.count;
-
- for(int i = 0; i < len; ++i) {
- char c = this.value[this.offset + i];
- char z = Character.toUpperCase(c);
- if (c != z) {
- char[] buf = new char[len];
-
- int j;
- for(j = 0; j < i; ++j) {
- buf[j] = this.value[this.offset + j];
- }
-
- for(buf[j++] = z; j < len; ++j) {
- buf[j] = Character.toUpperCase(this.value[this.offset + j]);
- }
-
- return new String(0, len, buf);
- }
- }
-
- return this;
- }
-
- public String trim() {
- int len = this.count;
-
- int st;
- for(st = 0; st < len && this.value[this.offset + st] <= ' '; ++st) {
- }
-
- while(st < len && this.value[this.offset + len - 1] <= ' ') {
- --len;
- }
-
- return st <= 0 && len >= this.count ? this : this.substring(st, len);
- }
-
- public String toString() {
- return this;
- }
-
- public char[] toCharArray() {
- int max = this.length();
- char[] result = new char[max];
- this.getChars(0, max, result, 0);
- return result;
- }
-
- public static String valueOf(Object obj) {
- return obj == null ? "null" : obj.toString();
- }
-
- public static String valueOf(char[] data) {
- return new String(data);
- }
-
- public static String valueOf(char[] data, int offset, int count) {
- return new String(data, offset, count);
- }
-
- public static String copyValueOf(char[] data, int offset, int count) {
- return new String(data, offset, count);
- }
-
- public static String copyValueOf(char[] data) {
- return copyValueOf(data, 0, data.length);
- }
-
- public static String valueOf(boolean b) {
- return b ? "true" : "false";
- }
-
- public static String valueOf(char c) {
- char[] data = new char[]{c};
- return new String(0, 1, data);
- }
-
- public static String valueOf(int i) {
- return Integer.toString(i, 10);
- }
-
- public static String valueOf(long l) {
- return Long.toString(l, 10);
- }
-
- public static String valueOf(float f) {
- return Float.toString(f);
- }
-
- public static String valueOf(double d) {
- return Double.toString(d);
- }
-
- public String intern() {
- if (InternSet == null) {
- InternSet = new Hashtable();
- }
-
- String s = (String)InternSet.get(this);
- if (s != null) {
- return s;
- } else {
- InternSet.put(this, this);
- return this;
- }
- }
-
- int utfLength() {
- int limit = this.offset + this.count;
- int utflen = 0;
-
- for(int i = this.offset; i < limit; ++i) {
- int c = this.value[i];
- if (c >= 1 && c <= 127) {
- ++utflen;
- } else if (c > 2047) {
- utflen += 3;
- } else {
- utflen += 2;
- }
- }
-
- return utflen;
- }
- }
-