diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
commit | 2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch) | |
tree | 7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/json | |
parent | 02e9018f1616b23f1276151797216717b3564202 (diff) | |
download | gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.zip gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.gz gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.bz2 |
libgo: Update to weekly.2011-11-02.
From-SVN: r181964
Diffstat (limited to 'libgo/go/json')
-rw-r--r-- | libgo/go/json/decode.go | 24 | ||||
-rw-r--r-- | libgo/go/json/decode_test.go | 5 | ||||
-rw-r--r-- | libgo/go/json/encode.go | 29 | ||||
-rw-r--r-- | libgo/go/json/indent.go | 9 | ||||
-rw-r--r-- | libgo/go/json/scanner.go | 13 | ||||
-rw-r--r-- | libgo/go/json/scanner_test.go | 3 | ||||
-rw-r--r-- | libgo/go/json/stream.go | 22 |
7 files changed, 48 insertions, 57 deletions
diff --git a/libgo/go/json/decode.go b/libgo/go/json/decode.go index 800df98..8abd7b4 100644 --- a/libgo/go/json/decode.go +++ b/libgo/go/json/decode.go @@ -9,7 +9,7 @@ package json import ( "encoding/base64" - "os" + "errors" "reflect" "runtime" "strconv" @@ -50,7 +50,7 @@ import ( // If no more serious errors are encountered, Unmarshal returns // an UnmarshalTypeError describing the earliest such error. // -func Unmarshal(data []byte, v interface{}) os.Error { +func Unmarshal(data []byte, v interface{}) error { d := new(decodeState).init(data) // Quick check for well-formedness. @@ -70,7 +70,7 @@ func Unmarshal(data []byte, v interface{}) os.Error { // encoding. UnmarshalJSON must copy the JSON data // if it wishes to retain the data after returning. type Unmarshaler interface { - UnmarshalJSON([]byte) os.Error + UnmarshalJSON([]byte) error } // An UnmarshalTypeError describes a JSON value that was @@ -80,7 +80,7 @@ type UnmarshalTypeError struct { Type reflect.Type // type of Go value it could not be assigned to } -func (e *UnmarshalTypeError) String() string { +func (e *UnmarshalTypeError) Error() string { return "json: cannot unmarshal " + e.Value + " into Go value of type " + e.Type.String() } @@ -92,7 +92,7 @@ type UnmarshalFieldError struct { Field reflect.StructField } -func (e *UnmarshalFieldError) String() string { +func (e *UnmarshalFieldError) Error() string { return "json: cannot unmarshal object key " + strconv.Quote(e.Key) + " into unexported field " + e.Field.Name + " of type " + e.Type.String() } @@ -102,7 +102,7 @@ type InvalidUnmarshalError struct { Type reflect.Type } -func (e *InvalidUnmarshalError) String() string { +func (e *InvalidUnmarshalError) Error() string { if e.Type == nil { return "json: Unmarshal(nil)" } @@ -113,13 +113,13 @@ func (e *InvalidUnmarshalError) String() string { return "json: Unmarshal(nil " + e.Type.String() + ")" } -func (d *decodeState) unmarshal(v interface{}) (err os.Error) { +func (d *decodeState) unmarshal(v interface{}) (err error) { defer func() { if r := recover(); r != nil { if _, ok := r.(runtime.Error); ok { panic(r) } - err = r.(os.Error) + err = r.(error) } }() @@ -142,14 +142,14 @@ type decodeState struct { off int // read offset in data scan scanner nextscan scanner // for calls to nextValue - savedError os.Error + savedError error tempstr string // scratch space to avoid some allocations } // errPhase is used for errors that should not happen unless // there is a bug in the JSON decoder or something is editing // the data slice while the decoder executes. -var errPhase = os.NewError("JSON decoder out of sync - data changing underfoot?") +var errPhase = errors.New("JSON decoder out of sync - data changing underfoot?") func (d *decodeState) init(data []byte) *decodeState { d.data = data @@ -159,13 +159,13 @@ func (d *decodeState) init(data []byte) *decodeState { } // error aborts the decoding by panicking with err. -func (d *decodeState) error(err os.Error) { +func (d *decodeState) error(err error) { panic(err) } // saveError saves the first err it is called with, // for reporting at the end of the unmarshal. -func (d *decodeState) saveError(err os.Error) { +func (d *decodeState) saveError(err error) { if d.savedError == nil { d.savedError = err } diff --git a/libgo/go/json/decode_test.go b/libgo/go/json/decode_test.go index d745e8dd..bd4326a 100644 --- a/libgo/go/json/decode_test.go +++ b/libgo/go/json/decode_test.go @@ -6,7 +6,6 @@ package json import ( "bytes" - "os" "reflect" "strings" "testing" @@ -30,7 +29,7 @@ type unmarshaler struct { T bool } -func (u *unmarshaler) UnmarshalJSON(b []byte) os.Error { +func (u *unmarshaler) UnmarshalJSON(b []byte) error { *u = unmarshaler{true} // All we need to see that UnmarshalJson is called. return nil } @@ -52,7 +51,7 @@ type unmarshalTest struct { in string ptr interface{} out interface{} - err os.Error + err error } var unmarshalTests = []unmarshalTest{ diff --git a/libgo/go/json/encode.go b/libgo/go/json/encode.go index ba5c15c..aac8f91 100644 --- a/libgo/go/json/encode.go +++ b/libgo/go/json/encode.go @@ -12,7 +12,6 @@ package json import ( "bytes" "encoding/base64" - "os" "reflect" "runtime" "sort" @@ -96,7 +95,7 @@ import ( // handle them. Passing cyclic structures to Marshal will result in // an infinite recursion. // -func Marshal(v interface{}) ([]byte, os.Error) { +func Marshal(v interface{}) ([]byte, error) { e := &encodeState{} err := e.marshal(v) if err != nil { @@ -106,7 +105,7 @@ func Marshal(v interface{}) ([]byte, os.Error) { } // MarshalIndent is like Marshal but applies Indent to format the output. -func MarshalIndent(v interface{}, prefix, indent string) ([]byte, os.Error) { +func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { b, err := Marshal(v) if err != nil { return nil, err @@ -120,7 +119,7 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, os.Error) { } // MarshalForHTML is like Marshal but applies HTMLEscape to the output. -func MarshalForHTML(v interface{}) ([]byte, os.Error) { +func MarshalForHTML(v interface{}) ([]byte, error) { b, err := Marshal(v) if err != nil { return nil, err @@ -159,14 +158,14 @@ func HTMLEscape(dst *bytes.Buffer, src []byte) { // Marshaler is the interface implemented by objects that // can marshal themselves into valid JSON. type Marshaler interface { - MarshalJSON() ([]byte, os.Error) + MarshalJSON() ([]byte, error) } type UnsupportedTypeError struct { Type reflect.Type } -func (e *UnsupportedTypeError) String() string { +func (e *UnsupportedTypeError) Error() string { return "json: unsupported type: " + e.Type.String() } @@ -174,17 +173,17 @@ type InvalidUTF8Error struct { S string } -func (e *InvalidUTF8Error) String() string { +func (e *InvalidUTF8Error) Error() string { return "json: invalid UTF-8 in string: " + strconv.Quote(e.S) } type MarshalerError struct { - Type reflect.Type - Error os.Error + Type reflect.Type + Err error } -func (e *MarshalerError) String() string { - return "json: error calling MarshalJSON for type " + e.Type.String() + ": " + e.Error.String() +func (e *MarshalerError) Error() string { + return "json: error calling MarshalJSON for type " + e.Type.String() + ": " + e.Err.Error() } type interfaceOrPtrValue interface { @@ -199,20 +198,20 @@ type encodeState struct { bytes.Buffer // accumulated output } -func (e *encodeState) marshal(v interface{}) (err os.Error) { +func (e *encodeState) marshal(v interface{}) (err error) { defer func() { if r := recover(); r != nil { if _, ok := r.(runtime.Error); ok { panic(r) } - err = r.(os.Error) + err = r.(error) } }() e.reflectValue(reflect.ValueOf(v)) return nil } -func (e *encodeState) error(err os.Error) { +func (e *encodeState) error(err error) { panic(err) } @@ -423,7 +422,7 @@ func (sv stringValues) Swap(i, j int) { sv[i], sv[j] = sv[j], sv[i] } func (sv stringValues) Less(i, j int) bool { return sv.get(i) < sv.get(j) } func (sv stringValues) get(i int) string { return sv[i].String() } -func (e *encodeState) string(s string) (int, os.Error) { +func (e *encodeState) string(s string) (int, error) { len0 := e.Len() e.WriteByte('"') start := 0 diff --git a/libgo/go/json/indent.go b/libgo/go/json/indent.go index 2a75303..5ba19b0 100644 --- a/libgo/go/json/indent.go +++ b/libgo/go/json/indent.go @@ -4,14 +4,11 @@ package json -import ( - "bytes" - "os" -) +import "bytes" // Compact appends to dst the JSON-encoded src with // insignificant space characters elided. -func Compact(dst *bytes.Buffer, src []byte) os.Error { +func Compact(dst *bytes.Buffer, src []byte) error { origLen := dst.Len() var scan scanner scan.reset() @@ -52,7 +49,7 @@ func newline(dst *bytes.Buffer, prefix, indent string, depth int) { // copies of indent according to the indentation nesting. // The data appended to dst has no trailing newline, to make it easier // to embed inside other formatted JSON data. -func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) os.Error { +func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error { origLen := dst.Len() var scan scanner scan.reset() diff --git a/libgo/go/json/scanner.go b/libgo/go/json/scanner.go index 1a39b4c..1796904 100644 --- a/libgo/go/json/scanner.go +++ b/libgo/go/json/scanner.go @@ -13,14 +13,11 @@ package json // This file starts with two simple examples using the scanner // before diving into the scanner itself. -import ( - "os" - "strconv" -) +import "strconv" // checkValid verifies that data is valid JSON-encoded data. // scan is passed in for use by checkValid to avoid an allocation. -func checkValid(data []byte, scan *scanner) os.Error { +func checkValid(data []byte, scan *scanner) error { scan.reset() for _, c := range data { scan.bytes++ @@ -37,7 +34,7 @@ func checkValid(data []byte, scan *scanner) os.Error { // nextValue splits data after the next whole JSON value, // returning that value and the bytes that follow it as separate slices. // scan is passed in for use by nextValue to avoid an allocation. -func nextValue(data []byte, scan *scanner) (value, rest []byte, err os.Error) { +func nextValue(data []byte, scan *scanner) (value, rest []byte, err error) { scan.reset() for i, c := range data { v := scan.step(scan, int(c)) @@ -62,7 +59,7 @@ type SyntaxError struct { Offset int64 // error occurred after reading Offset bytes } -func (e *SyntaxError) String() string { return e.msg } +func (e *SyntaxError) Error() string { return e.msg } // A scanner is a JSON scanning state machine. // Callers call scan.reset() and then pass bytes in one at a time @@ -87,7 +84,7 @@ type scanner struct { parseState []int // Error that happened, if any. - err os.Error + err error // 1-byte redo (see undo method) redoCode int diff --git a/libgo/go/json/scanner_test.go b/libgo/go/json/scanner_test.go index 40bf295..0b86cb5 100644 --- a/libgo/go/json/scanner_test.go +++ b/libgo/go/json/scanner_test.go @@ -7,7 +7,6 @@ package json import ( "bytes" "math" - "os" "rand" "reflect" "testing" @@ -140,7 +139,7 @@ func TestIndentBig(t *testing.T) { type indentErrorTest struct { in string - err os.Error + err error } var indentErrorTests = []indentErrorTest{ diff --git a/libgo/go/json/stream.go b/libgo/go/json/stream.go index 98cb793..f247639 100644 --- a/libgo/go/json/stream.go +++ b/libgo/go/json/stream.go @@ -5,8 +5,8 @@ package json import ( + "errors" "io" - "os" ) // A Decoder reads and decodes JSON objects from an input stream. @@ -15,7 +15,7 @@ type Decoder struct { buf []byte d decodeState scan scanner - err os.Error + err error } // NewDecoder returns a new decoder that reads from r. @@ -28,7 +28,7 @@ func NewDecoder(r io.Reader) *Decoder { // // See the documentation for Unmarshal for details about // the conversion of JSON into a Go value. -func (dec *Decoder) Decode(v interface{}) os.Error { +func (dec *Decoder) Decode(v interface{}) error { if dec.err != nil { return dec.err } @@ -53,11 +53,11 @@ func (dec *Decoder) Decode(v interface{}) os.Error { // readValue reads a JSON value into dec.buf. // It returns the length of the encoding. -func (dec *Decoder) readValue() (int, os.Error) { +func (dec *Decoder) readValue() (int, error) { dec.scan.reset() scanp := 0 - var err os.Error + var err error Input: for { // Look in the buffer for a new value. @@ -85,7 +85,7 @@ Input: // Did the last read have an error? // Delayed until now to allow buffer scan. if err != nil { - if err == os.EOF { + if err == io.EOF { if dec.scan.step(&dec.scan, ' ') == scanEnd { break Input } @@ -126,7 +126,7 @@ func nonSpace(b []byte) bool { type Encoder struct { w io.Writer e encodeState - err os.Error + err error } // NewEncoder returns a new encoder that writes to w. @@ -138,7 +138,7 @@ func NewEncoder(w io.Writer) *Encoder { // // See the documentation for Marshal for details about the // conversion of Go values to JSON. -func (enc *Encoder) Encode(v interface{}) os.Error { +func (enc *Encoder) Encode(v interface{}) error { if enc.err != nil { return enc.err } @@ -168,14 +168,14 @@ func (enc *Encoder) Encode(v interface{}) os.Error { type RawMessage []byte // MarshalJSON returns *m as the JSON encoding of m. -func (m *RawMessage) MarshalJSON() ([]byte, os.Error) { +func (m *RawMessage) MarshalJSON() ([]byte, error) { return *m, nil } // UnmarshalJSON sets *m to a copy of data. -func (m *RawMessage) UnmarshalJSON(data []byte) os.Error { +func (m *RawMessage) UnmarshalJSON(data []byte) error { if m == nil { - return os.NewError("json.RawMessage: UnmarshalJSON on nil pointer") + return errors.New("json.RawMessage: UnmarshalJSON on nil pointer") } *m = append((*m)[0:0], data...) return nil |