XU XUv0.8.8
中文

API

#strings

import: #strings

counts: 52 fns, 33 methods, 7 types, 0 consts, 0 ifaces

String helpers. Read-only functions take &string so the caller keeps the source. Search uses Horspool. Includes Builder / Reader / Replacer.

index_of

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

Purpose

Byte index of the first occurrence of sub in s. Empty sub returns 0; not found returns -1. Search uses Horspool.

Parameters

s &string
haystack (borrowed; caller keeps it)
sub string
needle substring

Returns

first index, or -1 if missing; empty sub yields 0

contains

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

Purpose

Whether s contains substring sub. An empty sub is treated as contained (index 0).

Parameters

s &string
haystack (borrowed; caller keeps it)
sub string
needle substring

Returns

true if found, else false

trim_space

XuAPI
pub fn trim_space(s &string) string

Purpose

Strip leading and trailing ASCII whitespace.

Parameters

s &string
source string (borrowed; caller keeps it; type &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 (borrowed; caller keeps it; type &string)
n int
count, length, or limit (int)

Returns

string — result string

join

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

Purpose

Join parts with sep. An empty slice yields the empty string.

Parameters

parts []string
strings to join
sep string
separator inserted between elements

Returns

the joined string

split

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

Purpose

Split s on sep. An empty sep does not split into bytes; the result is a one-element slice holding all of s.

Parameters

s &string
source (borrowed; caller keeps it)
sep string
separator; empty keeps the whole string as one part

Returns

[]string parts (including a trailing empty piece when s ends with sep)

has_prefix

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

Purpose

Whether s starts with pre.

Parameters

s &string
source (borrowed)
pre string
prefix

Returns

true if it does

has_suffix

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

Purpose

Whether s ends with suf.

Parameters

s &string
source (borrowed)
suf string
suffix

Returns

true if it does

ends_with

XuAPI
pub fn ends_with(s &string, suf string) bool

Purpose

Whether s ends with suf (same idea as has_suffix).

Parameters

s &string
source (borrowed)
suf string
suffix

Returns

true if it does

replace

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

Purpose

Replace old with new in s. n==0 or empty old returns s unchanged; n<0 replaces all; n>0 replaces at most n times.

Parameters

s &string
source (borrowed)
old string
substring to replace; empty means no replacement
new string
replacement
n int
max replacements; 0 leaves s unchanged; negative means all

Returns

a new string

fields

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

Purpose

Split on whitespace runs and drop the whitespace.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)

Returns

[]string — slice result

fields_func

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

Purpose

FieldsFunc: separator is any Unicode rune for which f returns true.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

Returns

[]string — slice result

to_lower

XuAPI
pub fn to_lower(s &string) string

Purpose

Map ASCII letters to lowercase.

Parameters

s &string
source string (borrowed; caller keeps it; 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 (borrowed; caller keeps it; type &string)

Returns

string — result string

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 (borrowed; caller keeps it; 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 (borrowed; caller keeps it; 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 (borrowed; caller keeps it; type &string)
cutset string
bytes to trim (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 (borrowed; caller keeps it; 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 (borrowed; caller keeps it; type &string)
suf string
suffix (string)

Returns

string — result string

compare

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

Purpose

Lexicographic compare: -1, 0, or 1.

Parameters

a &string
left operand (borrowed; caller keeps it; type &string)
b &string
right operand (borrowed; caller keeps it; type &string)

Returns

int — -1 if less, 0 if equal, 1 if greater

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 (borrowed; caller keeps it; type &string)
c int
byte or character code (int)

Returns

int — index; -1 if missing

last_index

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

Purpose

Index of the last occurrence; -1 if missing. Returns -1 if not found.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
sub string
substring (string)

Returns

int — index; -1 if missing

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 (borrowed; caller keeps it; type &string)
c int
byte or character code (int)

Returns

int — index; -1 if missing

count

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

Purpose

Non-overlapping count of sub in s. Empty sub returns 1+s.len.

Parameters

s &string
source (borrowed)
sub string
substring to count

Returns

occurrence count

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 (borrowed; caller keeps it; type &string)
sep string
separator (string)
n int
count, length, or limit (int)

Returns

[]string — slice result

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 (borrowed; caller keeps it; type &string)
old string
old value / piece to replace (string)
new string
new value / replacement (string)

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 (borrowed; caller keeps it; type &string)
b &string
b (borrowed; caller keeps it; type &string)

Returns

bool — true or false

struct Cut

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

Purpose

Public struct `Cut`.

Parameters

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 (borrowed; caller keeps it; 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 (borrowed; caller keeps it; 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 (borrowed; caller keeps it; type &string)
suf string
suffix (string)

Returns

Cut — a value of this type

struct Builder

XuAPI
pub struct Builder {
    pub buf string
}

Purpose

Public struct `Builder`.

Parameters

buf string
buffer

builder

XuAPI
pub fn builder() Builder

Purpose

builder; returns Builder.

Parameters

none

Returns

Builder — a value of this type

(&mut Builder) write_string

XuAPI
pub fn (b &mut Builder) write_string(s &string) int

Purpose

Method on `&mut Builder`: write a string and return the byte count.

Parameters

b &mut Builder
receiver &mut Builder (exclusive borrow)
s &string
source string (borrowed; caller keeps it; type &string)

Returns

int — bytes written

(&mut Builder) grow

XuAPI
pub fn (b &mut Builder) grow(n int)

Purpose

Method on `&mut Builder`: ensure room for at least n more bytes.

Parameters

b &mut Builder
receiver &mut Builder (exclusive borrow)
n int
count, length, or limit (int)

(&mut Builder) write_view

XuAPI
pub fn (b &mut Builder) write_view(s &string, v ByteView) int

Purpose

Method on `&mut Builder`: write view.

Parameters

b &mut Builder
receiver &mut Builder (exclusive borrow)
s &string
source string (borrowed; caller keeps it; type &string)
v ByteView
value (ByteView)

Returns

int — a value of this type

(&mut Builder) write_int

XuAPI
pub fn (b &mut Builder) write_int(n int) int

Purpose

Method on `&mut Builder`: write int.

Parameters

b &mut Builder
receiver &mut Builder (exclusive borrow)
n int
count, length, or limit (int)

Returns

int — a value of this type

(&Builder) length

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

Purpose

Method on `&Builder`: return the current length.

Parameters

b &Builder
receiver &Builder (borrow)

Returns

int — a value of this type

(&Builder) text

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

Purpose

Method on `&Builder`: return the current text.

Parameters

b &Builder
receiver &Builder (borrow)

Returns

string — result string

(&mut Builder) reset

XuAPI
pub fn (b &mut Builder) reset()

Purpose

Method on `&mut Builder`: clear internal state so the value can be reused.

Parameters

b &mut Builder
receiver &mut Builder (exclusive borrow)

index_func

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

Purpose

IndexFunc callbacks receive runes; results are byte offsets. MapBytes deliberately keeps its byte callback and byte result contract. Returns -1 if not found.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

Returns

int — index; -1 if missing

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. Returns -1 if not found.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

Returns

int — index; -1 if missing

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 (borrowed; caller keeps it; type &string)
f fn(int) int
byte callback: argument is 0..255, return whether it matches

Returns

string — result string

struct ByteBuilder

XuAPI
pub struct ByteBuilder {
    pub buf []int
    pub len int
}

Purpose

growable byte buffer for hot concat paths (compiler / fmt).

Parameters

buf []int
buffer
len int
field (int)

new_byte_builder

XuAPI
pub fn new_byte_builder(cap int) ByteBuilder

Purpose

Construct byte builder.

Parameters

cap int
cap (int)

Returns

ByteBuilder — a value of this type

(&mut ByteBuilder) reserve

XuAPI
pub fn (sb &mut ByteBuilder) reserve(extra int)

Purpose

Call `reserve` on `&mut ByteBuilder`.

Parameters

sb &mut ByteBuilder
receiver &mut ByteBuilder (exclusive borrow)
extra int
extra (int)

(&mut ByteBuilder) write_byte

XuAPI
pub fn (sb &mut ByteBuilder) write_byte(c int)

Purpose

Method on `&mut ByteBuilder`: write one byte.

Parameters

sb &mut ByteBuilder
receiver &mut ByteBuilder (exclusive borrow)
c int
byte or character code (int)

(&mut ByteBuilder) write_str

XuAPI
pub fn (sb &mut ByteBuilder) write_str(s string)

Purpose

Method on `&mut ByteBuilder`: write a string.

Parameters

sb &mut ByteBuilder
receiver &mut ByteBuilder (exclusive borrow)
s string
source string (string)

(ByteBuilder) to_string

XuAPI
pub fn (sb ByteBuilder) to_string() string

Purpose

Method on `ByteBuilder`: convert to string.

Parameters

sb ByteBuilder
receiver ByteBuilder (value receiver)

Returns

string — result string

clone

XuAPI
pub fn clone(s &string) string

Purpose

strings Clone / IndexAny / SplitAfter / TrimFunc / ToValidUTF8 Builder.WriteByte / WriteRune. Cutsets operate on Unicode runes.

Parameters

s &string
source string (borrowed; caller keeps it; 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 (borrowed; caller keeps it; type &string)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

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. Returns -1 if not found.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
chars string
byte cutset (string)

Returns

int — index; -1 if missing

last_index_any

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

Purpose

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

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
chars string
byte cutset (string)

Returns

int — index; -1 if missing

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 (borrowed; caller keeps it; 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. Returns -1 if not found.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
r int
rune (Unicode code point) (int)

Returns

int — index; -1 if missing

contains_rune

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

Purpose

Report whether the rune occurs.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
r int
rune (Unicode code point) (int)

Returns

bool — true or false

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 (borrowed; caller keeps it; 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 (borrowed; caller keeps it; 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 (borrowed; caller keeps it; type &string)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

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 (borrowed; caller keeps it; type &string)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

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 (borrowed; caller keeps it; type &string)
f fn(int) bool
byte callback: argument is 0..255, return whether it matches

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 (borrowed; caller keeps it; type &string)
replacement string
replacement for invalid sequences (string)

Returns

string — result string

(&mut Builder) write_byte

XuAPI
pub fn (b &mut Builder) write_byte(c int) int

Purpose

Method on `&mut Builder`: write one byte.

Parameters

b &mut Builder
receiver &mut Builder (exclusive borrow)
c int
byte or character code (int)

Returns

int — bytes written

(&mut Builder) write_rune

XuAPI
pub fn (b &mut Builder) write_rune(r int) int

Purpose

Method on `&mut Builder`: write a rune as UTF-8.

Parameters

b &mut Builder
receiver &mut Builder (exclusive borrow)
r int
rune (Unicode code point) (int)

Returns

int — bytes written

(&Builder) cap

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

Purpose

Method on `&Builder`: return the capacity.

Parameters

b &Builder
receiver &Builder (borrow)

Returns

int — a value of this type

struct Replacer

XuAPI
pub struct Replacer {

}

Purpose

strings.Replacer. Pairs are old/new; earlier pair wins when several match at the same index (not longest-first). Empty old inserts between bytes and at both ends, same as genericReplacer. No WriteString (no io.Writer). Odd argument count throws.

Parameters

none

new_replacer

XuAPI
pub fn new_replacer(oldnew <-> string) Replacer

Purpose

Construct replacer. Throws on failure.

Parameters

oldnew <-> string
variadic string (seen inside the function as []string)

Returns

Replacer — a value of this type

(&Replacer) replace

XuAPI
pub fn (r &Replacer) replace(s0 &string) string

Purpose

Replace old with new in s. n==0 or empty old returns s unchanged; n<0 replaces all; n>0 replaces at most n times.

Parameters

r &Replacer
receiver &Replacer (borrow)
s0 &string
s0 (borrowed; caller keeps it; type &string)

Returns

a new string

struct Reader

XuAPI
pub struct Reader {

}

Purpose

strings.Reader. read_n / read_at return owning strings (no []byte). read_n is empty at EOF (no throw); read_byte / read_rune throw "EOF". Invalid UTF-8 in read_rune is U+FFFD + 1 byte ( DecodeRuneInString). seek whence: 0 start / 1 current / 2 end. No WriteTo.

Parameters

none

struct RuneRead

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

Purpose

Public struct `RuneRead`.

Parameters

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

Method on `&Reader`: return the size.

Parameters

r &Reader
receiver &Reader (borrow)

Returns

int — a value of this type

(&Reader) length

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

Purpose

Method on `&Reader`: return the current length.

Parameters

r &Reader
receiver &Reader (borrow)

Returns

int — a value of this type

(&mut Reader) reset

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

Purpose

Method on `&mut Reader`: clear internal state so the value can be reused.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)
s string
source string (string)

(&mut Reader) read_n

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

Purpose

Method on `&mut Reader`: read at most n bytes; may return shorter or empty at end.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)
n int
count, length, or limit (int)

Returns

string — result string

(&mut Reader) read_byte

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

Purpose

Method on `&mut Reader`: read one byte; throws on failure. Throws on failure.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)

Returns

int — a value of this type

(&mut Reader) unread_byte

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

Purpose

Method on `&mut Reader`: unread the last byte. Throws on failure.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)

Returns

int — a value of this type

(&mut Reader) read_rune

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

Purpose

Method on `&mut Reader`: read one UTF-8 rune. Throws on failure.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)

Returns

RuneRead — a value of this type

(&mut Reader) unread_rune

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

Purpose

Method on `&mut Reader`: unread the last rune. Throws on failure.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)

Returns

int — a value of this type

(&mut Reader) seek

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

Purpose

Method on `&mut Reader`: move the read position. whence 0/1/2 = absolute / relative / from end. Throws on failure.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)
offset int
offset (int)
whence int
seek base: 0 start / 1 current / 2 end (int)

Returns

int — a value of this type

(&mut Reader) read_at

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

Purpose

Method on `&mut Reader`: read at most n bytes starting at offset off. Throws on failure.

Parameters

r &mut Reader
receiver &mut Reader (exclusive borrow)
n int
count, length, or limit (int)
off int
offset (int)

Returns

string — result string

struct ByteView

XuAPI
pub struct ByteView {
    pub off int
    pub len int
}

Purpose

ByteView is a read-only window [off, off+len) into a borrowed string. Xu has no user-visible pointers, so the (ptr,len) pair is (`s`, view). Indexing past the window is loud OOB (same as `s[s.len]`).

Parameters

off int
offset
len int
field (int)

view_of

XuAPI
pub fn view_of(s &string) ByteView

Purpose

View of.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)

Returns

ByteView — a value of this type

view_slice

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

Purpose

View slice.

Parameters

s &string
source string (borrowed; caller keeps it; type &string)
off int
offset (int)
n int
count, length, or limit (int)

Returns

ByteView — a value of this type

(&ByteView) at

XuAPI
pub fn (v &ByteView) at(s &string, i int) int

Purpose

Call `at` on `&ByteView`.

Parameters

v &ByteView
receiver &ByteView (borrow)
s &string
source string (borrowed; caller keeps it; type &string)
i int
index or integer (int)

Returns

int — a value of this type

(&ByteView) equal

XuAPI
pub fn (v &ByteView) equal(s &string, t &string, w ByteView) bool

Purpose

Method on `&ByteView`: report whether the two values are equal.

Parameters

v &ByteView
receiver &ByteView (borrow)
s &string
source string (borrowed; caller keeps it; type &string)
t &string
t (borrowed; caller keeps it; type &string)
w ByteView
writer or width (ByteView)

Returns

bool — true or false

(&ByteView) compare

XuAPI
pub fn (v &ByteView) compare(s &string, t &string, w ByteView) int

Purpose

Method on `&ByteView`: lexicographic compare: -1, 0, or 1.

Parameters

v &ByteView
receiver &ByteView (borrow)
s &string
source string (borrowed; caller keeps it; type &string)
t &string
t (borrowed; caller keeps it; type &string)
w ByteView
writer or width (ByteView)

Returns

int — -1 if less, 0 if equal, 1 if greater

(&ByteView) index_byte

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

Purpose

Method on `&ByteView`: index of the first byte c; -1 if missing. Returns -1 if not found.

Parameters

v &ByteView
receiver &ByteView (borrow)
s &string
source string (borrowed; caller keeps it; type &string)
c int
byte or character code (int)

Returns

int — index; -1 if missing

(&ByteView) last_index_byte

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

Purpose

Method on `&ByteView`: index of the last byte c; -1 if missing. Returns -1 if not found.

Parameters

v &ByteView
receiver &ByteView (borrow)
s &string
source string (borrowed; caller keeps it; type &string)
c int
byte or character code (int)

Returns

int — index; -1 if missing

(&ByteView) has_prefix

XuAPI
pub fn (v &ByteView) has_prefix(s &string, pre &string) bool

Purpose

Whether s starts with pre.

Parameters

v &ByteView
receiver &ByteView (borrow)
s &string
source (borrowed)
pre &string
prefix

Returns

true if it does

(&ByteView) has_suffix

XuAPI
pub fn (v &ByteView) has_suffix(s &string, suf &string) bool

Purpose

Whether s ends with suf.

Parameters

v &ByteView
receiver &ByteView (borrow)
s &string
source (borrowed)
suf &string
suffix

Returns

true if it does

(&ByteView) index

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

Purpose

Index of `sub` relative to the window. Empty needle matches at 0. Returns -1 if not found.

Parameters

v &ByteView
receiver &ByteView (borrow)
s &string
source string (borrowed; caller keeps it; type &string)
sub &string
substring (borrowed; caller keeps it; type &string)

Returns

int — index; -1 if missing