Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4120694

StringBuffer should have more functionality

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.0
    • 1.1.2, 1.1.3, 1.1.4, 1.2.0
    • core-libs
    • 1.2beta4
    • generic, x86, sparc
    • generic, solaris_2.5.1, solaris_2.6, windows_95, windows_nt
    • Not verified

      Problem:
        StringBuffer has methods for inserting and appending contents, but there
        is no direct and efficient way to delete, modify, or extract the contents
        of a StringBuffer. StringBuffer currently has a parallel structure between
        its existing appends and inserts except that there is no existing
        insert(int, char[], int, int); The lack of this insert operation may force
        a programmer to convert the StringBuffer to a String before the mutational
        operations are complete, hurting their performance.
       
      Requestors:
        Tim Budd
        Chris Tomkins, IBM
        Anthony Sabatini, Cash Markets Group
        Charles Kerr, OAO Corp.
        Steve Olechowski, Digital Knowledge Assets
        Kevin McIsaac, South Branch Software
        Vartan Piroumian, vartan.com

      Proposed API change:
          Add to class StringBuffer the following six operations to support
          minimal-but-useful, reasonably fast string processing:

        1. public StringBuffer delete(int start, int end)
        2. public StringBuffer deleteCharAt(int pos)
        3. public StringBuffer replace(int start, int end, String str)
        4a. public String substring(int start, int end)
        4b. public String substring(int start)
        5. public StringBuffer insert(int pos, char chars[], int offset, int len)

            This will fill out the following functionality matrix:

      MODE: character-wise range-wise
            OP -------------- ----------
          append | append(ch) append(str)
          insert | insert(pos, ch) insert(pos, str)
          delete | deleteCharAt(pos)[NEW] delete(start, end)[NEW]
          replace | setCharAt(pos, ch) replace(start, end, str)[NEW]
          extract | charAt(pos) substring(start, end)[NEW]


        Notes:
         - The range-wise operations provide full-speed access to S.B. internals.
         - Substring is necessary to avoid recopying the entire buffer.
         - Deletion is totally absent in the 1.1 StringBuffer class!
         - Rangewise delete and replace operations allow end > length (cf. indexOf).
         - 4a/4b match the pre-existing design of String.substring.
         - 5 matches pre-existing StringBuffer.append design (see below).
         - Insert/append of char arrays integrates with JDK 1.1 character I/O.
         - Considered & rejected: searching, matching, case-folding, byte-conversion.

      OP: append insert
           INPUT ------ ------
          String append(str) insert(pos, str)
          char[] append(chars) insert(pos, chars)
          char[]part append(chars,off,len) insert(pos, chars,off,len)[NEW]
          Object append(obj) insert(pos, obj)
          (any prim) append(primval) insert(pos, primval)

            mmcclosksunw Michael Mccloskey (Inactive)
            mmcclosksunw Michael Mccloskey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: