parser

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	RJson = "json"
	RUrl  = "url"
)

Variables

View Source
var Transferred map[string]string = map[string]string{
	`\'`: "_Sg_.Qmark_",
	`\"`: "_Db_.Qmark_",
}

Transferred Escape symbol

Functions

func ConvBool added in v1.2.0

func ConvBool(raw string) (value bool)

ConvBool convert string to bool

Example

func TestExampleConvBool(t *testing.T) {

var raw = "True"
var cv bool

// case
cv = ConvBool(raw)
fmt.Printf("ConvBool:%v => %v\n", raw, cv)

// case
raw = "TRUE"
cv = ConvBool(raw)
fmt.Printf("ConvBool:%v => %v\n", raw, cv)

// case
raw = "vaild"
cv = ConvBool(raw)
fmt.Printf("ConvBool:%v => %v\n", raw, cv)
Output:

ConvBool:True => true
ConvBool:TRUE => true
ConvBool:vaild => false

func ConvF64 added in v1.2.0

func ConvF64(raw string) (value float64)

ConvF64 convert string to float64

Example
var raw = "1949"
var cv float64

// case
cv = ConvF64(raw)
fmt.Printf("ConvF64:%v => %v\n", raw, cv)

// case
raw = "+1949"
cv = ConvF64(raw)
fmt.Printf("ConvF64:%v => %v\n", raw, cv)

// case
raw = "-1949.1001"
cv = ConvF64(raw)
fmt.Printf("ConvF64:%v => %v\n", raw, cv)

// case
raw = "-3.14159265359"
cv = ConvF64(raw)
fmt.Printf("ConvI64:%v => %v\n", raw, cv)

// case
raw = "vaild"
cv = ConvF64(raw)
fmt.Printf("ConvI64:%v => %v\n", raw, cv)
Output:

ConvF64:1949 => 1949
ConvF64:+1949 => 1949
ConvF64:-1949.1001 => -1949.1001
ConvI64:-3.14159265359 => -3.14159265359
ConvI64:vaild => 0

func ConvI64 added in v1.2.0

func ConvI64(raw string) (value int64)

ConvI64 convert string to int64, compatible float types

Example
var raw = "1949"
var cv int64

// case
cv = ConvI64(raw)
fmt.Printf("ConvI64:%v => %v\n", raw, cv)

// case
raw = "+1949"
cv = ConvI64(raw)
fmt.Printf("ConvI64:%v => %v\n", raw, cv)

// case
raw = "-1949.1001"
cv = ConvI64(raw)
fmt.Printf("ConvBool:%v => %v\n", raw, cv)

// case
raw = "-2022"
cv = ConvI64(raw)
fmt.Printf("ConvI64:%v => %v\n", raw, cv)

// case
raw = "vaild"
cv = ConvI64(raw)
fmt.Printf("ConvI64:%v => %v\n", raw, cv)
Output:

ConvI64:1949 => 1949
ConvI64:+1949 => 1949
ConvI64:-1949.1001 => -1949
ConvI64:-2022 => -2022
ConvI64:vaild => 0

func ConvInt added in v1.2.0

func ConvInt(raw string) (value int)

ConvInt convert string to int

Example
var raw = "1949"
var cv int

// case
cv = ConvInt(raw)
fmt.Printf("ConvInt:%v => %v\n", raw, cv)

// case
raw = "+1949"
cv = ConvInt(raw)
fmt.Printf("ConvInt:%v => %v\n", raw, cv)

// case
raw = "-1949.1001"
cv = ConvInt(raw)
fmt.Printf("ConvInt:%v => %v\n", raw, cv)

// case
raw = "-2022"
cv = ConvInt(raw)
fmt.Printf("ConvInt:%v => %v\n", raw, cv)

// case
raw = "vaild"
cv = ConvInt(raw)
fmt.Printf("ConvInt:%v => %v\n", raw, cv)
Output:

ConvInt:1949 => 1949
ConvInt:+1949 => 1949
ConvInt:-1949.1001 => -1949
ConvInt:-2022 => -2022
ConvInt:vaild => 0

func GetUrlContent

func GetUrlContent(vUrl string) []byte

GetUrlContent get url content

func NewParser

func NewParser(script string) [][]string

NewParser cli command 解析器 解析规则:

单行以“;"分割
多行以“行\n分割"分割

func NewScriptFile

func NewScriptFile(filename string) []string

NewScriptFile parse the script file, the syntax like shell.

"#"   comment line

func ParseLine

func ParseLine(line string) [][]string

ParseLine parse shell line syntax to option

Types

type BaseReceiver

type BaseReceiver struct {
	// contains filtered or unexported fields
}

BaseReceiver the url data receiver

type DataReceiver

type DataReceiver interface {
	Name() string
	Receiver(DataReceiverType, string) DataReceiver
	GetData() map[string]any
}

DataReceiver the data parse tool

func NewDataReceiver

func NewDataReceiver(vType string) (dr DataReceiver, er error)

NewDataReceiver get DataReceiver by different type.

type DataReceiverType

type DataReceiverType uint8
const (
	ReceiverContent DataReceiverType = iota
	ReceiverFile
	ReceiverUrl
)

type JsonReceiver

type JsonReceiver struct {
	BaseReceiver
}

JsonReceiver the data parse grammar, support json/url

func (*JsonReceiver) GetData

func (c *JsonReceiver) GetData() map[string]any

GetData get finally data by parse

func (*JsonReceiver) JsonFile

func (c *JsonReceiver) JsonFile(filename string) *JsonReceiver

JsonFile parse json from json-file

func (*JsonReceiver) JsonStr

func (c *JsonReceiver) JsonStr(vStr string) *JsonReceiver

JsonStr parse json string

func (*JsonReceiver) JsonUrl

func (c *JsonReceiver) JsonUrl(vUrl string) *JsonReceiver

JsonUrl parse json from json-url, only http.get

func (*JsonReceiver) Name

func (c *JsonReceiver) Name() string

func (*JsonReceiver) Receiver

func (c *JsonReceiver) Receiver(vType DataReceiverType, content string) DataReceiver

Receiver receiver data

type UrlReceiver

type UrlReceiver struct {
	BaseReceiver
}

UrlReceiver the url data receiver

func (*UrlReceiver) GetData

func (c *UrlReceiver) GetData() map[string]any

GetData get finally data by parse

func (*UrlReceiver) Name

func (c *UrlReceiver) Name() string

func (*UrlReceiver) Receiver

func (c *UrlReceiver) Receiver(vType DataReceiverType, content string) DataReceiver

Receiver receiver data

func (*UrlReceiver) UrlFile

func (c *UrlReceiver) UrlFile(filename string) *UrlReceiver

UrlFile parse json from json-file

func (*UrlReceiver) UrlStr

func (c *UrlReceiver) UrlStr(vStr string) *UrlReceiver

UrlStr parse json string

func (*UrlReceiver) UrlUrl

func (c *UrlReceiver) UrlUrl(vUrl string) *UrlReceiver

UrlUrl parse json from json-url, only http.get

type Value added in v1.2.0

type Value struct {
	// contains filtered or unexported fields
}

Value Analysis of original string type conversion

func NewValue added in v1.2.0

func NewValue(value string) *Value

func (*Value) Bool added in v1.2.0

func (c *Value) Bool() bool

Directories

Path Synopsis
Package syntax is bin language syntax extend, like digital computing.
Package syntax is bin language syntax extend, like digital computing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL