class StringBuffer : Vector
Since MiniD's strings are immutable, this class provides a mutable, resizable string object for building up strings piecewise, or just for having a modifiable string.
Notice that StringBuffer inherits from Vector. Most operations that are legal on Vectors are also legal on StringBuffers.
Methods
- this(v: string = "")
- fill(v: char|string|array|function|StringBuffer)
- `fillRange(lo: int = 0, hi: int = #this, v: …
- format(vararg)
- formatln(vararg)
- insert(position: int, value)
- remove(start: int [, end: int = start + 1])
- toString()
- append(vararg)
- opCatAssign
- opLength()
- opLengthAssign(newLength: int)
- opIndex(index: int)
- opIndexAssign(index: int, value: char)
- opSlice(lo: int, hi: int)
- opSliceAssign
- opApply([reverse: string])
this(v: string = "")
The StringBuffer's constructor. Takes a string which should be the initial data in the StringBuffer instance. If no string is passed, it defaults to "", which means there will be no data in it (it will have a length of 0).
fill(v: char|string|array|function|StringBuffer)
A pretty flexible way to fill a StringBuffer with some data. This only modifies existing data; the buffer's length is never changed.
If you pass a character, every character in the buffer will be set to that character.
If you pass a string, it must be the same length as the buffer, and the string's data is copied into the buffer.
If you pass an array, it must be the same length of the buffer and all its elements must be characters. Those characters will be copied into the buffer.
If you pass a StringBuffer, it must be the same length as the buffer and its data will be copied into this buffer.
If you pass a function, it must take an integer and return a character. It will be called on each location in the buffer, and the resulting characters will be put into the buffer.
fillRange(lo: int = 0, hi: int = #this, v: char|string|array|function|StringBuffer)
Works just like fill, except it works on just a subrange of the buffer. The lo and hi params work just like slice indices - low inclusive, high noninclusive, negative from the end.
format(vararg)
Calls format on the given parameters and appends the result to the end of the buffer.
formatln(vararg)
Similar to above, except it also appends the character '\n' after the formatted string.
insert(position: int, value)
This inserts the string representation of the value before the given position in the buffer. The position can be negative, which means an index from the end of the buffer. The position can be the length of the string buffer, in which case the data is appended to the end of the buffer.
remove(start: int [, end: int = start + 1])
This removes a sequence of characters from a StringBuffer. The start index is inclusive, the end index noninclusive. Either index can be negative, which means an index from the end of the buffer. The end index defaults to one after the start index, which means calling this function with just a start index will remove one character from the buffer.
toString()
Converts the contents of the string buffer to an immutable string value.
append(vararg)
This function is the main way to add data into a string buffer. Each value in vararg will have toString called on it if it's not a string or char already, and the resulting string will be appended to the end of the buffer. If a value is an instance of StringBuffer, its contents will be appended to the end of this buffer.
opCatAssign
This is simply an alias to append. That is, performing "sb ~= a ~ b ~ c" is identical to calling "sb.append(a, b, c)".
opLength()
This is an overload of the length operator (#), so the length of the buffer can be retrieved.
opLengthAssign(newLength: int)
This overload of the length operator sets the length of the buffer to the given length. If the new length is longer than the old length, the new slots are filled with the UTF-32 character U+00FFFF.
opIndex(index: int)
An overload of the indexing operator, for getting a character in the buffer. It returns a character. Negative indices mean an index from the end of the buffer.
opIndexAssign(index: int, value: char)
An overload of the index-assign operator, for setting a character in the buffer. Negative indices mean an index from the end of the buffer.
opSlice(lo: int, hi: int)
An overload of the slicing operator, for retrieving a subset of the buffer. The low and high indices can be negative to indicate an index from the end of the array. This returns a string, not a StringBuffer.
opSliceAssign
This is simply an alias to fillRange. That is, performing "sb[x .. y] = z" is identical to "sb.fillRange(x, y, z)" for any x, y, and z.
opApply([reverse: string])
This allows you to iterate over a StringBuffer with a foreach loop. The optional reverse parameter will make the iteration go in reverse if you pass in the string value "reverse".
