core/bytes
bytes
Types
2Constants
1Procedures
125alias
alias :: proc(a: []u8, b: []u8) -> (bool)Sourcealias returns true if and only if (⟺) a and b have a non-zero length, and any part of a overlaps with b.
alias_inexactly
alias_inexactly :: proc(a: []u8, b: []u8) -> (bool)Sourcealias_inexactly returns true if and only if (⟺) a and b have a non-zero length, the base pointer of a and b are NOT equal, and any part of a overlaps with b (ie: alias(a, b) with an exception that returns false for a == b, b = a[:len(a)-69] and similar conditions).
buffer_capacity
buffer_capacity :: proc(b: ^Buffer) -> (int)Sourcebuffer_destroy
buffer_destroy :: proc(b: ^Buffer)Sourcebuffer_grow
buffer_grow :: proc(b: ^Buffer, n: int, loc = #caller_location)Sourcebuffer_init
buffer_init :: proc(b: ^Buffer, buf: []u8, loc = #caller_location)Sourcebuffer_init_allocator
buffer_init_allocator :: proc(b: ^Buffer, len: int, cap: int, allocator: mem.Allocator = context.allocator, loc = #caller_location)Sourcebuffer_init_string
buffer_init_string :: proc(b: ^Buffer, s: string, loc = #caller_location)Sourcebuffer_is_empty
buffer_is_empty :: proc(b: ^Buffer) -> (bool)Sourcebuffer_length
buffer_length :: proc(b: ^Buffer) -> (int)Sourcebuffer_next
buffer_next :: proc(b: ^Buffer, n: int) -> ([]u8)Sourcebuffer_read
buffer_read :: proc(b: ^Buffer, p: []u8) -> (n: int, err: io.Error)Sourcebuffer_read_at
buffer_read_at :: proc(b: ^Buffer, p: []u8, offset: int) -> (n: int, err: io.Error)Sourcebuffer_read_byte
buffer_read_byte :: proc(b: ^Buffer) -> (io.Error, u8)Sourcebuffer_read_bytes
buffer_read_bytes :: proc(b: ^Buffer, delim: u8) -> (line: []u8, err: io.Error)Sourcebuffer_read_from
buffer_read_from :: proc(b: ^Buffer, r: io.Reader) -> (n: i64, err: io.Error)Sourcebuffer_read_ptr
buffer_read_ptr :: proc(b: ^Buffer, ptr: rawptr, size: int) -> (n: int, err: io.Error)Sourcebuffer_read_rune
buffer_read_rune :: proc(b: ^Buffer) -> (r: rune, size: int, err: io.Error)Sourcebuffer_read_slice
buffer_read_slice :: proc(b: ^Buffer, slice: S) -> (n: int, err: io.Error)Sourcebuffer_read_string
buffer_read_string :: proc(b: ^Buffer, delim: u8) -> (line: string, err: io.Error)Sourcebuffer_reset
buffer_reset :: proc(b: ^Buffer)Sourcebuffer_seek
buffer_seek :: proc(b: ^Buffer, offset: i64, whence: io.Seek_From) -> (io.Error, i64)Sourcebuffer_to_bytes
buffer_to_bytes :: proc(b: ^Buffer) -> ([]u8)Sourcebuffer_to_stream
buffer_to_stream :: proc(b: ^Buffer) -> (s: io.Stream)Sourcebuffer_to_string
buffer_to_string :: proc(b: ^Buffer) -> (string)Sourcebuffer_truncate
buffer_truncate :: proc(b: ^Buffer, n: int)Sourcebuffer_unread_byte
buffer_unread_byte :: proc(b: ^Buffer) -> (io.Error)Sourcebuffer_unread_rune
buffer_unread_rune :: proc(b: ^Buffer) -> (io.Error)Sourcebuffer_write
buffer_write :: proc(b: ^Buffer, p: []u8, loc = #caller_location) -> (n: int, err: io.Error)Sourcebuffer_write_at
buffer_write_at :: proc(b: ^Buffer, p: []u8, offset: int, loc = #caller_location) -> (n: int, err: io.Error)Sourcebuffer_write_byte
buffer_write_byte :: proc(b: ^Buffer, c: u8, loc = #caller_location) -> (io.Error)Sourcebuffer_write_ptr
buffer_write_ptr :: proc(b: ^Buffer, ptr: rawptr, size: int, loc = #caller_location) -> (n: int, err: io.Error)Sourcebuffer_write_rune
buffer_write_rune :: proc(b: ^Buffer, r: rune, loc = #caller_location) -> (n: int, err: io.Error)Sourcebuffer_write_slice
buffer_write_slice :: proc(b: ^Buffer, slice: S, loc = #caller_location) -> (n: int, err: io.Error)Sourcebuffer_write_string
buffer_write_string :: proc(b: ^Buffer, s: string, loc = #caller_location) -> (n: int, err: io.Error)Sourcebuffer_write_to
buffer_write_to :: proc(b: ^Buffer, w: io.Writer) -> (n: i64, err: io.Error)Sourcecenter_justify
center_justify :: proc(str: []u8, length: int, pad: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)SourceNOTE(bill): Because Americans exist
centre_justify
centre_justify :: proc(str: []u8, length: int, pad: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourcecentre_justify returns a byte slice with a pad byte slice at boths sides if the str's rune length is smaller than length
clone
clone :: proc(s: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourceclone_safe
clone_safe :: proc(s: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> (data: []u8, err: runtime.Allocator_Error)Sourcecompare
compare :: proc(lhs: []u8, rhs: []u8) -> (int)SourceCompares two []byte, returning a value representing which one comes first lexiographically. Returns: -1 for lhs, 1 for rhs, or 0 if they are equal.
concatenate
concatenate :: proc(a: [][]u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourceconcatenate_safe
concatenate_safe :: proc(a: [][]u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> (data: []u8, err: runtime.Allocator_Error)Sourcecontains
contains :: proc(s: []u8, substr: []u8) -> (bool)Sourcecontains_any
contains_any :: proc(s: []u8, chars: []u8) -> (bool)Sourcecontains_rune
contains_rune :: proc(s: []u8, r: rune) -> (int)Sourcecount
count :: proc(s: []u8, substr: []u8) -> (int)Sourceequal
equal :: proc(a: []u8, b: []u8) -> (bool)Sourceequal_fold
equal_fold :: proc(u: []u8, v: []u8) -> (bool)Sourceexpand_tabs
expand_tabs :: proc(s: []u8, tab_size: int, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourcefields
fields :: proc(s: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Sourcefields splits the byte slice s around each instance of one or more consecutive white space character, defined by unicode.is_space returning a slice of subslices of s or an empty slice if s only contains white space
fields_proc
fields_proc :: proc(s: []u8, f: proc() -> (bool), allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Sourcefields_proc splits the byte slice s at each run of unicode code points ch satisfying f(ch) returns a slice of subslices of s If all code points in s satisfy f(ch) or string is empty, an empty slice is returned
fields_proc makes no guarantee about the order in which it calls f(ch) it assumes that f always returns the same value for a given ch
has_prefix
has_prefix :: proc(s: []u8, prefix: []u8) -> (bool)Sourcehas_suffix
has_suffix :: proc(s: []u8, suffix: []u8) -> (bool)Sourceindex
index :: proc(s: []u8, substr: []u8) -> (int)Sourceindex_any
index_any :: proc(s: []u8, chars: []u8) -> (int)Sourceindex_byte
index_byte :: proc(s: []u8, c: u8) -> (index: int)SourceScan a slice of bytes for a specific byte.
This procedure safely handles slices of any length, including empty slices.
Inputs:
- data: A slice of bytes.
- c: The byte to search for.
Returns:
- index: The index of the byte
c, or -1 if it was not found.
index_proc
index_proc :: proc(s: []u8, p: proc() -> (bool), truth: untyped boolean = true) -> (int)Sourceindex_proc_with_state
index_proc_with_state :: proc(s: []u8, p: proc() -> (bool), state: rawptr, truth: untyped boolean = true) -> (int)Sourceindex_rune
index_rune :: proc(s: []u8, r: rune) -> (int)Sourceis_ascii_space
is_ascii_space :: proc(r: rune) -> (bool)Sourceis_in_cutset
is_in_cutset :: proc(state: rawptr, r: rune) -> (bool)Sourceis_null
is_null :: proc(r: rune) -> (bool)Sourceis_space
is_space :: proc(r: rune) -> (bool)Sourcejoin
join :: proc(a: [][]u8, sep: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourcejoin_safe
join_safe :: proc(a: [][]u8, sep: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> (data: []u8, err: runtime.Allocator_Error)Sourcelast_index
last_index :: proc(s: []u8, substr: []u8) -> (int)Sourcelast_index_any
last_index_any :: proc(s: []u8, chars: []u8) -> (int)Sourcelast_index_byte
last_index_byte :: proc(s: []u8, c: u8) -> (int)SourceScan a slice of bytes for a specific byte, starting from the end and working backwards to the start.
This procedure safely handles slices of any length, including empty slices.
Inputs:
- data: A slice of bytes.
- c: The byte to search for.
Returns:
- index: The index of the byte
c, or -1 if it was not found.
last_index_proc
last_index_proc :: proc(s: []u8, p: proc() -> (bool), truth: untyped boolean = true) -> (int)Sourcelast_index_proc_with_state
last_index_proc_with_state :: proc(s: []u8, p: proc() -> (bool), state: rawptr, truth: untyped boolean = true) -> (int)Sourceleft_justify
left_justify :: proc(str: []u8, length: int, pad: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourceleft_justify returns a byte slice with a pad byte slice at left side if the str's rune length is smaller than length
partition
partition :: proc(str: []u8, sep: []u8) -> (head: []u8, match: []u8, tail: []u8)Sourceptr_from_bytes
ptr_from_bytes :: proc(str: []u8) -> (^u8)Sourceptr_from_slice
ptr_from_slice :: proc(str: []u8) -> (^u8)Sourcereader_init
reader_init :: proc(r: ^Reader, s: []u8) -> (io.Stream)Sourcereader_length
reader_length :: proc(r: ^Reader) -> (int)Sourcereader_read
reader_read :: proc(r: ^Reader, p: []u8) -> (n: int, err: io.Error)Sourcereader_read_at
reader_read_at :: proc(r: ^Reader, p: []u8, off: i64) -> (n: int, err: io.Error)Sourcereader_read_byte
reader_read_byte :: proc(r: ^Reader) -> (io.Error, u8)Sourcereader_read_ptr
reader_read_ptr :: proc(r: ^Reader, data: rawptr, len: int) -> (n: int, err: io.Error)Sourcereader_read_ptr_at
reader_read_ptr_at :: proc(r: ^Reader, data: rawptr, len: int, off: i64) -> (n: int, err: io.Error)Sourcereader_read_rune
reader_read_rune :: proc(r: ^Reader) -> (ch: rune, size: int, err: io.Error)Sourcereader_read_slice
reader_read_slice :: proc(r: ^Reader, slice: T) -> (n: int, err: io.Error)Sourcereader_read_slice_at
reader_read_slice_at :: proc(r: ^Reader, slice: T, off: i64) -> (n: int, err: io.Error)Sourcereader_seek
reader_seek :: proc(r: ^Reader, offset: i64, whence: io.Seek_From) -> (io.Error, i64)Sourcereader_size
reader_size :: proc(r: ^Reader) -> (i64)Sourcereader_to_stream
reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream)Sourcereader_unread_byte
reader_unread_byte :: proc(r: ^Reader) -> (io.Error)Sourcereader_unread_rune
reader_unread_rune :: proc(r: ^Reader) -> (io.Error)Sourcereader_write_to
reader_write_to :: proc(r: ^Reader, w: io.Writer) -> (n: i64, err: io.Error)Sourceremove
remove :: proc(s: []u8, key: []u8, n: int, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> (output: []u8, was_allocation: bool)Sourceremove_all
remove_all :: proc(s: []u8, key: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> (output: []u8, was_allocation: bool)Sourcerepeat
repeat :: proc(s: []u8, count: int, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourcereplace
replace :: proc(
s: []u8,
old: []u8,
new: []u8,
n: int,
allocator: mem.Allocator = context.allocator,
loc: _ = #caller_location,
) -> (output: []u8, was_allocation: bool)Sourceif n < 0, no limit on the number of replacements
replace_all
replace_all :: proc(s: []u8, old: []u8, new: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> (output: []u8, was_allocation: bool)Sourcereverse
reverse :: proc(s: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourceright_justify
right_justify :: proc(str: []u8, length: int, pad: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Sourceright_justify returns a byte slice with a pad byte slice at right side if the str's rune length is smaller than length
rune_count
rune_count :: proc(s: []u8) -> (int)Sourcescrub
scrub :: proc(s: []u8, replacement: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)SourceScrubs invalid utf-8 characters and replaces them with the replacement string Adjacent invalid bytes are only replaced once
split
split :: proc(s: []u8, sep: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Sourcesplit_after
split_after :: proc(s: []u8, sep: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Sourcesplit_after_iterator
split_after_iterator :: proc(s: ^[]u8, sep: []u8) -> ([]u8, bool)Sourcesplit_after_n
split_after_n :: proc(s: []u8, sep: []u8, n: int, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Sourcesplit_iterator
split_iterator :: proc(s: ^[]u8, sep: []u8) -> ([]u8, bool)Sourcesplit_multi
split_multi :: proc(s: []u8, substrs: [][]u8, skip_empty: untyped boolean = false, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Sourcesplit_multi_iterator
split_multi_iterator :: proc(s: ^[]u8, substrs: [][]u8, skip_empty: untyped boolean = false) -> ([]u8, bool)Sourcesplit_n
split_n :: proc(s: []u8, sep: []u8, n: int, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Sourcetrim
trim :: proc(s: []u8, cutset: []u8) -> ([]u8)Sourcetrim_left
trim_left :: proc(s: []u8, cutset: []u8) -> ([]u8)Sourcetrim_left_null
trim_left_null :: proc(s: []u8) -> ([]u8)Sourcetrim_left_proc
trim_left_proc :: proc(s: []u8, p: proc() -> (bool)) -> ([]u8)Sourcetrim_left_proc_with_state
trim_left_proc_with_state :: proc(s: []u8, p: proc() -> (bool), state: rawptr) -> ([]u8)Sourcetrim_left_space
trim_left_space :: proc(s: []u8) -> ([]u8)Sourcetrim_null
trim_null :: proc(s: []u8) -> ([]u8)Sourcetrim_prefix
trim_prefix :: proc(s: []u8, prefix: []u8) -> ([]u8)Sourcetrim_right
trim_right :: proc(s: []u8, cutset: []u8) -> ([]u8)Sourcetrim_right_null
trim_right_null :: proc(s: []u8) -> ([]u8)Sourcetrim_right_proc
trim_right_proc :: proc(s: []u8, p: proc() -> (bool)) -> ([]u8)Sourcetrim_right_proc_with_state
trim_right_proc_with_state :: proc(s: []u8, p: proc() -> (bool), state: rawptr) -> ([]u8)Sourcetrim_right_space
trim_right_space :: proc(s: []u8) -> ([]u8)Sourcetrim_space
trim_space :: proc(s: []u8) -> ([]u8)Sourcetrim_suffix
trim_suffix :: proc(s: []u8, suffix: []u8) -> ([]u8)Sourcetruncate_to_byte
truncate_to_byte :: proc(str: []u8, b: u8) -> ([]u8)Sourcetruncate_to_rune
truncate_to_rune :: proc(str: []u8, r: rune) -> ([]u8)Source