core/bytes

bytes

Types

2

Buffer

Buffer :: struct { buf: [dynamic]u8, off: int, last_read: Read_Op, }Source

A Buffer is a variable-sized buffer of bytes with a io.Stream interface The zero value for Buffer is an empty buffer ready to use.

Constants

1

Procedures

125

alias

alias :: proc(a: []u8, b: []u8) -> (bool)Source

alias 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)Source

alias_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).

centre_justify

centre_justify :: proc(str: []u8, length: int, pad: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Source

centre_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)Source

compare

compare :: proc(lhs: []u8, rhs: []u8) -> (int)Source

Compares two []byte, returning a value representing which one comes first lexiographically. Returns: -1 for lhs, 1 for rhs, or 0 if they are equal.

fields

fields :: proc(s: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Source

fields 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)Source

fields_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

index_byte

index_byte :: proc(s: []u8, c: u8) -> (index: int)Source

Scan a slice of bytes for a specific byte.

This procedure safely handles slices of any length, including empty slices.

  • data: A slice of bytes.
  • c: The byte to search for.
  • index: The index of the byte c, or -1 if it was not found.

join

join :: proc(a: [][]u8, sep: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Source

last_index_byte

last_index_byte :: proc(s: []u8, c: u8) -> (int)Source

Scan 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.

  • data: A slice of bytes.
  • c: The byte to search for.
  • index: The index of the byte c, or -1 if it was not found.

left_justify

left_justify :: proc(str: []u8, length: int, pad: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Source

left_justify returns a byte slice with a pad byte slice at left side if the str's rune length is smaller than length

remove

remove :: proc(s: []u8, key: []u8, n: int, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> (output: []u8, was_allocation: bool)Source

repeat

repeat :: proc(s: []u8, count: int, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Source

replace

replace :: proc( s: []u8, old: []u8, new: []u8, n: int, allocator: mem.Allocator = context.allocator, loc: _ = #caller_location, ) -> (output: []u8, was_allocation: bool)Source

if n < 0, no limit on the number of replacements

right_justify

right_justify :: proc(str: []u8, length: int, pad: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Source

right_justify returns a byte slice with a pad byte slice at right side if the str's rune length is smaller than length

scrub

scrub :: proc(s: []u8, replacement: []u8, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([]u8)Source

Scrubs 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)Source

split_multi

split_multi :: proc(s: []u8, substrs: [][]u8, skip_empty: untyped boolean = false, allocator: mem.Allocator = context.allocator, loc = #caller_location) -> ([][]u8)Source

Reference search

Find anything

Documentation preferences

Settings

System theme variants

Used only while Theme is set to System.