XU XUv0.8.8
中文

API

#encoding/json

import: #encoding/json

counts: 8 fns, 27 methods, 1 types, 0 consts, 0 ifaces

Strict JSON; parse yields a pooled Doc. valid/compact/indent/quote.

struct Doc

XuAPI
pub struct Doc {
    pub kinds []int
    pub texts []string
    pub keys []string
    pub firsts []int
    pub nexts []int
    pub lasts []int
    pub root_idx int
    pub err string
    pub line int
    pub raw string
    pub i int
}

Purpose

Public struct `Doc`.

Parameters

kinds []int
field ([]int)
texts []string
field ([]string)
keys []string
field ([]string)
firsts []int
field ([]int)
nexts []int
field ([]int)
lasts []int
field ([]int)
root_idx int
field (int)
err string
error
line int
field (int)
raw string
Parse state (kept here: arrays cannot move between structs).
i int
index or integer

(Doc) ok

XuAPI
pub fn (d Doc) ok() bool

Purpose

===== public API =====

Parameters

d Doc
receiver Doc (value receiver)

Returns

bool — true or false

(Doc) error

XuAPI
pub fn (d Doc) error() string

Purpose

Call `error` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)

Returns

string — result string

(Doc) error_line

XuAPI
pub fn (d Doc) error_line() int

Purpose

Method on `Doc`: error line.

Parameters

d Doc
receiver Doc (value receiver)

Returns

int — a value of this type

(Doc) root

XuAPI
pub fn (d Doc) root() int

Purpose

Call `root` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)

Returns

int — a value of this type

(Doc) kind

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

Purpose

Call `kind` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) is_dict

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

Purpose

Method on `Doc`: whether it is dict.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) is_list

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

Purpose

Method on `Doc`: whether it is list.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) is_string

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

Purpose

Method on `Doc`: whether it is string.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) is_number

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

Purpose

Method on `Doc`: whether it is number.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) is_bool

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

Purpose

Method on `Doc`: whether it is bool.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) as_bool

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

Purpose

Method on `Doc`: as bool. Throws on failure.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) as_string

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

Purpose

Method on `Doc`: as string. Throws on failure.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

string — result string

(Doc) as_null

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

Purpose

Method on `Doc`: as null. Throws on failure.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) as_int

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

Purpose

Method on `Doc`: as int. Throws on failure.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) as_f64

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

Purpose

Method on `Doc`: as f64. Throws on failure.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

f64 — a value of this type

(Doc) is_null

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

Purpose

Method on `Doc`: whether it is null.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

bool — true or false

(Doc) text

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

Purpose

Method on `Doc`: return the current text.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

string — result string

(Doc) key

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

Purpose

Call `key` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

string — result string

(Doc) count

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

Purpose

Method on `Doc`: count non-overlapping occurrences.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) at

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

Purpose

Call `at` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)
i int
index or integer (int)

Returns

int — a value of this type

(Doc) has

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

Purpose

Call `has` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)
key string
key (string)

Returns

bool — true or false

(Doc) dict_keys

XuAPI
pub fn (d Doc) dict_keys(n int) []string

Purpose

Method on `Doc`: dict keys.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

[]string — slice result

(Doc) get

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

Purpose

Call `get` on `Doc`.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)
key string
key (string)

Returns

int — a value of this type

(Doc) number_int

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

Purpose

number_int converts a number node whose raw text is a plain integer.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

int — a value of this type

(Doc) number_f64

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

Purpose

number_f64 converts a number node through strconv.parse_float.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

f64 — a value of this type

parse

XuAPI
pub fn parse(src &string) Doc

Purpose

===== parse =====

Parameters

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

Returns

Doc — a value of this type

escape

XuAPI
pub fn escape(s &string) string

Purpose

escape: JSON string body escaping (no surrounding quotes).

Parameters

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

Returns

string — result string

quote

XuAPI
pub fn quote(s &string) string

Purpose

quote: JSON string literal, surrounding quotes included.

Parameters

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

Returns

string — result string

unquote

XuAPI
pub fn unquote(s &string) string

Purpose

unquote parses exactly one JSON string literal (quotes included). Throws on failure.

Parameters

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

Returns

string — result string

(Doc) to_json

XuAPI
pub fn (d Doc) to_json() string

Purpose

to_json: canonical re-emission of the document (keys in parse order, strings re-escaped, numbers verbatim).

Parameters

d Doc
receiver Doc (value receiver)

Returns

string — result string

valid

XuAPI
pub fn valid(src &string) bool

Purpose

Whether the value is valid.

Parameters

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

Returns

bool — true or false

compact

XuAPI
pub fn compact(src &string) string

Purpose

compact; returns string. Throws on failure.

Parameters

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

Returns

string — result string

indent

XuAPI
pub fn indent(src &string, prefix &string, gap &string) string

Purpose

indent; returns string. Throws on failure.

Parameters

src &string
source (borrowed; caller keeps it; type &string)
prefix &string
prefix (borrowed; caller keeps it; type &string)
gap &string
gap (borrowed; caller keeps it; type &string)

Returns

string — result string

html_escape

XuAPI
pub fn html_escape(src &string) string

Purpose

Html escape.

Parameters

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

Returns

string — result string

(Doc) encode

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

Purpose

Re-emit one parsed subtree with the same escaping and number spelling as to_json, so consumers can retain complete nested response values. Throws on failure.

Parameters

d Doc
receiver Doc (value receiver)
n int
count, length, or limit (int)

Returns

string — result string