Index: /luni/src/main/java/java/lang/String.java =================================================================== --- /luni/src/main/java/java/lang/String.java (revision 392827) +++ /luni/src/main/java/java/lang/String.java (working copy) @@ -33,12 +33,12 @@ import org.apache.harmony.luni.util.PriviAction; /** - * The implementation of this class is provided, but the documented native must - * be provided by the vm vendor. - * - * Strings are objects which represent immutable arrays of characters. + *
An immutable sequence of characters (chars).
+ * Constructs a String from the sub-array of Unicode code
+ * points.
+ *
codePoints to begin
+ * converting from.
+ * @param count The number of element in codePoints to copy.
+ * @throws NullPointerException if codePoints is null.
+ * @throws IllegalArgumentException if any of the elements of
+ * codePoints are not valid Unicode code points.
+ * @throws IndexOutOfBoundsException if offset or
+ * count are not within the bounds of
+ * codePoints.
+ * @since 1.5
+ */
+ public String(int[] codePoints, int offset, int count) {
+ super();
+ if (codePoints == null)
+ throw new NullPointerException();
+ if (offset < 0 || count < 0 || (offset + count) > codePoints.length)
+ throw new IndexOutOfBoundsException();
+ this.offset = 0;
+ this.value = new char[count * 2];
+ int end = offset + count;
+ int c = 0;
+ for (int i = offset; i < end; i++) {
+ c += Character.toChars(codePoints[i], this.value, c);
+ }
+ this.count = c;
+ }
+
+ /**
+ *
+ * Constructs a String from a StringBuilder.
+ *
sb is null.
+ * @since 1.5
+ */
+ public String(StringBuilder sb) {
+ if (sb == null)
+ throw new NullPointerException();
+ this.offset = 0;
+ this.count = sb.length();
+ this.value = new char[this.count];
+ sb.getChars(0, this.count, this.value, 0);
+ }
/*
- * Creates a string that is s1 + v1.
- */
+ * Creates a string that is s1 + v1.
+ */
private String(String s1, int v1) {
if (s1 == null)
s1 = "null";
@@ -732,7 +784,7 @@
/**
* Converts this String to a byte encoding using the default encoding as
- * specified by the file.encoding sytem property. If the system property is
+ * specified by the file.encoding system property. If the system property is
* not defined, the default encoding is ISO8859_1 (ISO-Latin-1). If 8859-1
* is not available, an ASCII encoding is used.
*
@@ -1673,6 +1725,26 @@
size);
}
}
+
+ /**
+ *
+ * Compares a CharSequence to this String to
+ * determine if their contents are equal.
+ *
true if equal, otherwise false
+ * @since 1.5
+ */
+ public boolean contentEquals(CharSequence cs) {
+ if (cs == null)
+ throw new NullPointerException();
+ if (cs instanceof StringBuffer)
+ return contentEquals((StringBuffer)cs);
+ else {
+ return regionMatches(0, cs.toString(), 0, cs.length());
+ }
+ }
/**
* Determines whether a this String matches a given regular expression.
@@ -1789,6 +1861,105 @@
public CharSequence subSequence(int start, int end) {
return substring(start, end);
}
+
+ /**
+ *
+ * Retrieves the Unicode code point value at the index.
+ *
char code unit within this
+ * object.
+ * @return The Unicode code point value.
+ * @throws IndexOutOfBoundsException if index is negative or
+ * greater than or equal to {@link #length()}.
+ * @see Character
+ * @see Character#codePointAt(char[], int, int)
+ * @since 1.5
+ */
+ public int codePointAt(int index) {
+ if (index < 0 || index >= (offset + count))
+ throw new IndexOutOfBoundsException();
+ return Character.codePointAt(value, index + offset, count);
+ }
+
+ /**
+ *
+ * Retrieves the Unicode code point value that precedes the
+ * index.
+ *
char code unit within this
+ * object.
+ * @return The Unicode code point value.
+ * @throws IndexOutOfBoundsException if index is less than 1
+ * or greater than {@link #length()}.
+ * @see Character
+ * @see Character#codePointBefore(char[], int, int)
+ * @since 1.5
+ */
+ public int codePointBefore(int index) {
+ if (index < 1 || index > (offset + count))
+ throw new IndexOutOfBoundsException();
+ return Character.codePointBefore(value, index + offset);
+ }
+
+ /**
+ *
+ * Calculates the number of Unicode code points between
+ * beginIndex and endIndex.
+ *
beginIndex is
+ * negative or greater than endIndex or
+ * endIndex is greater than {@link #length()}.
+ * @since 1.5
+ */
+ public int codePointCount(int beginIndex, int endIndex) {
+ if (beginIndex < offset || endIndex > (offset + count) || beginIndex > endIndex)
+ throw new IndexOutOfBoundsException();
+ return Character.codePointCount(value, beginIndex, endIndex
+ - beginIndex);
+ }
+
+ /**
+ *
+ * Determines if this String contains the sequence of
+ * characters in the CharSequence passed.
+ *
true if the sequence of characters are contained
+ * in this object; otherwise false
+ * @since 1.5
+ */
+ public boolean contains(CharSequence cs) {
+ if (cs == null)
+ throw new NullPointerException();
+ return indexOf(cs.toString()) >= 0;
+ }
+
+ /**
+ *
+ * Returns the index within this object that is offset from
+ * index by codePointOffset code points.
+ *
index is negative or
+ * greater than {@link #length()} or if there aren't enough code
+ * points before or after index to match
+ * codePointOffset.
+ * @since 1.5
+ */
+ public int offsetByCodePoints(int index, int codePointOffset) {
+ return Character.offsetByCodePoints(value, offset, count, index,
+ codePointOffset);
+ }
/*
* An implementation of a String.indexOf that is supposed to perform