Index: goyaml.go |
=== gustavo@niemeyer.net-20110803012746-kfztjoklitkbblk8 > roger.peppe@canonical.com-20111124195000-qdc8y4aqqk6uprst |
=== modified file 'goyaml.go' |
--- goyaml.go 2011-08-03 01:27:46 +0000 |
+++ goyaml.go 2011-11-24 19:50:00 +0000 |
@@ -10,15 +10,15 @@ |
package goyaml |
import ( |
+ "errors" |
"fmt" |
"reflect" |
"runtime" |
"strings" |
"sync" |
- "os" |
) |
-func handleErr(err *os.Error) { |
+func handleErr(err *error) { |
if r := recover(); r != nil { |
if _, ok := r.(runtime.Error); ok { |
panic(r) |
@@ -27,8 +27,8 @@ |
} else if _, ok := r.(externalPanic); ok { |
panic(r) |
} else if s, ok := r.(string); ok { |
- *err = os.NewError("YAML error: " + s) |
- } else if e, ok := r.(os.Error); ok { |
+ *err = errors.New("YAML error: " + s) |
+ } else if e, ok := r.(error); ok { |
*err = e |
} else { |
panic(r) |
@@ -84,7 +84,7 @@ |
// var T t |
// goyaml.Unmarshal([]byte("a: 1\nb: 2"), &t) |
// |
-func Unmarshal(in []byte, out interface{}) (err os.Error) { |
+func Unmarshal(in []byte, out interface{}) (err error) { |
defer handleErr(&err) |
d := newDecoder() |
p := newParser(in) |
@@ -128,7 +128,7 @@ |
// goyaml.Marshal(&T{B: 2}) // Returns "b: 2\n" |
// goyaml.Marshal(&T{F: 1}} // Returns "a: 1\nb: 0\n" |
// |
-func Marshal(in interface{}) (out []byte, err os.Error) { |
+func Marshal(in interface{}) (out []byte, err error) { |
defer handleErr(&err) |
e := newEncoder() |
defer e.destroy() |
@@ -138,7 +138,6 @@ |
return |
} |
- |
// -------------------------------------------------------------------------- |
// Maintain a mapping of keys to structure field indexes |
@@ -165,7 +164,7 @@ |
return string(e) |
} |
-func getStructFields(st reflect.Type) (*structFields, os.Error) { |
+func getStructFields(st reflect.Type) (*structFields, error) { |
path := st.PkgPath() |
name := st.Name() |
@@ -235,7 +234,7 @@ |
if _, found = fieldsMap[info.Key]; found { |
msg := "Duplicated key '" + info.Key + "' in struct " + st.String() |
- return nil, os.NewError(msg) |
+ return nil, errors.New(msg) |
} |
fieldsList[len(fieldsMap)] = info |
@@ -263,6 +262,8 @@ |
return v.Len() == 0 |
case reflect.Map: |
return v.Len() == 0 |
+ case reflect.Ptr: |
+ return v.IsNil() |
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
return v.Int() == 0 |
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: |