XU XUv0.16.0

#bytes

import: #bytes

counts: 51 functions, 31 methods, 4 types, 0 constants, 0 method sets

Work with byte data stored in strings, including search, replacement and Buffer I/O. Individual APIs distinguish byte operations from Unicode character operations.

struct Buffer

XuAPI
pub struct Buffer {
    pub data string
    pub off int
}

Purpose

Structure encapsulating data, off.

Public fields

data string
data
off int
offset

buffer

XuAPI
pub fn buffer() Buffer

Purpose

Execute buffer.

Parameters

No arguments are required.

Returns

Buffer — a value of this type

buffer_from

XuAPI
pub fn buffer_from(s string) Buffer

Purpose

Buffer from.

Parameters

s string
source string (string)

Returns

Buffer — a value of this type

($&Buffer) write

XuAPI
pub fn (b $&Buffer) write(data &string) int

Purpose

Operation on $&Buffer: write data and return the byte count.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
data &string
data (read-only borrow; caller keeps the original; type &string)

Returns

int — bytes written

($&Buffer) write_byte

XuAPI
pub fn (b $&Buffer) write_byte(c int) int

Purpose

Operation on $&Buffer: write one byte. Throws on failure; handle the error or propagate it to the caller.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
c int
byte or character code (int)

Returns

int — bytes written

($&Buffer) read_n

XuAPI
pub fn (b $&Buffer) read_n(n int) string

Purpose

Operation on $&Buffer: read at most n bytes; may return shorter or empty at end.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

string — result string

(&Buffer) length

XuAPI
pub fn (b &Buffer) length() int

Purpose

Operation on &Buffer: return the current length.

Parameters

b &Buffer
The Buffer instance used by this call (borrow).

Returns

int — a value of this type

(&Buffer) text

XuAPI
pub fn (b &Buffer) text() string

Purpose

Operation on &Buffer: return the current text.

Parameters

b &Buffer
The Buffer instance used by this call (borrow).

Returns

string — result string

(&Buffer) bytes

XuAPI
pub fn (b &Buffer) bytes() string

Purpose

Operation on &Buffer: return the buffered bytes.

Parameters

b &Buffer
The Buffer instance used by this call (borrow).

Returns

string — result string

($&Buffer) reset

XuAPI
pub fn (b $&Buffer) reset()

Purpose

Operation on $&Buffer: clear internal state so the value can be reused.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Buffer) truncate

XuAPI
pub fn (b $&Buffer) truncate(n int) int

Purpose

Execute truncate on $&Buffer. Throws on failure; handle the error or propagate it to the caller.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

int — a value of this type

view_of

XuAPI
pub fn view_of(s &string) strings.ByteView

Purpose

Create a borrowed read-only ByteView over the string.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

strings.ByteView — a value of this type

view_slice

XuAPI
pub fn view_slice(s &string, off int, n int) strings.ByteView

Purpose

View slice.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
off int
offset (int)
n int
count, length, or limit (int)

Returns

strings.ByteView — a value of this type

equal

XuAPI
pub fn equal(a &string, b &string) bool

Purpose

Report whether the two values are equal.

Parameters

