XU XUv0.8.8
EN

API

#strings

import: #strings

counts: 52 函数, 33 方法, 7 类型, 0 常量, 0 方法集

字符串工具。只读函数吃 &string,调用方仍持有源。查找走 Horspool。含 Builder / Reader / Replacer。

index_of

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

用途

返回 sub 在 s 中首次出现的字节下标。空 sub 返回 0;未找到返回 -1。查找走 Horspool。

参数

s &string
被查找的字符串(借用,调用方仍持有)
sub string
要查找的子串

返回

首次出现的下标;未找到为 -1;空 sub 为 0

contains

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

用途

判断 s 是否包含子串 sub。空 sub 视为包含(下标 0)。

参数

s &string
被查找的字符串(借用,调用方仍持有)
sub string
要查找的子串

返回

包含则为 true,否则 false

trim_space

XuAPI
pub fn trim_space(s &string) string

用途

去掉两端 ASCII 空白,返回新串。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

repeat

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

用途

把内容重复 n 次;n<=0 得空串。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
n int
数量、长度或上限(int)

返回

string — 结果字符串

join

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

用途

用 sep 把 parts 拼成一个字符串。空切片得到空串。

参数

parts []string
要拼接的字符串切片
sep string
插在元素之间的分隔符

返回

拼接后的 string

split

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

用途

按 sep 切开 s。空 sep 不按字符拆,而是返回仅含整个 s 的单元素切片。

参数

s &string
源字符串(借用,调用方仍持有)
sep string
分隔符;空串则整段作为一项

返回

切开后的 []string(含末尾空段)

has_prefix

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

用途

判断 s 是否以 pre 开头。

参数

s &string
源字符串(借用)
pre string
前缀

返回

是则 true

has_suffix

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

用途

判断 s 是否以 suf 结尾。

参数

s &string
源字符串(借用)
suf string
后缀

返回

是则 true

ends_with

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

用途

判断 s 是否以 suf 结尾(与 has_suffix 同类)。

参数

s &string
源字符串(借用)
suf string
后缀

返回

是则 true

replace

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

用途

把 s 里的 old 换成 new。n==0 或 old 为空则原样返回;n<0 替换全部;n>0 最多替换 n 次。

参数

s &string
源字符串(借用)
old string
被替换的子串;空串则不替换
new string
替换成的子串
n int
最大替换次数;0 不改;负值表示全部

返回

替换后的新 string

fields

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

用途

按空白段切开,丢掉空白本身。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

[]string — 切片结果

fields_func

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

用途

按回调为真的字节切开。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
f fn(int) bool
字节回调:参数为字节值 0..255,返回是否命中

返回

[]string — 切片结果

to_lower

XuAPI
pub fn to_lower(s &string) string

用途

ASCII 字母转小写。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

to_upper

XuAPI
pub fn to_upper(s &string) string

用途

ASCII 字母转大写。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

trim_left

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

用途

去掉左端出现在 cutset 中的字节。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
cutset string
要剥除的字节集合(string)

返回

string — 结果字符串

trim_right

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

用途

去掉右端出现在 cutset 中的字节。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
cutset string
要剥除的字节集合(string)

返回

string — 结果字符串

trim

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

用途

去掉两端出现在 cutset 中的字节。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
cutset string
要剥除的字节集合(string)

返回

string — 结果字符串

trim_prefix

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

用途

若有前缀则去掉该前缀,否则原样返回。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
pre string
前缀(string)

返回

string — 结果字符串

trim_suffix

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

用途

若有后缀则去掉该后缀,否则原样返回。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
suf string
后缀(string)

返回

string — 结果字符串

compare

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

用途

字典序比较:小于 -1、相等 0、大于 1。

参数

a &string
左操作数(借用,调用方仍持有;类型 &string)
b &string
右操作数(借用,调用方仍持有;类型 &string)

返回

int — 小于 -1、相等 0、大于 1

index_byte

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

用途

返回字节 c 首次出现的下标;未找到为 -1。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
c int
字节或字符码(int)

返回

int — 下标;未找到为 -1

last_index

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

用途

返回最后一次出现的下标;未找到为 -1。未找到返回 -1。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
sub string
子串(string)

返回

int — 下标;未找到为 -1

last_index_byte

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

用途

返回字节 c 最后一次出现的下标;未找到为 -1。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
c int
字节或字符码(int)

返回

int — 下标;未找到为 -1

count

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

用途

统计 sub 在 s 中非重叠出现次数。空 sub 返回 1+s.len。

参数

s &string
源字符串(借用)
sub string
要计数的子串

返回

出现次数(int)

split_n

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

用途

按分隔符切开,最多 n 段。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
sep string
分隔符(string)
n int
数量、长度或上限(int)

