Documentation ¶
Overview ¶
* 硬编码实现 PEG.
Index ¶
- Constants
- Variables
- type Item
- type Kind
- type Scanner
- type Status
- type Token
- type TokenHandler
- type Toml
- type TomlArray
- type Value
- func (p *Value) Add(ai ...interface{}) error
- func (it *Value) Apply(dst interface{}) (count int)
- func (p *Value) Boolean() bool
- func (p *Value) BooleanArray() []bool
- func (p *Value) Comment() string
- func (p *Value) Comments() []string
- func (p *Value) Datetime() time.Time
- func (p *Value) DatetimeArray() []time.Time
- func (p *Value) Float() float64
- func (p *Value) FloatArray() []float64
- func (p *Value) Id() int
- func (p *Value) Index(idx int) *Value
- func (p *Value) Int() int64
- func (p *Value) IntArray() []int64
- func (p *Value) Integer() int
- func (p *Value) IntegerArray() []int
- func (p *Value) IsValid() bool
- func (p *Value) IsValue() bool
- func (p *Value) Kind() Kind
- func (p *Value) KindIs(kind ...Kind) bool
- func (p *Value) Len() int
- func (p *Value) Set(x interface{}) error
- func (p *Value) SetAs(s string, kind Kind) (err error)
- func (p *Value) SetComment(s string)
- func (p *Value) SetComments(as []string)
- func (p *Value) String() string
- func (p *Value) StringArray() []string
- func (p *Value) UInt() uint64
- func (p *Value) UIntArray() []uint64
- func (p *Value) UInteger() uint
- func (p *Value) UIntegerArray() []uint
Constants ¶
const ( EOF = 0xF8 RuneError = 0xFFFD )
const (
BOM = 0xFEFF // UTF-8 encoded byte order mark
)
Variables ¶
var ( NotSupported = errors.New("not supported") OutOfRange = errors.New("out of range") InternalError = errors.New("internal error") InvalidItem = errors.New("invalid Item") )
var ( InValidFormat = errors.New("invalid TOML format") Redeclared = errors.New("duplicate definitionin") )
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
*Value
}
Item 扩展自 *Value,支持 ArrayOfTables.
func GenItem ¶
GenItem 函数返回一个新 Item. 为保持格式化输出次序, GenItem 内部使用了一个计数器. 使用者应该使用该函数来得到新的 Item. 而不是用 new(Item) 获得. 那样的话就无法保持格式化输出次序.
type Kind ¶
type Kind uint
Kind 用来标识 TOML 所有的规格. 对于用于配置的 TOML 定义, Kind 其实是分段定义和值定义的. 由于 TOML 官方没有使用 段/值 这样的词汇, tom-toml 选用规格这个词.
type Scanner ¶
type TokenHandler ¶
type Toml ¶
Toml 是一个 maps, 不是 tree 实现.
func New ¶
func New() Toml
Must be use New() to got Toml, do not use Toml{}. 新建一个 Toml, 必须使用 New() 函数, 不要用 Toml{}. 因为 Toml 的实现需要有一个用于管理的 Id Value, New() 可以做到.
func (Toml) Apply ¶
Apply to each field in the struct, case sensitive. * Apply 把 p 存储的值赋给 dst , TypeOf(dst).Kind() 为 reflect.Struct, 返回赋值成功的次数.
func (Toml) Fetch ¶
* such as:
p.Fetch("") // returns all valid elements in p p.Fetch("prefix") // same as p.Fetch("prefix.")
从 Toml 中提取出 prefix 开头的所有 Table 元素, 返回值也是一个 Toml. 注意:
返回值是原 Toml 的子集. 返回子集中不包括 [prefix] TableName. 对返回子集添加 *Item 不会增加到原 Toml 中. 对返回子集中的 *Item 进行更新, 原 Toml 也会更新. 子集中不会含有 ArrayOfTables 类型数据.
func (Toml) TableNames ¶
TableNames returns all name of TableName and ArrayOfTables. 返回所有 TableName 的名字和 ArrayOfTables 的名字.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value 用来存储 String 至 Array 的值.
func NewValue ¶
NewValue 函数返回一个新 *Value. 为保持格式化输出次序, NewValue 内部使用了一个计数器. 使用者应该使用该函数来得到新的 *Value. 而不是用 new(Value) 获得. 那样的话就无法保持格式化输出次序.
func (*Value) Add ¶
Add element for Array or typeArray. * Add 方法为数组添加元素, 支持空数组元素. p 本身的 Kind 决定是否支持参数元素 Kind.
func (*Value) BooleanArray ¶
func (*Value) Datetime ¶
* 如果值是 Datetime 可以使用 Datetime 返回其 time.Time 值. 否则返回UTC时间公元元年1月1日 00:00:00. 可以用 IsZero() 进行判断.
func (*Value) DatetimeArray ¶
func (*Value) FloatArray ¶
func (*Value) IntegerArray ¶
func (*Value) Set ¶
Set 用来设置 *Value 要存储的具体值. 参数 x 的类型范围可以是 String,Integer,Float,Boolean,Datetime 之一 如果 *Value 的 Kind 是 InvalidKind(也就是没有明确值类型), 调用 Set 后, *Value 的 kind 会相应的更改, 否则要求 x 的类型必须符合 *Value 的 kind Set 失败会返回 NotSupported 错误.