Define Properties as map[string]string instead of using an internal map.
diff --git a/decoder.go b/decoder.go index 3c4246c..9a8b90d 100644 --- a/decoder.go +++ b/decoder.go
@@ -16,17 +16,17 @@ ) // Decodes an ISO-8859-1 encoded buffer into a Properties struct. -func Decode(buf []byte) (*Properties, error) { +func Decode(buf []byte) (Properties, error) { return decodeWithEncoding(buf, enc_iso_8859_1) } // Decodes an UTF-8 string into a Properties struct. -func DecodeFromString(input string) (*Properties, error) { +func DecodeFromString(input string) (Properties, error) { return decodeWithEncoding([]byte(input), enc_utf8) } // Decodes either an ISO-8859-1 or an UTF-8 encoded string into a Properties struct. -func decodeWithEncoding(buf []byte, enc encoding) (*Properties, error) { +func decodeWithEncoding(buf []byte, enc encoding) (Properties, error) { return newParser().Parse(convert(buf, enc)) }
diff --git a/decoder_test.go b/decoder_test.go index e445b8b..701ef2e 100644 --- a/decoder_test.go +++ b/decoder_test.go
@@ -136,11 +136,11 @@ p, err := Decode([]byte(input)) c.Assert(err, IsNil) c.Assert(p, NotNil) - c.Assert(p.Len(), Equals, len(keyvalues)/2, Commentf("Odd number of key/value pairs.")) + c.Assert(len(p), Equals, len(keyvalues)/2, Commentf("Odd number of key/value pairs.")) for i := 0; i < len(keyvalues)/2; i += 2 { key, value := keyvalues[i], keyvalues[i+1] - v, ok := p.Get(key) + v, ok := p[key] c.Assert(ok, Equals, true, Commentf("No key %q for input %q", key, input)) c.Assert(v, Equals, value, Commentf("Value %q does not match input %q", value, input)) }
diff --git a/example_test.go b/example_test.go index 7ecbc11..1c128cc 100644 --- a/example_test.go +++ b/example_test.go
@@ -12,7 +12,7 @@ buf := []byte("key = ISO-8859-1 value with unicode literal \\u2318 and umlaut ") buf = append(buf, 0xE4) // 0xE4 == ä p, _ := Decode(buf) - v, ok := p.Get("key") + v, ok := p["key"] fmt.Println(ok) fmt.Println(v) // Output: @@ -22,7 +22,7 @@ func ExampleDecodeFromString() { p, _ := DecodeFromString("key = UTF-8 value with unicode character ⌘ and umlaut ä") - v, ok := p.Get("key") + v, ok := p["key"] fmt.Println(ok) fmt.Println(v) // Output:
diff --git a/parser.go b/parser.go index 0909443..849449b 100644 --- a/parser.go +++ b/parser.go
@@ -17,10 +17,10 @@ return &parser{} } -func (p *parser) Parse(input string) (props *Properties, err error) { +func (p *parser) Parse(input string) (props Properties, err error) { defer p.recover(&err) p.lex = lex(input) - props = &Properties{m:make(map[string]string)} + props = make(map[string]string) for { token := p.expectOneOf(itemKey, itemEOF) @@ -31,10 +31,10 @@ token = p.expectOneOf(itemValue, itemEOF) if token.typ == itemEOF { - props.Set(key, "") + props[key] = "" break } - props.Set(key, token.val) + props[key] = token.val } return props, nil
diff --git a/properties.go b/properties.go index ee0d318..0f965a9 100644 --- a/properties.go +++ b/properties.go
@@ -4,28 +4,4 @@ package goproperties -type Properties struct { - m map[string]string -} - -// Returns the value for the given key. -func (p *Properties) Get(key string) (value string, ok bool) { - value, ok = p.m[key] - return value, ok -} - -// Sets the property key to the given value and returns the previous value if exists or an empty string. -func (p *Properties) Set(key, value string) (prevValue string) { - prevValue, ok := p.m[key] - if !ok { - prevValue = "" - } - - p.m[key] = value - return prevValue -} - -// Returns the number of keys. -func (p *Properties) Len() int { - return len(p.m) -} +type Properties map[string]string