返回

[]string — 切片结果

replace_all

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

用途

替换全部出现的子串。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
old string
旧值 / 被替换片段(string)
new string
新值 / 替换成的片段(string)

返回

string — 结果字符串

equal_fold

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

用途

ASCII 大小写不敏感比较。

参数

a &string
值(借用,调用方仍持有;类型 &string)
b &string
b(借用,调用方仍持有;类型 &string)

返回

bool — 是否成立

struct Cut

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

用途

公开结构体 `Cut`。

参数

before string
字段(string)
after string
字段(string)
found bool
字段(bool)

cut

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

用途

在首个 sep 处切成前后两段。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
sep string
分隔符(string)

返回

Cut — 该类型的值

cut_prefix

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

用途

若有前缀则切掉。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
pre string
前缀(string)

返回

Cut — 该类型的值

cut_suffix

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

用途

若有后缀则切掉。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
suf string
后缀(string)

返回

Cut — 该类型的值

struct Builder

XuAPI
pub struct Builder {
    pub buf string
}

用途

公开结构体 `Builder`。

参数

buf string
缓冲

builder

XuAPI
pub fn builder() Builder

用途

构建器。

参数

无

返回

Builder — 该类型的值

(&mut Builder) write_string

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

用途

`&mut Builder` 上的方法:写入字符串,返回写入的字节数。

参数

b &mut Builder
接收者 &mut Builder(可变借用)
s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

int — 写入的字节数

(&mut Builder) grow

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

用途

`&mut Builder` 上的方法:保证至少还能再写入 n 字节。

参数

b &mut Builder
接收者 &mut Builder(可变借用)
n int
数量、长度或上限(int)

(&mut Builder) write_view

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

用途

`&mut Builder` 上的方法:写入view。

参数

b &mut Builder
接收者 &mut Builder(可变借用)
s &string
源字符串(借用,调用方仍持有;类型 &string)
v ByteView
值(ByteView)

返回

int — 该类型的值

(&mut Builder) write_int

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

用途

`&mut Builder` 上的方法:写入int。

参数

b &mut Builder
接收者 &mut Builder(可变借用)
n int
数量、长度或上限(int)

返回

int — 该类型的值

(&Builder) length

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

用途

`&Builder` 上的方法:返回当前长度。

参数

b &Builder
接收者 &Builder(借用)

返回

int — 该类型的值

(&Builder) text

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

用途

`&Builder` 上的方法:返回当前文本。

参数

b &Builder
接收者 &Builder(借用)

返回

string — 结果字符串

(&mut Builder) reset

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

用途

`&mut Builder` 上的方法:清空内部状态,可再写入或读取。

参数

b &mut Builder
接收者 &mut Builder(可变借用)

index_func

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

用途

返回使回调为真的首个字节下标;未找到为 -1。未找到返回 -1。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
f fn(int) bool
字节回调:参数为字节值 0..255,返回是否命中

返回

int — 下标;未找到为 -1

last_index_func

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

用途

返回使回调为真的最后字节下标;未找到为 -1。未找到返回 -1。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
f fn(int) bool
字节回调:参数为字节值 0..255,返回是否命中

返回

int — 下标;未找到为 -1

map_bytes

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

用途

对每个字节调用 f,用返回值重建字符串。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
f fn(int) int
字节回调:参数为字节值 0..255,返回是否命中

返回

string — 结果字符串

struct ByteBuilder

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

用途

公开结构体 `ByteBuilder`。

参数

buf []int
缓冲
len int
字段(int)

new_byte_builder

XuAPI
pub fn new_byte_builder(cap int) ByteBuilder

用途

构造 byte builder。

参数

cap int
cap(int)

返回

ByteBuilder — 该类型的值

(&mut ByteBuilder) reserve

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

用途

`&mut ByteBuilder` 上的方法:预留。

参数

sb &mut ByteBuilder
接收者 &mut ByteBuilder(可变借用)
extra int
extra(int)

(&mut ByteBuilder) write_byte

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

用途

`&mut ByteBuilder` 上的方法:写入一个字节。

参数

sb &mut ByteBuilder
接收者 &mut ByteBuilder(可变借用)
c int
字节或字符码(int)

(&mut ByteBuilder) write_str

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

用途

`&mut ByteBuilder` 上的方法:写入字符串。

参数

sb &mut ByteBuilder
接收者 &mut ByteBuilder(可变借用)
s string
源字符串(string)

(ByteBuilder) to_string

XuAPI
pub fn (sb ByteBuilder) to_string() string

用途

`ByteBuilder` 上的方法:转成 string。

参数

sb ByteBuilder
接收者 ByteBuilder(值接收者)

返回

string — 结果字符串

clone