a &string
value (read-only borrow; caller keeps the original; type &string)
b &string
b (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

compare

XuAPI
pub fn compare(a &string, b &string) int

Purpose

Lexicographic compare: -1, 0, or 1.

Parameters

a &string
left operand (read-only borrow; caller keeps the original; type &string)
b &string
right operand (read-only borrow; caller keeps the original; type &string)

Returns

int — negative if less, zero if equal, positive if greater

has_prefix

XuAPI
pub fn has_prefix(s &string, prefix string) bool

Purpose

Report whether the value has the given prefix.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
prefix string
prefix (string)

Returns

bool — true or false

has_suffix

XuAPI
pub fn has_suffix(s &string, suffix string) bool

Purpose

Report whether the value has the given suffix.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
suffix string
suffix (string)

Returns

bool — true or false

index_byte

XuAPI
pub fn index_byte(s &string, c int) int

Purpose

Index of the first byte c; -1 if missing.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
c int
byte or character code (int)

Returns

int — index; see the description for its range and special values

last_index_byte

XuAPI
pub fn last_index_byte(s &string, c int) int

Purpose

Index of the last byte c; -1 if missing.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
c int
byte or character code (int)

Returns

int — index; see the description for its range and special values

last_index

XuAPI
pub fn last_index(s &string, sub string) int

Purpose

Index of the last occurrence; -1 if missing.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sub string
substring (string)

Returns

int — index; see the description for its range and special values

count

XuAPI
pub fn count(s &string, sub string) int

Purpose

Count non-overlapping occurrences.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sub string
substring (string)

Returns

int — a value of this type

replace

XuAPI
pub fn replace(s &string, old string, new string, n int) string

Purpose

Replace a substring, limited by n.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
old string
old value / piece to replace (string)
new string
new value / replacement (string)
n int
count, length, or limit (int)

Returns

string — result string

replace_all

XuAPI
pub fn replace_all(s &string, old string, new string) string

Purpose

Replace every occurrence of the substring.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
old string
old value / piece to replace (string)
new string
new value / replacement (string)

Returns

string — result string

contains

XuAPI
pub fn contains(s &string, sub string) bool

Purpose

Report whether the input contains the given piece.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sub string
substring (string)

Returns

bool — true or false

index

XuAPI
pub fn index(s &string, sub string) int

Purpose

Index of the first occurrence; -1 if missing.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sub string
substring (string)

Returns

int — index; see the description for its range and special values

trim_left

XuAPI
pub fn trim_left(s &string, cutset string) string

Purpose

Strip leading bytes that appear in the cutset.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
cutset string
bytes to trim (string)

Returns

string — result string

trim_right

XuAPI
pub fn trim_right(s &string, cutset string) string

Purpose

Strip trailing bytes that appear in the cutset.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
cutset string
bytes to trim (string)

Returns

string — result string

trim

XuAPI
pub fn trim(s &string, cutset string) string

Purpose

Strip leading and trailing bytes that appear in the cutset.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
cutset string
bytes to trim (string)

Returns

string — result string

trim_space

XuAPI
pub fn trim_space(s &string) string

Purpose

Strip leading and trailing ASCII whitespace.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

trim_prefix

XuAPI
pub fn trim_prefix(s &string, pre string) string

Purpose

Remove prefix if present; otherwise return the input.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
pre string
prefix (string)

Returns

string — result string

trim_suffix

XuAPI
pub fn trim_suffix(s &string, suf string) string

Purpose

Remove suffix if present; otherwise return the input.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
suf string
suffix (string)

Returns

string — result string

join

XuAPI
pub fn join(parts []string, sep string) string

Purpose

Join pieces with a separator.

Parameters

parts []string
parts ([]string)
sep string
separator (string)

Returns

string — result string

split

XuAPI
pub fn split(s &string, sep string) []string

Purpose

Split on the separator.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sep string
separator (string)

Returns

[]string — slice result

fields

XuAPI
pub fn fields(s &string) []string

Purpose

Split on whitespace runs and drop the whitespace.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

[]string — slice result

index_func

XuAPI
pub fn index_func(s &string, f fn(int) bool) int

Purpose

Text callbacks receive runes, aligned with strings. MapBytes remains byte-based.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
f fn(int) bool
Callback with signature fn(int) bool; pass the function value for this operation to invoke.

Returns

int — index; see the description for its range and special values

last_index_func

XuAPI
pub fn last_index_func(s &string, f fn(int) bool) int

Purpose

Last index where the callback is true; -1 if missing.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
f fn(int) bool
Callback with signature fn(int) bool; pass the function value for this operation to invoke.

Returns

int — index; see the description for its range and special values

map_bytes

XuAPI
pub fn map_bytes(s &string, f fn(int) int) string

Purpose

Map each byte through f and rebuild the string.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
f fn(int) int
Callback with signature fn(int) int; pass the function value for this operation to invoke.

Returns

string — result string

fields_func

XuAPI
pub fn fields_func(s &string, f fn(int) bool) []string

Purpose

Split on bytes for which the callback is true.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
f fn(int) bool
Callback with signature fn(int) bool; pass the function value for this operation to invoke.

Returns

[]string — slice result

clone

XuAPI
pub fn clone(s &string) string

Purpose

Copy into a new independent string.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

contains_func

XuAPI
pub fn contains_func(s &string, f fn(int) bool) bool

Purpose

Report whether any byte satisfies the callback.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
f fn(int) bool
Callback with signature fn(int) bool; pass the function value for this operation to invoke.

Returns

bool — true or false

index_any

XuAPI
pub fn index_any(s &string, chars string) int

Purpose

Index of the first byte that appears in the cutset; -1 if missing.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
chars string
byte cutset (string)

Returns

int — index; see the description for its range and special values

last_index_any

XuAPI
pub fn last_index_any(s &string, chars string) int

Purpose

Last index of any cutset byte; -1 if missing.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
chars string
byte cutset (string)

Returns

int — index; see the description for its range and special values

contains_any

XuAPI
pub fn contains_any(s &string, chars string) bool

Purpose

Report whether any byte from the cutset occurs.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
chars string
byte cutset (string)

Returns

bool — true or false

index_rune

XuAPI
pub fn index_rune(s &string, r int) int

Purpose

Index of the first rune; -1 if missing.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
r int
rune (Unicode code point) (int)

Returns

int — index; see the description for its range and special values

contains_rune

XuAPI
pub fn contains_rune(s &string, r int) bool

Purpose

Report whether the rune occurs.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
r int
rune (Unicode code point) (int)

Returns

bool — true or false

split_n

XuAPI
pub fn split_n(s &string, sep string, n int) []string

Purpose

Split on the separator, at most n parts.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sep string
separator (string)
n int
count, length, or limit (int)

Returns

[]string — slice result

split_after

XuAPI
pub fn split_after(s &string, sep string) []string

Purpose

Split after the separator, keeping it on each piece.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sep string
separator (string)

Returns

[]string — slice result

split_after_n

XuAPI
pub fn split_after_n(s &string, sep string, n int) []string

Purpose

Split after the separator, at most n parts.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sep string
separator (string)
n int
count, length, or limit (int)

Returns

[]string — slice result

trim_left_func

XuAPI
pub fn trim_left_func(s &string, f fn(int) bool) string

Purpose

Trim leading bytes using the callback.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
f fn(int) bool
Callback with signature fn(int) bool; pass the function value for this operation to invoke.

Returns

string — result string

trim_right_func

XuAPI
pub fn trim_right_func(s &string, f fn(int) bool) string

Purpose

Trim trailing bytes using the callback.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
f fn(int) bool
Callback with signature fn(int) bool; pass the function value for this operation to invoke.

Returns

string — result string

trim_func

XuAPI
pub fn trim_func(s &string, f fn(int) bool) string

Purpose

Trim bytes on both ends using the callback.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
f fn(int) bool
Callback with signature fn(int) bool; pass the function value for this operation to invoke.

Returns

string — result string

to_valid_utf8

XuAPI
pub fn to_valid_utf8(s &string, replacement string) string

Purpose

Replace invalid UTF-8 sequences with replacement.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
replacement string
replacement for invalid sequences (string)

Returns

string — result string

repeat

XuAPI
pub fn repeat(s &string, n int) string

Purpose

Repeat the content n times; n<=0 yields empty.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
n int
count, length, or limit (int)

Returns

string — result string

equal_fold

XuAPI
pub fn equal_fold(a &string, b &string) bool

Purpose

ASCII case-insensitive equality.

Parameters

a &string
value (read-only borrow; caller keeps the original; type &string)
b &string
b (read-only borrow; caller keeps the original; type &string)

Returns

bool — true or false

to_lower

XuAPI
pub fn to_lower(s &string) string

Purpose

Map ASCII letters to lowercase.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

to_upper

XuAPI
pub fn to_upper(s &string) string

Purpose

Map ASCII letters to uppercase.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

($&Buffer) grow

XuAPI
pub fn (b $&Buffer) grow(n int)

Purpose

Operation on $&Buffer: ensure room for at least n more bytes.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

This call does not return a value.

($&Buffer) write_string

XuAPI
pub fn (b $&Buffer) write_string(s &string) int

Purpose

Operation on $&Buffer: write a string and return the byte count.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

int — bytes written

($&Buffer) write_rune

XuAPI
pub fn (b $&Buffer) write_rune(r int) int

Purpose

Operation on $&Buffer: write a rune as UTF-8. Throws on failure; handle the error or propagate it to the caller.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
r int
rune (Unicode code point) (int)

Returns

int — bytes written

($&Buffer) read_byte

XuAPI
pub fn (b $&Buffer) read_byte() int

Purpose

Operation on $&Buffer: read one byte; throws on failure. Throws on failure; handle the error or propagate it to the caller.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Buffer) unread_byte

