API
#regexp
Xu 0.8.8 API
import: #regexp
counts: 2 函数, 14 方法, 4 类型, 0 常量, 0 方法集
正则子集:compile/match/find/replace;有界回溯。
struct Regexp
pub struct Regexp {
pub nodes []Node
pub root int
pub class_data string
pub steps_max int
pub num_caps int
}
用途
公开结构体 `Regexp`。
参数
nodes []Node- 字段([]Node)
root int- 字段(int)
class_data string- 字段(string)
steps_max int- 字段(int)
num_caps int- 字段(int)
quote_meta
pub fn quote_meta(s &string) string
用途
加引号meta。
参数
s &string- 源字符串(借用,调用方仍持有;类型 &string)
返回
string — 结果字符串
compile
pub fn compile(expr string) Regexp
用途
compile,返回 Regexp。失败时 throw。
参数
expr string- expr(string)
返回
Regexp — 该类型的值
(Regexp) num_subexp
pub fn (re Regexp) num_subexp() int
用途
`Regexp` 上的方法:分子subexp。
参数
re Regexp- 接收者 Regexp(值接收者)
返回
int — 该类型的值
(Regexp) find_submatch
pub fn (re Regexp) find_submatch(s &string) []string
用途
`Regexp` 上的方法:findsubmatch。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
返回
[]string — 切片结果
struct Submatch
pub struct Submatch {
pub start int
pub end int
pub parts []string
}
用途
公开结构体 `Submatch`。
参数
start int- 字段(int)
end int- 字段(int)
parts []string- 各段
(Regexp) find_all_submatch
pub fn (re Regexp) find_all_submatch(s &string, n int) [][]string
用途
`Regexp` 上的方法:findallsubmatch。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
n int- 数量、长度或上限(int)
返回
[][]string — 切片结果
(Regexp) expand
pub fn (re Regexp) expand(s &string, repl &string) string
用途
在 `Regexp` 上调用 `expand`。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
repl &string- repl(借用,调用方仍持有;类型 &string)
返回
string — 结果字符串
struct LiteralPrefix
pub struct LiteralPrefix {
pub prefix string
pub complete bool
}
用途
公开结构体 `LiteralPrefix`。
参数
prefix string- 前缀
complete bool- 字段(bool)
(Regexp) literal_prefix
pub fn (re Regexp) literal_prefix() LiteralPrefix
用途
`Regexp` 上的方法:literalprefix。
参数
re Regexp- 接收者 Regexp(值接收者)
返回
LiteralPrefix — 该类型的值
(Regexp) match_string
pub fn (re Regexp) match_string(s &string) bool
用途
`Regexp` 上的方法:match字符串。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
返回
bool — 是否成立
(Regexp) find
pub fn (re Regexp) find(s &string) string
用途
在 `Regexp` 上调用 `find`。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
返回
string — 结果字符串
struct Index
pub struct Index {
pub start int
pub end int
}
用途
公开结构体 `Index`。
参数
start int- 字段(int)
end int- 字段(int)
(Regexp) find_index
pub fn (re Regexp) find_index(s &string) Index
用途
`Regexp` 上的方法:find下标。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
返回
Index — 该类型的值
(Regexp) find_all_index
pub fn (re Regexp) find_all_index(s &string, n int) []Index
用途
`Regexp` 上的方法:findall下标。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
n int- 数量、长度或上限(int)
返回
[]Index — 切片结果
(Regexp) find_all
pub fn (re Regexp) find_all(s &string, n int) []string
用途
`Regexp` 上的方法:findall。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
n int- 数量、长度或上限(int)
返回
[]string — 切片结果
(Regexp) split
pub fn (re Regexp) split(s &string, n int) []string
用途
`Regexp` 上的方法:按分隔符切开。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
n int- 数量、长度或上限(int)
返回
[]string — 切片结果
(Regexp) find_submatch_index
pub fn (re Regexp) find_submatch_index(s &string) []Index
用途
`Regexp` 上的方法:findsubmatch下标。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
返回
[]Index — 切片结果
(Regexp) replace_all_literal
pub fn (re Regexp) replace_all_literal(s &string, repl &string) string
用途
`Regexp` 上的方法:替换allliteral。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
repl &string- repl(借用,调用方仍持有;类型 &string)
返回
string — 结果字符串
(Regexp) replace_all
pub fn (re Regexp) replace_all(s &string, repl &string) string
用途
`Regexp` 上的方法:替换全部出现的子串。
参数
re Regexp- 接收者 Regexp(值接收者)
s &string- 源字符串(借用,调用方仍持有;类型 &string)
repl &string- repl(借用,调用方仍持有;类型 &string)
返回
string — 结果字符串