StrBuf
class StrBuf : Obj
StrBuf is a mutable sequence of Int characters.
Create with initial capacity (defaults to 16)
The number of characters this buffer can hold without allocating more memory
Add x.toStr to the end of this buffer
Optimized implementation for add(ch.toChar)
Add a substring of the given string to the buffer
Add string with its leading and trailing whitespace trimmed
Clear the contents of the string buffer so that it has a size of zero
Get the character at the zero based index as a Unicode code point
Return a substring based on the specified range
Insert x.toStr into this buffer at the specified index
Return if size() == 0
Add x.toStr to the end of the buffer
Call join but only if x is non-null
Convenience for adding newline char
Create an output stream to append characters to this string buffer
Remove the char at the specified index
Remove a range of indices from this buffer
Replaces a range of indices from this buffer with the specified string
Reverse the contents of this string buffer
Replace the existing character at index in this buffer
Return the number of characters in the buffer
Convenience for adding space char
Add given number of spaces to the buffer
Return the current buffer contents as a Str
Remove any trailing whitespace in the buffer
This add(Obj? x)
Add x.toStr to the end of this buffer. If x is null then the string "null" is inserted. Return this.
This addChar(Int ch)
Optimized implementation for add(ch.toChar). Return this.
This addRange(Str s, Range r)
Add a substring of the given string to the buffer. Return this.
This addTrim(Str x)
Add string with its leading and trailing whitespace trimmed. Return this.
Int : capacity
The number of characters this buffer can hold without allocating more memory.
This clear()
Clear the contents of the string buffer so that it has a size of zero. Return this.
@Operator
Int get(Int index)
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.
@Operator
Str getRange(Range range)
Return a substring based on the specified range. Negative indexes may be used to access from the end of the string buffer. This method is accessed via the [] operator. Throw IndexErr if range illegal.
Examples:
"abcd"[0..2] => "abc"
"abcd"[3..3] => "d"
"abcd"[-2..-1] => "cd"
"abcd"[0..<2] => "ab"
"abcd"[1..-2] => "bc"
"abcd"[4..-1] => ""
This insert(Int index, Obj? x)
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.
Bool isEmpty()
Return if size() == 0.
This join(Obj? x, Str sep := " ")
Add x.toStr to the end of the buffer. If the buffer is not empty, then first add the specified separator which defaults to a space if not specified. Return this.
This joinNotNull(Obj? x, Str sep := " ")
Call join but only if x is non-null.
new make(Int capacity := 16)
Create with initial capacity (defaults to 16).
This nl()
Convenience for adding newline char
OutStream out()
Create an output stream to append characters to this string buffer. The output stream is designed to write character data, attempts to do binary writes will throw UnsupportedErr.
This remove(Int index)
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 this. Throw IndexErr if index is out of range.
This removeRange(Range r)
Remove a range of indices from this buffer. Negative indexes may be used to access from the end of the list. Throw IndexErr if range illegal. Return this.
This replaceRange(Range r, Str str)
Replaces a range of indices from this buffer with the specified string. Negative indexes may be used to access from the end of the buffer. Throw IndexErr if range illegal. Return this.
This reverse()
Reverse the contents of this string buffer. Return this.
@Operator
This set(Int index, Int ch)
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.
Int size()
Return the number of characters in the buffer.
This sp()
Convenience for adding space char
This tab(Int num)
Add given number of spaces to the buffer
virtual Str toStr()
Return the current buffer contents as a Str.
This trimEnd()
Remove any trailing whitespace in the buffer. Return this.