classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Patch: FYI: StringBuilder updates


From: Tom Tromey
Subject: [cp-patches] Patch: FYI: StringBuilder updates
Date: 24 Oct 2005 17:47:59 -0600

I'm checking this in.

This adds a few methods to StringBuilder that were missing; I just
copied these from StringBuffer with the appropriate tweaks.  It also
fixes a small javadoc bug in StringBuffer.

Tom

2005-10-24  Tom Tromey  <address@hidden>

        * java/lang/StringBuffer.java (appendCodePoint): Added @since.
        * java/lang/StringBuilder.java (insert): New overloads.
        (appendCodePoint): New method.

Index: java/lang/StringBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/StringBuffer.java,v
retrieving revision 1.33
diff -u -r1.33 StringBuffer.java
--- java/lang/StringBuffer.java 16 Sep 2005 19:13:35 -0000      1.33
+++ java/lang/StringBuffer.java 24 Oct 2005 23:53:20 -0000
@@ -504,6 +504,7 @@
    * @param code the code point to append
    * @return this <code>StringBuffer</code>
    * @see Character#toChars(int, char[], int)
+   * @since 1.5
    */
   public synchronized StringBuffer appendCodePoint(int code)
   {
Index: java/lang/StringBuilder.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/StringBuilder.java,v
retrieving revision 1.5
diff -u -r1.5 StringBuilder.java
--- java/lang/StringBuilder.java        2 Jul 2005 20:32:39 -0000       1.5
+++ java/lang/StringBuilder.java        24 Oct 2005 23:53:20 -0000
@@ -464,6 +464,25 @@
   }
 
   /**
+   * Append the code point to this <code>StringBuilder</code>.
+   * This is like #append(char), but will append two characters
+   * if a supplementary code point is given.
+   *
+   * @param code the code point to append
+   * @return this <code>StringBuilder</code>
+   * @see Character#toChars(int, char[], int)
+   * @since 1.5
+   */
+  public synchronized StringBuilder appendCodePoint(int code)
+  {
+    int len = Character.charCount(code);
+    ensureCapacity(count + len);
+    Character.toChars(code, value, count);
+    count += len;
+    return this;
+  }
+
+  /**
    * Append the <code>String</code> value of the argument to this
    * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
    * to <code>String</code>.
@@ -700,6 +719,52 @@
     ensureCapacity(count + len);
     System.arraycopy(value, offset, value, offset + len, count - offset);
     str.getChars(0, len, value, offset);
+    count += len;
+    return this;
+  }
+
+  /**
+   * Insert the <code>CharSequence</code> argument into this
+   * <code>StringBuilder</code>.  If the sequence is null, the String
+   * "null" is used instead.
+   *
+   * @param offset the place to insert in this buffer
+   * @param sequence the <code>CharSequence</code> to insert
+   * @return this <code>StringBuilder</code>
+   * @throws IndexOutOfBoundsException if offset is out of bounds
+   */
+  public synchronized StringBuilder insert(int offset, CharSequence sequence)
+  {
+    if (sequence == null)
+      sequence = "null";
+    return insert(offset, sequence, 0, sequence.length());
+  }
+
+  /**
+   * Insert a subsequence of the <code>CharSequence</code> argument into this
+   * <code>StringBuilder</code>.  If the sequence is null, the String
+   * "null" is used instead.
+   *
+   * @param offset the place to insert in this buffer
+   * @param sequence the <code>CharSequence</code> to insert
+   * @param start the starting index of the subsequence
+   * @param end one past the ending index of the subsequence
+   * @return this <code>StringBuilder</code>
+   * @throws IndexOutOfBoundsException if offset, start,
+   * or end are out of bounds
+   */
+  public synchronized StringBuilder insert(int offset, CharSequence sequence,
+                      int start, int end)
+  {
+    if (sequence == null)
+      sequence = "null";
+    if (start < 0 || end < 0 || start > end || end > sequence.length())
+      throw new IndexOutOfBoundsException();
+    int len = end - start;
+    ensureCapacity(count + len);
+    VMSystem.arraycopy(value, offset, value, offset + len, count - offset);
+    for (int i = start; i < end; ++i)
+      value[offset++] = sequence.charAt(i);
     count += len;
     return this;
   }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]