strbuf
Growable string buffer.
StrBuf stores a NUL-terminated byte buffer in a region. Growth allocates a new buffer in the same region and copies existing content.
Notes:
- This is a byte buffer; it does not enforce UTF-8 boundaries.
- All allocations are performed in the provided
Region.
Types
StrBuf
Opaque string buffer allocated in a Region.
Functions
append(buf: StrBuf, foreign text: String) -> void
Append a string to the end of the buffer.
Parameters
buf: StrBuf- Buffer.foreign text: String- String to append.
---
append_char(buf: StrBuf, ch: char) -> void
Append a single byte to the end of the buffer.
Parameters
buf: StrBuf- Buffer.ch: char- Byte to append.
---
clear(buf: StrBuf) -> void
Clears the buffer.
Parameters
buf: StrBuf- Buffer.
Notes
- Does not deallocate or free anything, just resets the buffer pointer.
---
len(buf: StrBuf) -> int
Get the length of the buffer in bytes.
Parameters
buf: StrBuf- Buffer.
Returns
- The number of bytes in the buffer.
---
new(foreign text: String, region: Region) -> StrBuf
Create a new buffer from initial content.
Parameters
foreign text: String- Initial content.region: Region- Allocation region.
Returns
- A new
StrBuf.
---
pop(buf: StrBuf) -> char
Pop a single byte from the end of the buffer.
Parameters
buf: StrBuf- Buffer.
Returns
- A byte from the end of the buffer.
---
print(buf: StrBuf) -> void
Prints the buffer.
Parameters
buf: StrBuf- Buffer.
---
to_string(foreign buf: StrBuf, region: Region) -> String
Converts the buffer contents to a String.
Parameters
foreign buf: StrBuf- Buffer.region: Region- Region to allocate the String.
Returns
- Contents of the buffer as a String.