core/bufio

bufio

Types

8

Lookahead_Reader

Lookahead_Reader :: struct { r: io.Reader, buf: []u8, n: int, }Source

Lookahead_Reader provides io lookahead. This is useful for tokenizers/parsers. Lookahead_Reader is similar to bufio.Reader, but unlike bufio.Reader, Lookahead_Reader's buffer size will EXACTLY match the specified size, whereas bufio.Reader's buffer size may differ from the specified size. This makes sure that the buffer will not be accidentally read beyond the expected size.

Constants

2

Procedures

54

reader_peek

reader_peek :: proc(b: ^Reader, n: int) -> (data: []u8, err: io.Error)Source

reader_peek returns the next n bytes without advancing the reader The bytes stop being valid on the next read call If reader_peek returns fewer than n bytes, it also return an error explaining why the read is short The error will be .Buffer_Full if n is larger than the internal buffer size

reader_read_bytes

reader_read_bytes :: proc(b: ^Reader, delim: u8, allocator: mem.Allocator = context.allocator) -> (buf: []u8, err: io.Error)Source

reader_read_bytes reads until the first occurrence of delim from the Reader It returns an allocated slice containing the data up to and including the delimiter

reader_read_rune

reader_read_rune :: proc(b: ^Reader) -> (r: rune, size: int, err: io.Error)Source

reader_read_rune reads a single UTF-8 encoded unicode character and returns the rune and its size in bytes If the encoded rune is invalid, it consumes one byte and returns utf8.RUNE_ERROR (U+FFFD) with a size of 1

reader_read_slice

reader_read_slice :: proc(b: ^Reader, delim: u8) -> (line: []u8, err: io.Error)Source

reader_read_slice reads until the first occurrence of delim in the input, returning a slice pointing at the bytes in the internal buffer. The returned slice is only valid until the next read call. If the buffer fills without finding delim, it returns .Buffer_Full. If the underlying reader returns an error before finding delim, that error is returned. Because the returned data will be overwritten by the next I/O operation, reader_read_bytes or reader_read_string is usually preferred.

reader_read_slice returns err != nil if and only if line does not end in delim.

scan_lines

scan_lines :: proc(data: []u8, at_eof: bool) -> (advance: int, token: []u8, err: Scanner_Error, final_token: bool)Source

scan_lines is a splitting procedure that returns each line of text stripping of any trailing newline and an optional preceding carriage return (\r?\n). A new line is allowed to be empty.

scan_runes

scan_runes :: proc(data: []u8, at_eof: bool) -> (advance: int, token: []u8, err: Scanner_Error, final_token: bool)Source

scan_runes is a splitting procedure that returns each UTF-8 encoded rune as a token. The lsit of runes return is equivalent to that of iterating over a string in a 'for in' loop, meaning any erroneous UTF-8 encodings will be returned as U+FFFD. Unfortunately this means it is impossible for the "client" to know whether a U+FFFD is an expected replacement rune or an encoding of an error.

scan_words

scan_words :: proc(data: []u8, at_eof: bool) -> (advance: int, token: []u8, err: Scanner_Error, final_token: bool)Source

scan_words is a splitting procedure that returns each Unicode-space-separated word of text, excluding the surrounded spaces. It will never return return an empty string.

scanner_bytes

scanner_bytes :: proc(s: ^Scanner) -> ([]u8)Source

Returns the most recent token created by 'scan'. The underlying array may point to data that may be overwritten by another call to 'scan'. Treat the returned value as if it is immutable.

scanner_text

scanner_text :: proc(s: ^Scanner) -> (string)Source

Returns the most recent token created by 'scan'. The underlying array may point to data that may be overwritten by another call to 'scan'. Treat the returned value as if it is immutable.

writer_read_from

writer_read_from :: proc(b: ^Writer, r: io.Reader) -> (n: i64, err: io.Error)Source

writer_read_from is to support io.Reader_From types If the underlying writer supports the io,read_from, and b has no buffered data yet, this procedure calls the underlying read_from implementation without buffering

writer_write

writer_write :: proc(b: ^Writer, p: []u8) -> (n: int, err: io.Error)Source

writer_write writes the contents of p into the buffer It returns the number of bytes written If n < len(p), it will return an error explaining why the write is short

Reference search

Find anything

Documentation preferences

Settings

System theme variants

Used only while Theme is set to System.