XU XUv0.16.0

#encoding/xun

导入方式: #encoding/xun

公开 API: 4 函数, 36 方法, 2 类型, 5 常量, 0 方法集

0.11.4 解析与序列化

带类型的块列表继承其标量类型,逐项验证,并在序列化时保留容器和元素标签。可安全表示的同类型非字符串列表可使用紧凑输出;字符串列表保留块形式。序列化拼写可能变化,请更新文本快照;若拼写不是契约的一部分,可比较解析树。旧的非空 !s[...] 标量输入仍被接受。

根以下容器的嵌套受 MAX_DEPTH(64)限制,包含行内、空容器和带类型容器。duration 校验拒绝格式错误或缺少单位的输入,并持续推进解析位置。多行解析将结构缩进与正文空白分别处理。

const KIND_DICT

XuAPI
pub const KIND_DICT = 0

用途

常量 KIND_DICT,定义了相关的协议或算法配置参数。

const KIND_LIST

XuAPI
pub const KIND_LIST = 1

用途

常量 KIND_LIST,定义了相关的协议或算法配置参数。

const KIND_SCALAR

XuAPI
pub const KIND_SCALAR = 2

用途

常量 KIND_SCALAR,定义了相关的协议或算法配置参数。

const MAX_BYTES

XuAPI
pub const MAX_BYTES = 1048576

用途

常量 MAX_BYTES,定义了相关的协议或算法配置参数。

const MAX_DEPTH

XuAPI
pub const MAX_DEPTH = 64

用途

常量 MAX_DEPTH,定义了相关的协议或算法配置参数。

struct Span

XuAPI
pub struct Span {
    pub lo int
    pub hi int
}

用途

承载 lo、hi 等属性的结构体。

公开字段

lo int
字段(int)
hi int
字段(int)

struct Doc

XuAPI
pub struct Doc {
    pub kinds []int
    pub tag_lo []int
    pub tag_hi []int
    pub text_lo []int
    pub text_hi []int
    pub key_lo []int
    pub key_hi []int
    pub key_hashes []int
    pub firsts []int
    pub nexts []int
    pub lasts []int
    pub buf string
    pub root_idx int
    pub err string
    pub line int
    pub line_starts []int
    pub line_ends []int
    pub i int
    pub tok_kind int
    pub tok_no int
    pub tok_klo int
    pub tok_khi int
    pub tok_khash int
    pub tok_vlo int
    pub tok_vhi int
}

用途

承载 kinds、tag_lo、tag_hi、text_lo、text_hi 等属性的结构体。

公开字段

kinds []int
字段([]int)
tag_lo []int
字段([]int)
tag_hi []int
字段([]int)
text_lo []int
字段([]int)
text_hi []int
字段([]int)
key_lo []int
字段([]int)
key_hi []int
字段([]int)
key_hashes []int
字段([]int)
firsts []int
字段([]int)
nexts []int
字段([]int)
lasts []int
字段([]int)
buf string
缓冲
root_idx int
字段(int)
err string
错误
line int
字段(int)
line_starts []int
字段([]int)
line_ends []int
字段([]int)
i int
下标或整数
tok_kind int
字段(int)
tok_no int
字段(int)
tok_klo int
字段(int)
tok_khi int
字段(int)
tok_khash int
字段(int)
tok_vlo int
字段(int)
tok_vhi int
字段(int)

new_doc

XuAPI
pub fn new_doc() Doc

用途

构造 doc。

参数

无需传入参数。

返回值

Doc — 该类型的值

(Doc) ok

XuAPI
pub fn (d Doc) ok() bool

用途

在 Doc 上执行 ok 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。

返回值

bool — 是否成立

(Doc) error

XuAPI
pub fn (d Doc) error() string

用途

Doc 上的操作:错误。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。

返回值

string — 结果字符串

(Doc) error_line

XuAPI
pub fn (d Doc) error_line() int

用途

Doc 上的操作:执行 error line 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。

返回值

int — 该类型的值

(Doc) root

XuAPI
pub fn (d Doc) root() int

用途

在 Doc 上执行 root 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。

返回值

int — 该类型的值

(Doc) kind

XuAPI
pub fn (d Doc) kind(n int) int

用途

在 Doc 上执行 kind 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

int — 该类型的值

(Doc) is_dict

XuAPI
pub fn (d Doc) is_dict(n int) bool

用途

Doc 上的操作:判断是否 dict。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

bool — 是否成立

(Doc) is_list

XuAPI
pub fn (d Doc) is_list(n int) bool

用途

Doc 上的操作:判断是否 list。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

bool — 是否成立

(Doc) is_scalar

XuAPI
pub fn (d Doc) is_scalar(n int) bool

用途

Doc 上的操作:判断是否 scalar。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

bool — 是否成立

(Doc) tag

XuAPI
pub fn (d Doc) tag(n int) string

用途

Doc 上的操作:标签。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

string — 结果字符串

(Doc) text

XuAPI
pub fn (d Doc) text(n int) string

用途

Doc 上的操作:返回当前文本。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

string — 结果字符串

(Doc) key

XuAPI
pub fn (d Doc) key(n int) string

用途

Doc 上的操作:键。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

string — 结果字符串

(Doc) count

XuAPI
pub fn (d Doc) count(n int) int

用途

Doc 上的操作:统计非重叠出现次数。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

int — 该类型的值

(Doc) at

XuAPI
pub fn (d Doc) at(n int, i int) int

用途

在 Doc 上执行 at 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)
i int
下标或整数(int)

返回值

int — 该类型的值

(Doc) get

XuAPI
pub fn (d Doc) get(n int, key string) int

用途

在 Doc 上执行 get 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)
key string
键(string)

返回值

int — 该类型的值

(Doc) as_str

XuAPI
pub fn (d Doc) as_str(n int) string

用途

Doc 上的操作:执行 as str 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

string — 结果字符串

(Doc) as_int

XuAPI
pub fn (d Doc) as_int(n int) int

用途

Doc 上的操作:执行 as int 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

int — 该类型的值

(Doc) as_f64

XuAPI
pub fn (d Doc) as_f64(n int) f64

用途

Doc 上的操作:执行 as f64 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

f64 — 该类型的值

(Doc) as_bool

XuAPI
pub fn (d Doc) as_bool(n int) bool

用途

Doc 上的操作:执行 as bool 操作。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。
n int
数量、长度或上限(int)

返回值

bool — 是否成立

($&Doc) set_root

XuAPI
pub fn (d $&Doc) set_root(r int)

用途

$&Doc 上的操作:设置 root。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
r int
rune(Unicode 码点)(int)

返回值

不返回值。

($&Doc) new_node

XuAPI
pub fn (d $&Doc) new_node(kind int, tag string, text string, key string) int

用途

$&Doc 上的操作:构造 node。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
kind int
类型标签(int)
tag string
tag(string)
text string
文本(string)
key string
键(string)

返回值

int — 该类型的值

($&Doc) attach

XuAPI
pub fn (d $&Doc) attach(parent int, child int)

用途

在 $&Doc 上执行 attach 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
child int
child(int)

返回值

不返回值。

($&Doc) add_dict

XuAPI
pub fn (d $&Doc) add_dict(parent int, key string) int

用途

$&Doc 上的操作:执行 add dict 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
key string
键(string)

返回值

int — 该类型的值

($&Doc) add_list

XuAPI
pub fn (d $&Doc) add_list(parent int, key string) int

用途

$&Doc 上的操作:执行 add list 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
key string
键(string)

返回值

int — 该类型的值

($&Doc) add_scalar

XuAPI
pub fn (d $&Doc) add_scalar(parent int, key string, tag string, text string) int

用途

$&Doc 上的操作:执行 add scalar 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
key string
键(string)
tag string
tag(string)
text string
文本(string)

返回值

int — 该类型的值

($&Doc) add_str

XuAPI
pub fn (d $&Doc) add_str(parent int, key string, val string) int

用途

$&Doc 上的操作:执行 add str 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
key string
键(string)
val string
值(string)

返回值

int — 该类型的值

($&Doc) add_int

XuAPI
pub fn (d $&Doc) add_int(parent int, key string, val int) int

用途

$&Doc 上的操作:执行 add int 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
key string
键(string)
val int
值(int)

返回值

int — 该类型的值

($&Doc) add_f64

XuAPI
pub fn (d $&Doc) add_f64(parent int, key string, val f64) int

用途

$&Doc 上的操作:增加f64。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
key string
键(string)
val f64
值(f64)

返回值

int — 该类型的值

($&Doc) add_bool

XuAPI
pub fn (d $&Doc) add_bool(parent int, key string, val bool) int

用途

$&Doc 上的操作:执行 add bool 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
key string
键(string)
val bool
值(bool)

返回值

int — 该类型的值

($&Doc) push_dict

XuAPI
pub fn (d $&Doc) push_dict(parent int) int

用途

$&Doc 上的操作:执行 push dict 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)

返回值

int — 该类型的值

($&Doc) push_list

XuAPI
pub fn (d $&Doc) push_list(parent int) int

用途

$&Doc 上的操作:执行 push list 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)

返回值

int — 该类型的值

($&Doc) push_scalar

XuAPI
pub fn (d $&Doc) push_scalar(parent int, tag string, text string) int

用途

$&Doc 上的操作:执行 push scalar 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
tag string
tag(string)
text string
文本(string)

返回值

int — 该类型的值

($&Doc) push_str

XuAPI
pub fn (d $&Doc) push_str(parent int, val string) int

用途

$&Doc 上的操作:执行 push str 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
val string
值(string)

返回值

int — 该类型的值

($&Doc) push_int

XuAPI
pub fn (d $&Doc) push_int(parent int, val int) int

用途

$&Doc 上的操作:执行 push int 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
val int
值(int)

返回值

int — 该类型的值

($&Doc) push_f64

XuAPI
pub fn (d $&Doc) push_f64(parent int, val f64) int

用途

$&Doc 上的操作:压入f64。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
val f64
值(f64)

返回值

int — 该类型的值

($&Doc) push_bool

XuAPI
pub fn (d $&Doc) push_bool(parent int, val bool) int

用途

$&Doc 上的操作:执行 push bool 操作。

参数

d $&Doc
本次调用使用的 Doc 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
parent int
parent(int)
val bool
值(bool)

返回值

int — 该类型的值

parse

XuAPI
pub fn parse(src &string) Doc

用途

解析输入。

参数

src &string
源数据(只读借用,调用方仍持有原值;类型 &string)

返回值

Doc — 该类型的值

decode

XuAPI
pub fn decode(src &string) Doc

用途

从编码数据中还原原始数据。

参数

src &string
源数据(只读借用,调用方仍持有原值;类型 &string)

返回值

Doc — 该类型的值

encode

XuAPI
pub fn encode(d &Doc) string

用途

执行数据编码并返回结果。

参数

d &Doc
d(只读借用,调用方仍持有原值;类型 &Doc)

返回值

string — 结果字符串

(Doc) to_xun

XuAPI
pub fn (d Doc) to_xun() string

用途

Doc 上的操作:转换为 xun。

参数

d Doc
本次调用使用的 Doc 实例;按值接收。

返回值

string — 结果字符串