diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index ee26a08..77a58e9 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -15,7 +15,7 @@ }, { "ImportPath": "github.com/coreos/yaml", - "Rev": "9f9df34309c04878acc86042b16630b0f696e1de" + "Rev": "6b16a5714269b2f70720a45406b1babd947a17ef" }, { "ImportPath": "github.com/dotcloud/docker/pkg/netlink", diff --git a/Godeps/_workspace/src/github.com/coreos/yaml/README.md b/Godeps/_workspace/src/github.com/coreos/yaml/README.md index af07056..4427005 100644 --- a/Godeps/_workspace/src/github.com/coreos/yaml/README.md +++ b/Godeps/_workspace/src/github.com/coreos/yaml/README.md @@ -1,3 +1,6 @@ +Note: This is a fork of https://github.com/go-yaml/yaml. The following README +doesn't necessarily apply to this fork. + # YAML support for the Go language Introduction diff --git a/Godeps/_workspace/src/github.com/coreos/yaml/decode.go b/Godeps/_workspace/src/github.com/coreos/yaml/decode.go index a098626..e219d4b 100644 --- a/Godeps/_workspace/src/github.com/coreos/yaml/decode.go +++ b/Godeps/_workspace/src/github.com/coreos/yaml/decode.go @@ -30,13 +30,15 @@ type node struct { // Parser, produces a node tree out of a libyaml event stream. type parser struct { - parser yaml_parser_t - event yaml_event_t - doc *node + parser yaml_parser_t + event yaml_event_t + doc *node + transform transformString } -func newParser(b []byte) *parser { - p := parser{} +func newParser(b []byte, t transformString) *parser { + p := parser{transform: t} + if !yaml_parser_initialize(&p.parser) { panic("Failed to initialize YAML emitter") } @@ -175,7 +177,10 @@ func (p *parser) mapping() *node { p.anchor(n, p.event.anchor) p.skip() for p.event.typ != yaml_MAPPING_END_EVENT { - n.children = append(n.children, p.parse(), p.parse()) + key := p.parse() + key.value = p.transform(key.value) + value := p.parse() + n.children = append(n.children, key, value) } p.skip() return n diff --git a/Godeps/_workspace/src/github.com/coreos/yaml/decode_test.go b/Godeps/_workspace/src/github.com/coreos/yaml/decode_test.go index ef3d37f..349bee7 100644 --- a/Godeps/_workspace/src/github.com/coreos/yaml/decode_test.go +++ b/Godeps/_workspace/src/github.com/coreos/yaml/decode_test.go @@ -1,8 +1,8 @@ package yaml_test import ( + "github.com/coreos/yaml" . "gopkg.in/check.v1" - "gopkg.in/yaml.v1" "math" "reflect" "strings" @@ -557,6 +557,23 @@ func (s *S) TestUnmarshalWithFalseSetterIgnoresValue(c *C) { c.Assert(m["ghi"].value, Equals, 3) } +func (s *S) TestUnmarshalWithTransform(c *C) { + data := `{a_b: 1, c-d: 2, e-f_g: 3, h_i-j: 4}` + expect := map[string]int{ + "a_b": 1, + "c_d": 2, + "e_f_g": 3, + "h_i_j": 4, + } + m := map[string]int{} + yaml.UnmarshalMappingKeyTransform = func(i string) string { + return strings.Replace(i, "-", "_", -1) + } + err := yaml.Unmarshal([]byte(data), m) + c.Assert(err, IsNil) + c.Assert(m, DeepEquals, expect) +} + // From http://yaml.org/type/merge.html var mergeTests = ` anchors: diff --git a/Godeps/_workspace/src/github.com/coreos/yaml/encode_test.go b/Godeps/_workspace/src/github.com/coreos/yaml/encode_test.go index c9febc2..2cd0ea7 100644 --- a/Godeps/_workspace/src/github.com/coreos/yaml/encode_test.go +++ b/Godeps/_workspace/src/github.com/coreos/yaml/encode_test.go @@ -7,8 +7,8 @@ import ( "strings" "time" + "github.com/coreos/yaml" . "gopkg.in/check.v1" - "gopkg.in/yaml.v1" ) var marshalIntTest = 123 diff --git a/Godeps/_workspace/src/github.com/coreos/yaml/yaml.go b/Godeps/_workspace/src/github.com/coreos/yaml/yaml.go index f1c390e..16e1365 100644 --- a/Godeps/_workspace/src/github.com/coreos/yaml/yaml.go +++ b/Godeps/_workspace/src/github.com/coreos/yaml/yaml.go @@ -84,7 +84,7 @@ type Getter interface { func Unmarshal(in []byte, out interface{}) (err error) { defer handleErr(&err) d := newDecoder() - p := newParser(in) + p := newParser(in, UnmarshalMappingKeyTransform) defer p.destroy() node := p.parse() if node != nil { @@ -146,6 +146,17 @@ func Marshal(in interface{}) (out []byte, err error) { return } +// UnmarshalMappingKeyTransform is a string transformation that is applied to +// each mapping key in a YAML document before it is unmarshalled. By default, +// UnmarshalMappingKeyTransform is an identity transform (no modification). +var UnmarshalMappingKeyTransform transformString = identityTransform + +type transformString func(in string) (out string) + +func identityTransform(in string) (out string) { + return in +} + // -------------------------------------------------------------------------- // Maintain a mapping of keys to structure field indexes