XuAPI
pub fn (b $&Buffer) unread_byte() int

Purpose

Operation on $&Buffer: unread the last byte. Throws on failure; handle the error or propagate it to the caller.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Buffer) read_rune

XuAPI
pub fn (b $&Buffer) read_rune() RuneRead

Purpose

Operation on $&Buffer: read one UTF-8 rune. Throws on failure; handle the error or propagate it to the caller.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).

Returns

RuneRead — a value of this type

($&Buffer) unread_rune

XuAPI
pub fn (b $&Buffer) unread_rune() int

Purpose

Operation on $&Buffer: unread the last rune. Throws on failure; handle the error or propagate it to the caller.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).

Returns

int — a value of this type

(&Buffer) cap

XuAPI
pub fn (b &Buffer) cap() int

Purpose

Operation on &Buffer: return the capacity.

Parameters

b &Buffer
The Buffer instance used by this call (borrow).

Returns

int — a value of this type

($&Buffer) next

XuAPI
pub fn (b $&Buffer) next(n int) string

Purpose

Operation on $&Buffer: take the next item, or end according to this type.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

string — result string

struct Cut

XuAPI
pub struct Cut {
    pub before string
    pub after string
    pub found bool
}

Purpose

Structure encapsulating before, after, found.

Public fields

before string
field (string)
after string
field (string)
found bool
field (bool)

cut

XuAPI
pub fn cut(s &string, sep string) Cut

Purpose

Cut into before/after at the first sep.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
sep string
separator (string)

Returns

Cut — a value of this type

cut_prefix

XuAPI
pub fn cut_prefix(s &string, pre string) Cut

Purpose

Cut off a prefix when present.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
pre string
prefix (string)

Returns

Cut — a value of this type

cut_suffix

XuAPI
pub fn cut_suffix(s &string, suf string) Cut

Purpose

Cut off a suffix when present.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)
suf string
suffix (string)

Returns

Cut — a value of this type

($&Buffer) read_bytes

XuAPI
pub fn (b $&Buffer) read_bytes(delim int) string

Purpose

Operation on $&Buffer: read through delim (inclusive).

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
delim int
delim (int)

Returns

string — result string

($&Reader) read_result

XuAPI
pub fn (r $&Reader) read_result(n int) io.ReadResult

Purpose

Operation on $&Reader: read result.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

io.ReadResult — a value of this type

($&Buffer) read_result

XuAPI
pub fn (b $&Buffer) read_result(n int) io.ReadResult

Purpose

Operation on $&Buffer: read result.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

io.ReadResult — a value of this type

($&Buffer) write_result

XuAPI
pub fn (b $&Buffer) write_result(data string) io.WriteResult

Purpose

Operation on $&Buffer: write result.

Parameters

b $&Buffer
The Buffer instance used by this call (exclusive borrow).
data string
data (string)

Returns

io.WriteResult — a value of this type

struct Reader

XuAPI
pub struct Reader {

}

Purpose

Bytes Streaming reader and decoder.

Public fields

This type has no public fields.

struct RuneRead

XuAPI
pub struct RuneRead {
    pub ch int
    pub size int
}

Purpose

Structure encapsulating ch, size.

Public fields

ch int
character code
size int
field (int)

new_reader

XuAPI
pub fn new_reader(s string) Reader

Purpose

Construct reader.

Parameters

s string
source string (string)

Returns

Reader — a value of this type

(&Reader) size

XuAPI
pub fn (r &Reader) size() int

Purpose

Operation on &Reader: return the size.

Parameters

r &Reader
The Reader instance used by this call (borrow).

Returns

int — a value of this type

(&Reader) length

XuAPI
pub fn (r &Reader) length() int

Purpose

Operation on &Reader: return the current length.

Parameters

r &Reader
The Reader instance used by this call (borrow).

Returns

int — a value of this type

($&Reader) reset

XuAPI
pub fn (r $&Reader) reset(s string)

Purpose

Operation on $&Reader: clear internal state so the value can be reused.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
s string
source string (string)

Returns

This call does not return a value.

($&Reader) read_n

XuAPI
pub fn (r $&Reader) read_n(n int) string

Purpose

Operation on $&Reader: read at most n bytes; may return shorter or empty at end.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

string — result string

($&Reader) read_byte

XuAPI
pub fn (r $&Reader) read_byte() int

Purpose

Operation on $&Reader: read one byte; throws on failure. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Reader) unread_byte

XuAPI
pub fn (r $&Reader) unread_byte() int

Purpose

Operation on $&Reader: unread the last byte. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Reader) read_rune

XuAPI
pub fn (r $&Reader) read_rune() RuneRead

Purpose

Operation on $&Reader: read one UTF-8 rune. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).

Returns

RuneRead — a value of this type

($&Reader) unread_rune

XuAPI
pub fn (r $&Reader) unread_rune() int

Purpose

Operation on $&Reader: unread the last rune. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Reader) seek

XuAPI
pub fn (r $&Reader) seek(offset int, whence int) int

Purpose

Operation on $&Reader: move the read position. whence 0/1/2 = absolute / relative / from end. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
offset int
offset (int)
whence int
seek base: 0 start / 1 current / 2 end (int)

Returns

int — a value of this type

($&Reader) read_at

XuAPI
pub fn (r $&Reader) read_at(n int, off int) string

Purpose

Operation on $&Reader: read at most n bytes starting at offset off. Throws on failure; handle the error or propagate it to the caller.

Parameters

r $&Reader
The Reader instance used by this call (exclusive borrow).
n int
count, length, or limit (int)
off int
offset (int)

Returns

string — result string