XuAPI
pub fn clone(s &string) string

用途

拷贝一份独立的 string。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

contains_func

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

用途

判断是否存在使回调为真的字节。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
f fn(int) bool
字节回调:参数为字节值 0..255,返回是否命中

返回

bool — 是否成立

index_any

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

用途

返回 cutset 中任一字节首次出现的下标;未找到为 -1。未找到返回 -1。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
chars string
字节集合(cutset)(string)

返回

int — 下标;未找到为 -1

last_index_any

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

用途

返回 cutset 中字节最后一次出现的下标;未找到为 -1。未找到返回 -1。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
chars string
字节集合(cutset)(string)

返回

int — 下标;未找到为 -1

contains_any

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

用途

判断是否包含 cutset 中任一字节。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
chars string
字节集合(cutset)(string)

返回

bool — 是否成立

index_rune

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

用途

返回 rune 首次出现的下标;未找到为 -1。未找到返回 -1。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
r int
rune(Unicode 码点)(int)

返回

int — 下标;未找到为 -1

contains_rune

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

用途

判断是否包含给定 rune。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
r int
rune(Unicode 码点)(int)

返回

bool — 是否成立

split_after

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

用途

按分隔符切开,分隔符留在各段末尾。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
sep string
分隔符(string)

返回

[]string — 切片结果

split_after_n

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

用途

按分隔符切开并保留分隔符,最多 n 段。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
sep string
分隔符(string)
n int
数量、长度或上限(int)

返回

[]string — 切片结果

trim_left_func

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

用途

按回调去掉左端字节。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
f fn(int) bool
字节回调:参数为字节值 0..255,返回是否命中

返回

string — 结果字符串

trim_right_func

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

用途

按回调去掉右端字节。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
f fn(int) bool
字节回调:参数为字节值 0..255,返回是否命中

返回

string — 结果字符串

trim_func

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

用途

按回调去掉两端字节。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
f fn(int) bool
字节回调:参数为字节值 0..255,返回是否命中

返回

string — 结果字符串

to_valid_utf8

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

用途

把非法 UTF-8 序列换成 replacement。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
replacement string
非法序列的替换串(string)

返回

string — 结果字符串

(&mut Builder) write_byte

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

用途

`&mut Builder` 上的方法:写入一个字节。

参数

b &mut Builder
接收者 &mut Builder(可变借用)
c int
字节或字符码(int)

返回

int — 写入的字节数

(&mut Builder) write_rune

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

用途

`&mut Builder` 上的方法:写入一个 rune 的 UTF-8 编码。

参数

b &mut Builder
接收者 &mut Builder(可变借用)
r int
rune(Unicode 码点)(int)

返回

int — 写入的字节数

(&Builder) cap

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

用途

`&Builder` 上的方法:返回容量。

参数

b &Builder
接收者 &Builder(借用)

返回

int — 该类型的值

struct Replacer

XuAPI
pub struct Replacer {

}

用途

公开结构体 `Replacer`。

参数

无

new_replacer

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

用途

构造 replacer。失败时 throw。

参数

oldnew <-> string
可变参数,类型 string,在函数体内是 []string

返回

Replacer — 该类型的值

(&Replacer) replace

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

用途

把 s 里的 old 换成 new。n==0 或 old 为空则原样返回;n<0 替换全部;n>0 最多替换 n 次。

参数

r &Replacer
接收者 &Replacer(借用)
s0 &string
s0(借用,调用方仍持有;类型 &string)

返回

替换后的新 string

struct Reader

XuAPI
pub struct Reader {

}

用途

公开结构体 `Reader`。

参数

无

struct RuneRead

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

用途

公开结构体 `RuneRead`。

参数

ch int
字符码
size int
字段(int)

new_reader

XuAPI
pub fn new_reader(s string) Reader

用途

构造 reader。

参数

s string
源字符串(string)

返回

Reader — 该类型的值

(&Reader) size

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

用途

`&Reader` 上的方法:返回尺寸。

参数

r &Reader
接收者 &Reader(借用)

返回

int — 该类型的值

(&Reader) length

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

用途

`&Reader` 上的方法:返回当前长度。

参数

r &Reader
接收者 &Reader(借用)

返回

int — 该类型的值

(&mut Reader) reset

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

用途

`&mut Reader` 上的方法:清空内部状态,可再写入或读取。

参数

r &mut Reader
接收者 &mut Reader(可变借用)
s string
源字符串(string)

(&mut Reader) read_n

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

用途

`&mut Reader` 上的方法:最多读 n 字节;到末尾可返回更短或空串。

参数

r &mut Reader
接收者 &mut Reader(可变借用)
n int
数量、长度或上限(int)

返回

string — 结果字符串

(&mut Reader) read_byte

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

用途

`&mut Reader` 上的方法:读一个字节;失败时 throw。

参数

r &mut Reader
接收者 &mut Reader(可变借用)

返回

int — 该类型的值

(&mut Reader) unread_byte

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

用途

`&mut Reader` 上的方法:把最近读出的一字节退回。失败时 throw。

参数

r &mut Reader
接收者 &mut Reader(可变借用)

返回

int — 该类型的值

(&mut Reader) read_rune

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

用途

`&mut Reader` 上的方法:读一个 UTF-8 rune。失败时 throw。

参数

r &mut Reader
接收者 &mut Reader(可变借用)

返回

RuneRead — 该类型的值

(&mut Reader) unread_rune

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

用途

`&mut Reader` 上的方法:把最近读出的 rune 退回。失败时 throw。

参数

r &mut Reader
接收者 &mut Reader(可变借用)

返回

int — 该类型的值

(&mut Reader) seek

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

用途

`&mut Reader` 上的方法:按 whence 把读位置移到 offset。whence 0/1/2 分别为绝对、相对、从末尾。失败时 throw。

参数

r &mut Reader
接收者 &mut Reader(可变借用)
offset int
偏移(int)
whence int
定位基准:0 起点 / 1 当前 / 2 末尾(int)

返回

int — 该类型的值

(&mut Reader) read_at

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

用途

`&mut Reader` 上的方法:从偏移 off 起最多读 n 字节。失败时 throw。

参数

r &mut Reader
接收者 &mut Reader(可变借用)
n int
数量、长度或上限(int)
off int
偏移(int)

返回

string — 结果字符串

struct ByteView

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

用途

公开结构体 `ByteView`。

参数

off int
偏移
len int
字段(int)

view_of

XuAPI
pub fn view_of(s &string) ByteView

用途

viewof。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)

返回

ByteView — 该类型的值

view_slice

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

用途

view切片。

参数

s &string
源字符串(借用,调用方仍持有;类型 &string)
off int
偏移(int)
n int
数量、长度或上限(int)

返回

ByteView — 该类型的值

(&ByteView) at

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

用途

在 `&ByteView` 上调用 `at`。

参数

v &ByteView
接收者 &ByteView(借用)
s &string
源字符串(借用,调用方仍持有;类型 &string)
i int
下标或整数(int)

返回

int — 该类型的值

(&ByteView) equal

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

用途

`&ByteView` 上的方法:判断两值是否相等。

参数

v &ByteView
接收者 &ByteView(借用)
s &string
源字符串(借用,调用方仍持有;类型 &string)
t &string
t(借用,调用方仍持有;类型 &string)
w ByteView
写入侧 / 宽度(ByteView)

返回

bool — 是否成立

(&ByteView) compare

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

用途

`&ByteView` 上的方法:字典序比较:小于 -1、相等 0、大于 1。

参数

v &ByteView
接收者 &ByteView(借用)
s &string
源字符串(借用,调用方仍持有;类型 &string)
t &string
t(借用,调用方仍持有;类型 &string)
w ByteView
写入侧 / 宽度(ByteView)

返回

int — 小于 -1、相等 0、大于 1

(&ByteView) index_byte

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

用途

`&ByteView` 上的方法:返回字节 c 首次出现的下标;未找到为 -1。未找到返回 -1。

参数

v &ByteView
接收者 &ByteView(借用)
s &string
源字符串(借用,调用方仍持有;类型 &string)
c int
字节或字符码(int)

返回

int — 下标;未找到为 -1

(&ByteView) last_index_byte

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

用途

`&ByteView` 上的方法:返回字节 c 最后一次出现的下标;未找到为 -1。未找到返回 -1。

参数

v &ByteView
接收者 &ByteView(借用)
s &string
源字符串(借用,调用方仍持有;类型 &string)
c int
字节或字符码(int)

返回

int — 下标;未找到为 -1

(&ByteView) has_prefix

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

用途

判断 s 是否以 pre 开头。

参数

v &ByteView
接收者 &ByteView(借用)
s &string
源字符串(借用)
pre &string
前缀

返回

是则 true

(&ByteView) has_suffix

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

用途

判断 s 是否以 suf 结尾。

参数

v &ByteView
接收者 &ByteView(借用)
s &string
源字符串(借用)
suf &string
后缀

返回

是则 true

(&ByteView) index

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

用途

`&ByteView` 上的方法:返回首次出现的下标;未找到为 -1。未找到返回 -1。

参数

v &ByteView
接收者 &ByteView(借用)
s &string
源字符串(借用,调用方仍持有;类型 &string)
sub &string
子串(借用,调用方仍持有;类型 &string)

返回

int — 下标;未找到为 -1