strbuf.eh
String buffers. More...
Types
Functions
Description
String buffer is a mutable sequence of characters. Many of
StrBuf
functions
return the string buffer after operation allowing to write sequences like
String buffers are essentially effective when you need to construct new string.
Compare:
var str = ""
for (var i=0, i<100, i+=1)
str += i
var sb = new StrBuf()
for (var i=0, i<100, i+=1)
sb.append(i)
var str = sb.tostr()
|
In the first cycle new string is created on each iteration, wasting memory
and time on memory allocation. The second cycle is more efficient in both
memory and time. You may still use string concatenation for simple cases though,
compiler automatically turns long concatenations into
StrBuf
calls.
Type details
Mutable character sequence.
At any point in time it contains some particular sequence of characters, but the
length and content of the sequence can be changed.
Function details
Creates new empty string buffer.
Returns character at the specified position of this string buffer.
You may also use square brackets to get character (
strbuf[at]
).
Appends text representation of given value to the end of this string buffer.
The string representation is the same as returned by
Any.tostr. Note that character
literals are
Int
numbers so for example calling
strbuf.append('!')
actually
adds string
"33"
to the string buffer
strbuf. To add single character use
addch function.
Adds given character to the end of the string buffer.
Inserts string representation of given value at specified index of this string buffer.
The string representation is the same as returned by
Any.tostr.
Inserts given character at specified index of this string buffer.
Replaces substring of this string buffer by the string representation of given value.
The string representation is the same as returned by
Any.tostr.
Replaces character at specified index of this string buffer with given one.
Removes all characters in given range from this string buffer.
Removes character at specified index from this string buffer.
Returns current number of characters in this string buffer.
Copies characters from given range of this string buffer to the character array
buf starting at offset
ofs.