Source File
resolve.go
Belonging Package
gopkg.in/yaml.v2
package yaml
import (
)
type resolveMapItem struct {
value interface{}
tag string
}
var resolveTable = make([]byte, 256)
var resolveMap = make(map[string]resolveMapItem)
func () {
:= resolveTable
[int('+')] = 'S' // Sign
[int('-')] = 'S'
for , := range "0123456789" {
[int()] = 'D' // Digit
}
for , := range "yYnNtTfFoO~" {
[int()] = 'M' // In map
}
[int('.')] = '.' // Float (potentially in map)
var = []struct {
interface{}
string
[]string
}{
{true, yaml_BOOL_TAG, []string{"y", "Y", "yes", "Yes", "YES"}},
{true, yaml_BOOL_TAG, []string{"true", "True", "TRUE"}},
{true, yaml_BOOL_TAG, []string{"on", "On", "ON"}},
{false, yaml_BOOL_TAG, []string{"n", "N", "no", "No", "NO"}},
{false, yaml_BOOL_TAG, []string{"false", "False", "FALSE"}},
{false, yaml_BOOL_TAG, []string{"off", "Off", "OFF"}},
{nil, yaml_NULL_TAG, []string{"", "~", "null", "Null", "NULL"}},
{math.NaN(), yaml_FLOAT_TAG, []string{".nan", ".NaN", ".NAN"}},
{math.Inf(+1), yaml_FLOAT_TAG, []string{".inf", ".Inf", ".INF"}},
{math.Inf(+1), yaml_FLOAT_TAG, []string{"+.inf", "+.Inf", "+.INF"}},
{math.Inf(-1), yaml_FLOAT_TAG, []string{"-.inf", "-.Inf", "-.INF"}},
{"<<", yaml_MERGE_TAG, []string{"<<"}},
}
:= resolveMap
for , := range {
for , := range . {
[] = resolveMapItem{., .}
}
}
}
const longTagPrefix = "tag:yaml.org,2002:"
if strings.HasPrefix(, longTagPrefix) {
return "!!" + [len(longTagPrefix):]
}
return
}
func ( string) string {
if strings.HasPrefix(, "!!") {
return longTagPrefix + [2:]
}
return
}
func ( string) bool {
switch {
case "", yaml_STR_TAG, yaml_BOOL_TAG, yaml_INT_TAG, yaml_FLOAT_TAG, yaml_NULL_TAG, yaml_TIMESTAMP_TAG:
return true
}
return false
}
var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`)
func ( string, string) ( string, interface{}) {
if !resolvableTag() {
return ,
}
defer func() {
switch {
case "", , yaml_STR_TAG, yaml_BINARY_TAG:
return
case yaml_FLOAT_TAG:
if == yaml_INT_TAG {
switch v := .(type) {
case int64:
= yaml_FLOAT_TAG
= float64()
return
case int:
= yaml_FLOAT_TAG
= float64()
return
}
}
}
failf("cannot decode %s `%s` as a %s", shortTag(), , shortTag())
}()
:= byte('N')
if != "" {
= resolveTable[[0]]
}
if , := resolveMap[]; {
return .tag, .value
}
switch {
, := strconv.ParseFloat(, 64)
if == nil {
return yaml_FLOAT_TAG,
}
if == "" || == yaml_TIMESTAMP_TAG {
, := parseTimestamp()
if {
return yaml_TIMESTAMP_TAG,
}
}
:= strings.Replace(, "_", "", -1)
, := strconv.ParseInt(, 0, 64)
if == nil {
if == int64(int()) {
return yaml_INT_TAG, int()
} else {
return yaml_INT_TAG,
}
}
, := strconv.ParseUint(, 0, 64)
if == nil {
return yaml_INT_TAG,
}
if yamlStyleFloat.MatchString() {
, := strconv.ParseFloat(, 64)
if == nil {
return yaml_FLOAT_TAG,
}
}
if strings.HasPrefix(, "0b") {
, := strconv.ParseInt([2:], 2, 64)
if == nil {
if == int64(int()) {
return yaml_INT_TAG, int()
} else {
return yaml_INT_TAG,
}
}
, := strconv.ParseUint([2:], 2, 64)
if == nil {
return yaml_INT_TAG,
}
} else if strings.HasPrefix(, "-0b") {
, := strconv.ParseInt("-" + [3:], 2, 64)
if == nil {
if true || == int64(int()) {
return yaml_INT_TAG, int()
} else {
return yaml_INT_TAG,
}
}
}
default:
panic("resolveTable item not yet handled: " + string(rune()) + " (with " + + ")")
}
}
return yaml_STR_TAG,
}
var allowedTimestampFormats = []string{
"2006-1-2T15:4:5.999999999Z07:00", // RCF3339Nano with short date fields.
"2006-1-2t15:4:5.999999999Z07:00", // RFC3339Nano with short date fields and lower-case "t".
"2006-1-2 15:4:5.999999999", // space separated with no time zone
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |