Skip to content

Commit

Permalink
Squashed 'vendor/github.com/BurntSushi/toml/' changes from 2ceedfe..7…
Browse files Browse the repository at this point in the history
…47a777

bbd5bb6 Make struct decoding also handle empty Primitives
66416ff Decode empty Primitives into nullable values successfully
5b80cc5 Clean up slice decoding handling
75869ce Unify two switch arms
1946733 Properly encode struct fields having toml tags without a name
0e5f512 Don't treat non-empty strings of whitespace as empty for omitempty
e27e134 add bool empty option
a4eecd4 Remove extra lexer advance
0c4ce10 In Decode, reuse slices when possible
dacf173 Merge remote-tracking branch 'yourkarma/master'
166915e Merge pull request #82 from mjibson/fix-decode-omit
3e3bd42 Don't panic when failing to parse a timestamp
001f7af Fix no-op utf-8 validity test
2678c1e Add tests for ignored fields
2fe0945 Flesh out anonymous field encoding
4cc516a Merge remote-tracking branch 'shawnps/gofmt'
f772cd8 Merge pull request #112 from stapelberg/inaccessible-go1.6
77ccfcd Bugfix: update check for inaccessible fields for Go 1.6
312db06 Merge pull request #93 from bep/parse-panic
782628a gofmt -s
5c4df71 Merge pull request #108 from kezhuw/fix_endless_loop
c3bcd45 Fix endless loop in table name lexing
851e5be Panic instead of os.Exit for illegal state situations in parser
110f954 Make new destination slice when length doesn't match.
54c24c1 Use correct name during decode with omit options
056c9bc Merge pull request #81 from bbuck/omitempty
aa708eb Clean up, remove zero as 'empty' and add 'omitzero' option
d918309 Support for omitempty, as well as tests for omitempty.
443a628 Merge pull request #72 from binary132/fix-readme
9baf8a8 Updated link for TOML v0.2.0
f706d00 Support quoted keys.
7eda3e2 Remove escape for '/'.
0f9db13 Forbid '#' in table names.
a6db6cf Simplify lexer for Unicode escapes and add support for `\U`.
3644d30 Fix typo. Thanks @ChrisHines
32ee81d Various formatting fixes. 80 cols.
0eaa740 Fix #66.
3883ac1 Merge pull request #59 from fromonesrc/patch-1
237e946 Merge pull request #57 from gisakulabs/UnmarshalTOML
b2c5eb4 Merge pull request #61 from halostatue/multiline
1956abe Implement multiline strings and raw multiline strings.
73199af Support single-line raw strings.
71fac5b Fixed comment typo
ac8879e Fix readme typo on Decode method
67ade19 Modified the `Unmarshaler` interface to `.UnmarshalTOML(v interface{})`
bc95534 Added support for UnmarshalTOML() interface.

git-subtree-dir: vendor/github.com/BurntSushi/toml
git-subtree-split: 747a77770ca4730759d5944e3a7fe869d452648b
  • Loading branch information
nathanielc committed Jun 9, 2016
1 parent 2488f6b commit 814a5b4
Show file tree
Hide file tree
Showing 13 changed files with 1,142 additions and 195 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ representations. (There is an example of this below.)
Spec: https://github.com/mojombo/toml

