struct Buffer
pub struct Buffer {
pub data string
pub off int
}用途
公开结构体 `Buffer`。
参数
datastring- 数据
offint- 偏移
API
#bytes字节串工具,形状与 strings 对称。Buffer 可读写。查找同样走 Horspool。
struct Bufferpub struct Buffer {
pub data string
pub off int
}公开结构体 `Buffer`。
data stringoff intbufferpub fn buffer() Buffer缓冲。
无
Buffer — 该类型的值
buffer_frompub fn buffer_from(s string) Buffer缓冲从。
s stringBuffer — 该类型的值
(&mut Buffer) writepub fn (b &mut Buffer) write(data &string) int`&mut Buffer` 上的方法:写入数据,返回写入的字节数。
b &mut Bufferdata &stringint — 写入的字节数
(&mut Buffer) write_bytepub fn (b &mut Buffer) write_byte(c int) int`&mut Buffer` 上的方法:写入一个字节。失败时 throw。
b &mut Bufferc intint — 写入的字节数
(&mut Buffer) read_npub fn (b &mut Buffer) read_n(n int) string`&mut Buffer` 上的方法:最多读 n 字节;到末尾可返回更短或空串。
b &mut Buffern intstring — 结果字符串
(&Buffer) lengthpub fn (b &Buffer) length() int`&Buffer` 上的方法:返回当前长度。
b &Bufferint — 该类型的值
(&Buffer) textpub fn (b &Buffer) text() string`&Buffer` 上的方法:返回当前文本。
b &Bufferstring — 结果字符串
(&Buffer) bytespub fn (b &Buffer) bytes() string`&Buffer` 上的方法:返回已缓冲的字节串。
b &Bufferstring — 结果字符串
(&mut Buffer) resetpub fn (b &mut Buffer) reset()`&mut Buffer` 上的方法:清空内部状态,可再写入或读取。
b &mut Buffer(&mut Buffer) truncatepub fn (b &mut Buffer) truncate(n int) int`&mut Buffer` 上的方法:截断。失败时 throw。
b &mut Buffern intint — 该类型的值
view_ofpub fn view_of(s &string) strings.ByteViewviewof。
s &stringstrings.ByteView — 该类型的值
view_slicepub fn view_slice(s &string, off int, n int) strings.ByteViewview切片。
s &stringoff intn intstrings.ByteView — 该类型的值
equalpub fn equal(a &string, b &string) bool判断两值是否相等。
a &stringb &stringbool — 是否成立
comparepub fn compare(a &string, b &string) int字典序比较:小于 -1、相等 0、大于 1。
a &stringb &stringint — 小于 -1、相等 0、大于 1
has_prefixpub fn has_prefix(s &string, prefix string) bool判断是否具有给定前缀。
s &stringprefix stringbool — 是否成立
has_suffixpub fn has_suffix(s &string, suffix string) bool判断是否具有给定后缀。
s &stringsuffix stringbool — 是否成立
index_bytepub fn index_byte(s &string, c int) int返回字节 c 首次出现的下标;未找到为 -1。
s &stringc intint — 下标;未找到为 -1
last_index_bytepub fn last_index_byte(s &string, c int) int返回字节 c 最后一次出现的下标;未找到为 -1。
s &stringc intint — 下标;未找到为 -1
last_indexpub fn last_index(s &string, sub string) int返回最后一次出现的下标;未找到为 -1。
s &stringsub stringint — 下标;未找到为 -1
countpub fn count(s &string, sub string) int统计非重叠出现次数。
s &stringsub stringint — 该类型的值
replacepub fn replace(s &string, old string, new string, n int) string替换子串,次数由 n 限制。
s &stringold stringnew stringn intstring — 结果字符串
replace_allpub fn replace_all(s &string, old string, new string) string替换全部出现的子串。
s &stringold stringnew stringstring — 结果字符串
containspub fn contains(s &string, sub string) bool判断是否包含给定片段。
s &stringsub stringbool — 是否成立
indexpub fn index(s &string, sub string) int返回首次出现的下标;未找到为 -1。
s &stringsub stringint — 下标;未找到为 -1
trim_leftpub fn trim_left(s &string, cutset string) string去掉左端出现在 cutset 中的字节。
s &stringcutset stringstring — 结果字符串
trim_rightpub fn trim_right(s &string, cutset string) string去掉右端出现在 cutset 中的字节。
s &stringcutset stringstring — 结果字符串
trimpub fn trim(s &string, cutset string) string去掉两端出现在 cutset 中的字节。
s &stringcutset stringstring — 结果字符串
trim_spacepub fn trim_space(s &string) string去掉两端 ASCII 空白,返回新串。
s &stringstring — 结果字符串
trim_prefixpub fn trim_prefix(s &string, pre string) string若有前缀则去掉该前缀,否则原样返回。
s &stringpre stringstring — 结果字符串
trim_suffixpub fn trim_suffix(s &string, suf string) string若有后缀则去掉该后缀,否则原样返回。
s &stringsuf stringstring — 结果字符串
joinpub fn join(parts []string, sep string) string用分隔符拼接各段。
parts []stringsep stringstring — 结果字符串
splitpub fn split(s &string, sep string) []string按分隔符切开。
s &stringsep string[]string — 切片结果
fieldspub fn fields(s &string) []string按空白段切开,丢掉空白本身。
s &string[]string — 切片结果
index_funcpub fn index_func(s &string, f fn(int) bool) int返回使回调为真的首个字节下标;未找到为 -1。
s &stringf fn(int) boolint — 下标;未找到为 -1
last_index_funcpub fn last_index_func(s &string, f fn(int) bool) int返回使回调为真的最后字节下标;未找到为 -1。
s &stringf fn(int) boolint — 下标;未找到为 -1
map_bytespub fn map_bytes(s &string, f fn(int) int) string对每个字节调用 f,用返回值重建字符串。
s &stringf fn(int) intstring — 结果字符串
fields_funcpub fn fields_func(s &string, f fn(int) bool) []string按回调为真的字节切开。
s &stringf fn(int) bool[]string — 切片结果
clonepub fn clone(s &string) string拷贝一份独立的 string。
s &stringstring — 结果字符串
contains_funcpub fn contains_func(s &string, f fn(int) bool) bool判断是否存在使回调为真的字节。
s &stringf fn(int) boolbool — 是否成立
index_anypub fn index_any(s &string, chars string) int返回 cutset 中任一字节首次出现的下标;未找到为 -1。
s &stringchars stringint — 下标;未找到为 -1
last_index_anypub fn last_index_any(s &string, chars string) int返回 cutset 中字节最后一次出现的下标;未找到为 -1。
s &stringchars stringint — 下标;未找到为 -1
contains_anypub fn contains_any(s &string, chars string) bool判断是否包含 cutset 中任一字节。
s &stringchars stringbool — 是否成立
index_runepub fn index_rune(s &string, r int) int返回 rune 首次出现的下标;未找到为 -1。
s &stringr intint — 下标;未找到为 -1
contains_runepub fn contains_rune(s &string, r int) bool判断是否包含给定 rune。
s &stringr intbool — 是否成立
split_npub fn split_n(s &string, sep string, n int) []string按分隔符切开,最多 n 段。
s &stringsep stringn int[]string — 切片结果
split_afterpub fn split_after(s &string, sep string) []string按分隔符切开,分隔符留在各段末尾。
s &stringsep string[]string — 切片结果
split_after_npub fn split_after_n(s &string, sep string, n int) []string按分隔符切开并保留分隔符,最多 n 段。
s &stringsep stringn int[]string — 切片结果
trim_left_funcpub fn trim_left_func(s &string, f fn(int) bool) string按回调去掉左端字节。
s &stringf fn(int) boolstring — 结果字符串
trim_right_funcpub fn trim_right_func(s &string, f fn(int) bool) string按回调去掉右端字节。
s &stringf fn(int) boolstring — 结果字符串
trim_funcpub fn trim_func(s &string, f fn(int) bool) string按回调去掉两端字节。
s &stringf fn(int) boolstring — 结果字符串
to_valid_utf8pub fn to_valid_utf8(s &string, replacement string) string把非法 UTF-8 序列换成 replacement。
s &stringreplacement stringstring — 结果字符串
repeatpub fn repeat(s &string, n int) string把内容重复 n 次;n<=0 得空串。
s &stringn intstring — 结果字符串
equal_foldpub fn equal_fold(a &string, b &string) boolASCII 大小写不敏感比较。
a &stringb &stringbool — 是否成立
to_lowerpub fn to_lower(s &string) stringASCII 字母转小写。
s &stringstring — 结果字符串
to_upperpub fn to_upper(s &string) stringASCII 字母转大写。
s &stringstring — 结果字符串
(&mut Buffer) growpub fn (b &mut Buffer) grow(n int)`&mut Buffer` 上的方法:保证至少还能再写入 n 字节。
b &mut Buffern int(&mut Buffer) write_stringpub fn (b &mut Buffer) write_string(s &string) int`&mut Buffer` 上的方法:写入字符串,返回写入的字节数。
b &mut Buffers &stringint — 写入的字节数
(&mut Buffer) write_runepub fn (b &mut Buffer) write_rune(r int) int`&mut Buffer` 上的方法:写入一个 rune 的 UTF-8 编码。失败时 throw。
b &mut Bufferr intint — 写入的字节数
(&mut Buffer) read_bytepub fn (b &mut Buffer) read_byte() int`&mut Buffer` 上的方法:读一个字节;失败时 throw。
b &mut Bufferint — 该类型的值
(&mut Buffer) unread_bytepub fn (b &mut Buffer) unread_byte() int`&mut Buffer` 上的方法:把最近读出的一字节退回。失败时 throw。
b &mut Bufferint — 该类型的值
(&mut Buffer) read_runepub fn (b &mut Buffer) read_rune() RuneRead`&mut Buffer` 上的方法:读一个 UTF-8 rune。失败时 throw。
b &mut BufferRuneRead — 该类型的值
(&mut Buffer) unread_runepub fn (b &mut Buffer) unread_rune() int`&mut Buffer` 上的方法:把最近读出的 rune 退回。失败时 throw。
b &mut Bufferint — 该类型的值
(&Buffer) cappub fn (b &Buffer) cap() int`&Buffer` 上的方法:返回容量。
b &Bufferint — 该类型的值
(&mut Buffer) nextpub fn (b &mut Buffer) next(n int) string`&mut Buffer` 上的方法:取出下一项;没有则按本类型约定结束。
b &mut Buffern intstring — 结果字符串
struct Cutpub struct Cut {
pub before string
pub after string
pub found bool
}公开结构体 `Cut`。
before stringafter stringfound boolcutpub fn cut(s &string, sep string) Cut在首个 sep 处切成前后两段。
s &stringsep stringCut — 该类型的值
cut_prefixpub fn cut_prefix(s &string, pre string) Cut若有前缀则切掉。
s &stringpre stringCut — 该类型的值
cut_suffixpub fn cut_suffix(s &string, suf string) Cut若有后缀则切掉。
s &stringsuf stringCut — 该类型的值
(&mut Buffer) read_bytespub fn (b &mut Buffer) read_bytes(delim int) string`&mut Buffer` 上的方法:读到 delim(含 delim)。
b &mut Bufferdelim intstring — 结果字符串
(&mut Reader) read_resultpub fn (r &mut Reader) read_result(n int) io.ReadResult`&mut Reader` 上的方法:读取结果。
r &mut Readern intio.ReadResult — 该类型的值
(&mut Buffer) read_resultpub fn (b &mut Buffer) read_result(n int) io.ReadResult`&mut Buffer` 上的方法:读取结果。
b &mut Buffern intio.ReadResult — 该类型的值
(&mut Buffer) write_resultpub fn (b &mut Buffer) write_result(data string) io.WriteResult`&mut Buffer` 上的方法:写入结果。
b &mut Bufferdata stringio.WriteResult — 该类型的值
struct Readerpub struct Reader {
}公开结构体 `Reader`。
无
struct RuneReadpub struct RuneRead {
pub ch int
pub size int
}公开结构体 `RuneRead`。
ch intsize intnew_readerpub fn new_reader(s string) Reader构造 reader。
s stringReader — 该类型的值
(&Reader) sizepub fn (r &Reader) size() int`&Reader` 上的方法:返回尺寸。
r &Readerint — 该类型的值
(&Reader) lengthpub fn (r &Reader) length() int`&Reader` 上的方法:返回当前长度。
r &Readerint — 该类型的值
(&mut Reader) resetpub fn (r &mut Reader) reset(s string)`&mut Reader` 上的方法:清空内部状态,可再写入或读取。
r &mut Readers string(&mut Reader) read_npub fn (r &mut Reader) read_n(n int) string`&mut Reader` 上的方法:最多读 n 字节;到末尾可返回更短或空串。
r &mut Readern intstring — 结果字符串
(&mut Reader) read_bytepub fn (r &mut Reader) read_byte() int`&mut Reader` 上的方法:读一个字节;失败时 throw。
r &mut Readerint — 该类型的值
(&mut Reader) unread_bytepub fn (r &mut Reader) unread_byte() int`&mut Reader` 上的方法:把最近读出的一字节退回。失败时 throw。
r &mut Readerint — 该类型的值
(&mut Reader) read_runepub fn (r &mut Reader) read_rune() RuneRead`&mut Reader` 上的方法:读一个 UTF-8 rune。失败时 throw。
r &mut ReaderRuneRead — 该类型的值
(&mut Reader) unread_runepub fn (r &mut Reader) unread_rune() int`&mut Reader` 上的方法:把最近读出的 rune 退回。失败时 throw。
r &mut Readerint — 该类型的值
(&mut Reader) seekpub fn (r &mut Reader) seek(offset int, whence int) int`&mut Reader` 上的方法:按 whence 把读位置移到 offset。whence 0/1/2 分别为绝对、相对、从末尾。失败时 throw。
r &mut Readeroffset intwhence intint — 该类型的值
(&mut Reader) read_atpub fn (r &mut Reader) read_at(n int, off int) string`&mut Reader` 上的方法:从偏移 off 起最多读 n 字节。失败时 throw。
r &mut Readern intoff intstring — 结果字符串