
1 // 2 // Copyright (c) 2006, Brian Frank and Andy Frank 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 4 Jan 06 Brian Frank Creation 7 // 8 9 ** 10 ** StrBuf is a mutable sequence of Int characters. 11 ** 12 final class StrBuf 13 { 14 15 ////////////////////////////////////////////////////////////////////////// 16 // Construction 17 ////////////////////////////////////////////////////////////////////////// 18 19 ** 20 ** Create with initial capacity (defaults to 16). 21 ** 22 new make(Int capacity := 16) 23 24 ////////////////////////////////////////////////////////////////////////// 25 // Methods 26 ////////////////////////////////////////////////////////////////////////// 27 28 ** 29 ** Return if size() == 0. 30 ** 31 Bool isEmpty() 32 33 ** 34 ** Return the number of characters in the buffer. 35 ** 36 Int size() 37 38 ** 39 ** Get the character at the zero based index as a Unicode code point. 40 ** Negative indexes may be used to access from the end of the string buffer. 41 ** This method is accessed via the [] operator. 42 ** 43 Int get(Int index) 44 45 ** 46 ** Replace the existing character at index in this buffer. 47 ** Negative indexes may be used to access from the end of 48 ** the string buffer. This method is accessed via the [] 49 ** operator. Return this. 50 ** 51 StrBuf set(Int index, Int ch) 52 53 ** 54 ** Add x.toStr to the end of this buffer. If x is null then 55 ** the string "null" is inserted. Return this. 56 ** 57 StrBuf add(Obj x) 58 59 ** 60 ** Optimized implementation for add(ch.toChar). Return this. 61 ** 62 StrBuf addChar(Int ch) 63 64 ** 65 ** Insert x.toStr into this buffer at the specified index. 66 ** If x is null then the string "null" is inserted. Negative 67 ** indexes may be used to access from the end of the string 68 ** buffer. Throw IndexErr if index is out of range. Return 69 ** this. 70 ** 71 StrBuf insert(Int index, Obj x) 72 73 ** 74 ** Remove the char at the specified index. A negative index may be 75 ** used to access an index from the end of the list. Size is decremented 76 ** by 1. Return the this. Throw IndexErr if index is out of range. 77 ** 78 StrBuf remove(Int index) 79 80 ** 81 ** Ensure that this buffer has the specified capactity. If 82 ** this buffer is already beyond the given capacity, then 83 ** do nothing. Return this. 84 ** 85 StrBuf grow(Int size) 86 87 ** 88 ** Clear the contents of the string buffer so that is 89 ** has a size of zero. Return this. 90 ** 91 StrBuf clear() 92 93 // TODO: capacity, get, slice, etc 94 95 ////////////////////////////////////////////////////////////////////////// 96 // Conversion 97 ////////////////////////////////////////////////////////////////////////// 98 99 ** 100 ** Return the current buffer contents as a Str. 101 ** 102 override Str toStr() 103 104 }