logo

final class

sys::StrBuf

sys::Obj
  sys::StrBuf
//
// Copyright (c) 2006, Brian Frank and Andy Frank
// Licensed under the Academic Free License version 3.0
//
// History:
//   4 Jan 06  Brian Frank  Creation
//

**
** StrBuf is a mutable sequence of Int characters.
**
final class StrBuf
{

//////////////////////////////////////////////////////////////////////////
// Construction
//////////////////////////////////////////////////////////////////////////

  **
  ** Create with initial capacity (defaults to 16).
  **
  new make(Int capacity := 16)

//////////////////////////////////////////////////////////////////////////
// Methods
//////////////////////////////////////////////////////////////////////////

  **
  ** Return if size() == 0.
  **
  Bool isEmpty()

  **
  ** Return the number of characters in the buffer.
  **
  Int size()

  **
  ** Get the character at the zero based index as a Unicode code point.
  ** Negative indexes may be used to access from the end of the string buffer.
  ** This method is accessed via the [] operator.
  **
  Int get(Int index)

  **
  ** Replace the existing character at index in this buffer.
  ** Negative indexes may be used to access from the end of
  ** the string buffer.  This method is accessed via the []
  ** operator.  Return this.
  **
  StrBuf set(Int index, Int ch)

  **
  ** Add x.toStr to the end of this buffer.  If x is null then
  ** the string "null" is inserted.  Return this.
  **
  StrBuf add(Obj x)

  **
  ** Optimized implementation for add(ch.toChar).  Return this.
  **
  StrBuf addChar(Int ch)

  **
  ** Insert x.toStr into this buffer at the specified index.
  ** If x is null then the string "null" is inserted.  Negative
  ** indexes may be used to access from the end of the string
  ** buffer.  Throw IndexErr if index is out of range.  Return
  ** this.
  **
  StrBuf insert(Int index, Obj x)

  **
  ** Remove the char at the specified index.  A negative index may be
  ** used to access an index from the end of the list.  Size is decremented
  ** by 1.  Return the this.  Throw IndexErr if index is out of range.
  **
  StrBuf remove(Int index)

  **
  ** Ensure that this buffer has the specified capactity.  If
  ** this buffer is already beyond the given capacity, then
  ** do nothing.  Return this.
  **
  StrBuf grow(Int size)

  **
  ** Clear the contents of the string buffer so that is
  ** has a size of zero.  Return this.
  **
  StrBuf clear()

// TODO: capacity, get, slice, etc

//////////////////////////////////////////////////////////////////////////
// Conversion
//////////////////////////////////////////////////////////////////////////

  **
  ** Return the current buffer contents as a Str.
  **
  override Str toStr()

}