Compatible with TOML version
[v0.2.0](https://github.com/mojombo/toml/blob/master/versions/toml-v0.2.0.md)
[v0.2.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.2.0.md)

Documentation: http://godoc.org/github.com/BurntSushi/toml

Expand Down Expand Up @@ -111,7 +111,7 @@ type songs struct {
Song []song
}
var favorites songs
if _, err := Decode(blob, &favorites); err != nil {
if _, err := toml.Decode(blob, &favorites); err != nil {
log.Fatal(err)
}

Expand Down
6 changes: 4 additions & 2 deletions _examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func main() {

fmt.Printf("Title: %s\n", config.Title)
fmt.Printf("Owner: %s (%s, %s), Born: %s\n",
config.Owner.Name, config.Owner.Org, config.Owner.Bio, config.Owner.DOB)
config.Owner.Name, config.Owner.Org, config.Owner.Bio,
config.Owner.DOB)
fmt.Printf("Database: %s %v (Max conn. %d), Enabled? %v\n",
config.DB.Server, config.DB.Ports, config.DB.ConnMax, config.DB.Enabled)
config.DB.Server, config.DB.Ports, config.DB.ConnMax,
config.DB.Enabled)
for serverName, server := range config.Servers {
fmt.Printf("Server: %s (%s, %s)\n", serverName, server.IP, server.DC)
}
Expand Down
39 changes: 36 additions & 3 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ import (

var e = fmt.Errorf

// Unmarshaler is the interface implemented by objects that can unmarshal a
// TOML description of themselves.
type Unmarshaler interface {
UnmarshalTOML(interface{}) error
}

// Unmarshal decodes the contents of `p` in TOML format into a pointer `v`.
func Unmarshal(p []byte, v interface{}) error {
_, err := Decode(string(p), v)
return err
}

// Primitive is a TOML value that hasn't been decoded into a Go value.
// When using the various `Decode*` functions, the type `Primitive` may
// be given to any value, and its decoding will be delayed.
Expand Down Expand Up @@ -128,6 +140,7 @@ func DecodeReader(r io.Reader, v interface{}) (MetaData, error) {
// Any type mismatch produces an error. Finding a type that we don't know
// how to handle produces an unsupported type error.
func (md *MetaData) unify(data interface{}, rv reflect.Value) error {

// Special case. Look for a `Primitive` value.
if rv.Type() == reflect.TypeOf((*Primitive)(nil)).Elem() {
// Save the undecoded data and the key context into the primitive
Expand All @@ -141,6 +154,13 @@ func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
return nil
}

// Special case. Unmarshaler Interface support.
if rv.CanAddr() {
if v, ok := rv.Addr().Interface().(Unmarshaler); ok {
return v.UnmarshalTOML(data)
}
}

// Special case. Handle time.Time values specifically.
// TODO: Remove this code when we decide to drop support for Go 1.1.
// This isn't necessary in Go 1.2 because time.Time satisfies the encoding
Expand Down Expand Up @@ -205,6 +225,9 @@ func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
func (md *MetaData) unifyStruct(mapping interface{}, rv reflect.Value) error {
tmap, ok := mapping.(map[string]interface{})
if !ok {
if mapping == nil {
return nil
}
return mismatch(rv, "map", mapping)
}

Expand Down Expand Up @@ -247,6 +270,9 @@ func (md *MetaData) unifyStruct(mapping interface{}, rv reflect.Value) error {
func (md *MetaData) unifyMap(mapping interface{}, rv reflect.Value) error {
tmap, ok := mapping.(map[string]interface{})
if !ok {
if tmap == nil {
return nil
}
return badtype("map", mapping)
}
if rv.IsNil() {
Expand All @@ -272,6 +298,9 @@ func (md *MetaData) unifyMap(mapping interface{}, rv reflect.Value) error {
func (md *MetaData) unifyArray(data interface{}, rv reflect.Value) error {
datav := reflect.ValueOf(data)
if datav.Kind() != reflect.Slice {
if !datav.IsValid() {
return nil
}
return badtype("slice", data)
}
sliceLen := datav.Len()
Expand All @@ -285,12 +314,16 @@ func (md *MetaData) unifyArray(data interface{}, rv reflect.Value) error {
func (md *MetaData) unifySlice(data interface{}, rv reflect.Value) error {
datav := reflect.ValueOf(data)
if datav.Kind() != reflect.Slice {
if !datav.IsValid() {
return nil
}
return badtype("slice", data)
}
sliceLen := datav.Len()
if rv.IsNil() {
rv.Set(reflect.MakeSlice(rv.Type(), sliceLen, sliceLen))
n := datav.Len()
if rv.IsNil() || rv.Cap() < n {
rv.Set(reflect.MakeSlice(rv.Type(), n, n))
}
rv.SetLen(n)
return md.unifySliceArray(datav, rv)
}

Expand Down
23 changes: 23 additions & 0 deletions decode_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ func (k Key) String() string {
return strings.Join(k, ".")
}

func (k Key) maybeQuotedAll() string {
var ss []string
for i := range k {
ss = append(ss, k.maybeQuoted(i))
}
return strings.Join(ss, ".")
}

func (k Key) maybeQuoted(i int) string {
quote := false
for _, c := range k[i] {
if !isBareKeyChar(c) {
quote = true
break
}
}
if quote {
return "\"" + strings.Replace(k[i], "\"", "\\\"", -1) + "\""
} else {
return k[i]
}
}

func (k Key) add(piece string) Key {
newKey := make(Key, len(k)+1)
copy(newKey, k)
Expand Down
Loading

0 comments on commit 814a5b4

Please sign in to comment.