class sys::StrBuf

sys::Obj
  sys::StrBuf

Source

StrBuf is a mutable sequence of Int characters.

add

This add(Obj? x)

Source

Add x.toStr to the end of this buffer. If x is null then the string "null" is inserted. Return this.

addChar

This addChar(Int ch)

Source

Optimized implementation for add(ch.toChar). Return this.

capacity

Int capacity

Source

The number of characters this buffer can hold without allocating more memory.

clear

This clear()

Source

Clear the contents of the string buffer so that it has a size of zero. Return this.

get

@Operator
Int get(Int index)

Source

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.

getRange

@Operator
Str getRange(Range range)

Source

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]  => ""
insert

This insert(Int index, Obj? x)

Source

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.

isEmpty

Bool isEmpty()

Source

Return if size() == 0.

join

This join(Obj? x, Str sep := " ")

Source

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.

make

new make(Int capacity := 16)

Source

Create with initial capacity (defaults to 16).

out

OutStream out()

Source

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.

remove

This remove(Int index)

Source

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.

removeRange

This removeRange(Range r)

Source

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.

replaceRange

This replaceRange(Range r, Str str)

Source

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.

reverse

This reverse()

Source

Reverse the contents of this string buffer. Return this.

set

@Operator
This set(Int index, Int ch)

Source

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.

size

Int size()

Source

Return the number of characters in the buffer.

toStr

virtual override Str toStr()

Source

Return the current buffer contents as a Str.