summaryrefslogtreecommitdiff
path: root/libgo/go/xml
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/xml')
-rw-r--r--libgo/go/xml/marshal.go9
-rw-r--r--libgo/go/xml/marshal_test.go8
-rw-r--r--libgo/go/xml/read.go30
-rw-r--r--libgo/go/xml/xml.go21
-rw-r--r--libgo/go/xml/xml_test.go34
5 files changed, 49 insertions, 53 deletions
diff --git a/libgo/go/xml/marshal.go b/libgo/go/xml/marshal.go
index 8396dba27e9..691b70d2510 100644
--- a/libgo/go/xml/marshal.go
+++ b/libgo/go/xml/marshal.go
@@ -7,7 +7,6 @@ package xml
import (
"bufio"
"io"
- "os"
"reflect"
"strconv"
"strings"
@@ -23,7 +22,7 @@ const (
// A Marshaler can produce well-formatted XML representing its internal state.
// It is used by both Marshal and MarshalIndent.
type Marshaler interface {
- MarshalXML() ([]byte, os.Error)
+ MarshalXML() ([]byte, error)
}
type printer struct {
@@ -84,14 +83,14 @@ type printer struct {
// </result>
//
// Marshal will return an error if asked to marshal a channel, function, or map.
-func Marshal(w io.Writer, v interface{}) (err os.Error) {
+func Marshal(w io.Writer, v interface{}) (err error) {
p := &printer{bufio.NewWriter(w)}
err = p.marshalValue(reflect.ValueOf(v), "???")
p.Flush()
return err
}
-func (p *printer) marshalValue(val reflect.Value, name string) os.Error {
+func (p *printer) marshalValue(val reflect.Value, name string) error {
if !val.IsValid() {
return nil
}
@@ -300,6 +299,6 @@ type UnsupportedTypeError struct {
Type reflect.Type
}
-func (e *UnsupportedTypeError) String() string {
+func (e *UnsupportedTypeError) Error() string {
return "xml: unsupported type: " + e.Type.String()
}
diff --git a/libgo/go/xml/marshal_test.go b/libgo/go/xml/marshal_test.go
index eb358d5dcce..59007b36456 100644
--- a/libgo/go/xml/marshal_test.go
+++ b/libgo/go/xml/marshal_test.go
@@ -7,11 +7,9 @@ package xml
import (
"reflect"
"testing"
-
"bytes"
- "os"
- "strconv"
"strings"
+ "strconv"
)
type DriveType int
@@ -39,7 +37,7 @@ type Ship struct {
type RawXML string
-func (rx RawXML) MarshalXML() ([]byte, os.Error) {
+func (rx RawXML) MarshalXML() ([]byte, error) {
return []byte(rx), nil
}
@@ -342,7 +340,7 @@ func TestMarshalErrors(t *testing.T) {
for idx, test := range marshalErrorTests {
buf := bytes.NewBuffer(nil)
err := Marshal(buf, test.Value)
- if err == nil || err.String() != test.Err {
+ if err == nil || err.Error() != test.Err {
t.Errorf("#%d: marshal(%#v) = [error] %q, want %q", idx, test.Value, err, test.Err)
}
if kind := err.(*UnsupportedTypeError).Type.Kind(); kind != test.Kind {
diff --git a/libgo/go/xml/read.go b/libgo/go/xml/read.go
index 1fe20ac6147..a88941c92b3 100644
--- a/libgo/go/xml/read.go
+++ b/libgo/go/xml/read.go
@@ -6,9 +6,9 @@ package xml
import (
"bytes"
+ "errors"
"fmt"
"io"
- "os"
"reflect"
"strconv"
"strings"
@@ -150,10 +150,10 @@ import (
// Unmarshal maps an XML element to a pointer by setting the pointer
// to a freshly allocated value and then mapping the element to that value.
//
-func Unmarshal(r io.Reader, val interface{}) os.Error {
+func Unmarshal(r io.Reader, val interface{}) error {
v := reflect.ValueOf(val)
if v.Kind() != reflect.Ptr {
- return os.NewError("non-pointer passed to Unmarshal")
+ return errors.New("non-pointer passed to Unmarshal")
}
p := NewParser(r)
elem := v.Elem()
@@ -167,7 +167,7 @@ func Unmarshal(r io.Reader, val interface{}) os.Error {
// An UnmarshalError represents an error in the unmarshalling process.
type UnmarshalError string
-func (e UnmarshalError) String() string { return string(e) }
+func (e UnmarshalError) Error() string { return string(e) }
// A TagPathError represents an error in the unmarshalling process
// caused by the use of field tags with conflicting paths.
@@ -177,7 +177,7 @@ type TagPathError struct {
Field2, Tag2 string
}
-func (e *TagPathError) String() string {
+func (e *TagPathError) Error() string {
return fmt.Sprintf("%s field %q with tag %q conflicts with field %q with tag %q", e.Struct, e.Field1, e.Tag1, e.Field2, e.Tag2)
}
@@ -187,10 +187,10 @@ func (e *TagPathError) String() string {
// but also defers to Unmarshal for some elements.
// Passing a nil start element indicates that Unmarshal should
// read the token stream to find the start element.
-func (p *Parser) Unmarshal(val interface{}, start *StartElement) os.Error {
+func (p *Parser) Unmarshal(val interface{}, start *StartElement) error {
v := reflect.ValueOf(val)
if v.Kind() != reflect.Ptr {
- return os.NewError("non-pointer passed to Unmarshal")
+ return errors.New("non-pointer passed to Unmarshal")
}
return p.unmarshal(v.Elem(), start)
}
@@ -216,7 +216,7 @@ func fieldName(original string) string {
}
// Unmarshal a single XML element into val.
-func (p *Parser) unmarshal(val reflect.Value, start *StartElement) os.Error {
+func (p *Parser) unmarshal(val reflect.Value, start *StartElement) error {
// Find start element if we need it.
if start == nil {
for {
@@ -253,7 +253,7 @@ func (p *Parser) unmarshal(val reflect.Value, start *StartElement) os.Error {
switch v := val; v.Kind() {
default:
- return os.NewError("unknown type " + v.Type().String())
+ return errors.New("unknown type " + v.Type().String())
case reflect.Slice:
typ := v.Type()
@@ -482,7 +482,7 @@ Loop:
return nil
}
-func copyValue(dst reflect.Value, src []byte) (err os.Error) {
+func copyValue(dst reflect.Value, src []byte) (err error) {
// Helper functions for integer and unsigned integer conversions
var itmp int64
getInt64 := func() bool {
@@ -508,7 +508,7 @@ func copyValue(dst reflect.Value, src []byte) (err os.Error) {
case reflect.Invalid:
// Probably a comment, handled below
default:
- return os.NewError("cannot happen: unknown type " + t.Type().String())
+ return errors.New("cannot happen: unknown type " + t.Type().String())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
if !getInt64() {
return err
@@ -547,7 +547,7 @@ type pathInfo struct {
// paths map with all paths leading to it ("a", "a>b", and "a>b>c").
// It is okay for paths to share a common, shorter prefix but not ok
// for one path to itself be a prefix of another.
-func addFieldPath(sv reflect.Value, paths map[string]pathInfo, path string, fieldIdx []int) os.Error {
+func addFieldPath(sv reflect.Value, paths map[string]pathInfo, path string, fieldIdx []int) error {
if info, found := paths[path]; found {
return tagError(sv, info.fieldIdx, fieldIdx)
}
@@ -570,7 +570,7 @@ func addFieldPath(sv reflect.Value, paths map[string]pathInfo, path string, fiel
}
-func tagError(sv reflect.Value, idx1 []int, idx2 []int) os.Error {
+func tagError(sv reflect.Value, idx1 []int, idx2 []int) error {
t := sv.Type()
f1 := t.FieldByIndex(idx1)
f2 := t.FieldByIndex(idx2)
@@ -579,7 +579,7 @@ func tagError(sv reflect.Value, idx1 []int, idx2 []int) os.Error {
// unmarshalPaths walks down an XML structure looking for
// wanted paths, and calls unmarshal on them.
-func (p *Parser) unmarshalPaths(sv reflect.Value, paths map[string]pathInfo, path string, start *StartElement) os.Error {
+func (p *Parser) unmarshalPaths(sv reflect.Value, paths map[string]pathInfo, path string, start *StartElement) error {
if info, _ := paths[path]; info.complete {
return p.unmarshal(sv.FieldByIndex(info.fieldIdx), start)
}
@@ -611,7 +611,7 @@ func (p *Parser) unmarshalPaths(sv reflect.Value, paths map[string]pathInfo, pat
// Read tokens until we find the end element.
// Token is taking care of making sure the
// end element matches the start element we saw.
-func (p *Parser) Skip() os.Error {
+func (p *Parser) Skip() error {
for {
tok, err := p.Token()
if err != nil {
diff --git a/libgo/go/xml/xml.go b/libgo/go/xml/xml.go
index bc03c8e0d49..d534c52c1ca 100644
--- a/libgo/go/xml/xml.go
+++ b/libgo/go/xml/xml.go
@@ -18,7 +18,6 @@ import (
"bytes"
"fmt"
"io"
- "os"
"strconv"
"strings"
"unicode"
@@ -31,7 +30,7 @@ type SyntaxError struct {
Line int
}
-func (e *SyntaxError) String() string {
+func (e *SyntaxError) Error() string {
return "XML syntax error on line " + strconv.Itoa(e.Line) + ": " + e.Msg
}
@@ -168,7 +167,7 @@ type Parser struct {
// non-UTF-8 charset into UTF-8. If CharsetReader is nil or
// returns an error, parsing stops with an error. One of the
// the CharsetReader's result values must be non-nil.
- CharsetReader func(charset string, input io.Reader) (io.Reader, os.Error)
+ CharsetReader func(charset string, input io.Reader) (io.Reader, error)
r io.ByteReader
buf bytes.Buffer
@@ -180,7 +179,7 @@ type Parser struct {
nextToken Token
nextByte int
ns map[string]string
- err os.Error
+ err error
line int
tmp [32]byte
}
@@ -219,7 +218,7 @@ func NewParser(r io.Reader) *Parser {
// set to the URL identifying its name space when known.
// If Token encounters an unrecognized name space prefix,
// it uses the prefix as the Space rather than report an error.
-func (p *Parser) Token() (t Token, err os.Error) {
+func (p *Parser) Token() (t Token, err error) {
if p.nextToken != nil {
t = p.nextToken
p.nextToken = nil
@@ -354,7 +353,7 @@ func (p *Parser) pushNs(local string, url string, ok bool) {
}
// Creates a SyntaxError with the current line number.
-func (p *Parser) syntaxError(msg string) os.Error {
+func (p *Parser) syntaxError(msg string) error {
return &SyntaxError{Msg: msg, Line: p.line}
}
@@ -423,7 +422,7 @@ func (p *Parser) autoClose(t Token) (Token, bool) {
// RawToken is like Token but does not verify that
// start and end elements match and does not translate
// name space prefixes to their corresponding URLs.
-func (p *Parser) RawToken() (Token, os.Error) {
+func (p *Parser) RawToken() (Token, error) {
if p.err != nil {
return nil, p.err
}
@@ -777,7 +776,7 @@ func (p *Parser) savedOffset() int {
// and return ok==false
func (p *Parser) mustgetc() (b byte, ok bool) {
if b, ok = p.getc(); !ok {
- if p.err == os.EOF {
+ if p.err == io.EOF {
p.err = p.syntaxError("unexpected EOF")
}
}
@@ -813,7 +812,7 @@ Input:
b, ok := p.getc()
if !ok {
if cdata {
- if p.err == os.EOF {
+ if p.err == io.EOF {
p.err = p.syntaxError("unexpected EOF in CDATA section")
}
return nil
@@ -855,7 +854,7 @@ Input:
var ok bool
p.tmp[i], ok = p.getc()
if !ok {
- if p.err == os.EOF {
+ if p.err == io.EOF {
p.err = p.syntaxError("unexpected EOF")
}
return nil
@@ -888,7 +887,7 @@ Input:
var text string
if i >= 2 && s[0] == '#' {
var n uint64
- var err os.Error
+ var err error
if i >= 3 && s[1] == 'x' {
n, err = strconv.Btoui64(s[2:], 16)
} else {
diff --git a/libgo/go/xml/xml_test.go b/libgo/go/xml/xml_test.go
index 64076240557..1b40d0c4d41 100644
--- a/libgo/go/xml/xml_test.go
+++ b/libgo/go/xml/xml_test.go
@@ -162,9 +162,9 @@ type stringReader struct {
off int
}
-func (r *stringReader) Read(b []byte) (n int, err os.Error) {
+func (r *stringReader) Read(b []byte) (n int, err error) {
if r.off >= len(r.s) {
- return 0, os.EOF
+ return 0, io.EOF
}
for r.off < len(r.s) && n < len(b) {
b[n] = r.s[r.off]
@@ -174,9 +174,9 @@ func (r *stringReader) Read(b []byte) (n int, err os.Error) {
return
}
-func (r *stringReader) ReadByte() (b byte, err os.Error) {
+func (r *stringReader) ReadByte() (b byte, err error) {
if r.off >= len(r.s) {
- return 0, os.EOF
+ return 0, io.EOF
}
b = r.s[r.off]
r.off++
@@ -195,7 +195,7 @@ type downCaser struct {
r io.ByteReader
}
-func (d *downCaser) ReadByte() (c byte, err os.Error) {
+func (d *downCaser) ReadByte() (c byte, err error) {
c, err = d.r.ReadByte()
if c >= 'A' && c <= 'Z' {
c += 'a' - 'A'
@@ -203,7 +203,7 @@ func (d *downCaser) ReadByte() (c byte, err os.Error) {
return
}
-func (d *downCaser) Read(p []byte) (int, os.Error) {
+func (d *downCaser) Read(p []byte) (int, error) {
d.t.Fatalf("unexpected Read call on downCaser reader")
return 0, os.EINVAL
}
@@ -211,7 +211,7 @@ func (d *downCaser) Read(p []byte) (int, os.Error) {
func TestRawTokenAltEncoding(t *testing.T) {
sawEncoding := ""
p := NewParser(StringReader(testInputAltEncoding))
- p.CharsetReader = func(charset string, input io.Reader) (io.Reader, os.Error) {
+ p.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
sawEncoding = charset
if charset != "x-testing-uppercase" {
t.Fatalf("unexpected charset %q", charset)
@@ -238,7 +238,7 @@ func TestRawTokenAltEncodingNoConverter(t *testing.T) {
t.Fatalf("expected an error on second RawToken call")
}
const encoding = "x-testing-uppercase"
- if !strings.Contains(err.String(), encoding) {
+ if !strings.Contains(err.Error(), encoding) {
t.Errorf("expected error to contain %q; got error: %v",
encoding, err)
}
@@ -319,7 +319,7 @@ func TestToken(t *testing.T) {
func TestSyntax(t *testing.T) {
for i := range xmlInput {
p := NewParser(StringReader(xmlInput[i]))
- var err os.Error
+ var err error
for _, err = p.Token(); err == nil; _, err = p.Token() {
}
if _, ok := err.(*SyntaxError); !ok {
@@ -501,7 +501,7 @@ func TestCopyTokenStartElement(t *testing.T) {
func TestSyntaxErrorLineNum(t *testing.T) {
testInput := "<P>Foo<P>\n\n<P>Bar</>\n"
p := NewParser(StringReader(testInput))
- var err os.Error
+ var err error
for _, err = p.Token(); err == nil; _, err = p.Token() {
}
synerr, ok := err.(*SyntaxError)
@@ -516,10 +516,10 @@ func TestSyntaxErrorLineNum(t *testing.T) {
func TestTrailingRawToken(t *testing.T) {
input := `<FOO></FOO> `
p := NewParser(StringReader(input))
- var err os.Error
+ var err error
for _, err = p.RawToken(); err == nil; _, err = p.RawToken() {
}
- if err != os.EOF {
+ if err != io.EOF {
t.Fatalf("p.RawToken() = _, %v, want _, os.EOF", err)
}
}
@@ -527,10 +527,10 @@ func TestTrailingRawToken(t *testing.T) {
func TestTrailingToken(t *testing.T) {
input := `<FOO></FOO> `
p := NewParser(StringReader(input))
- var err os.Error
+ var err error
for _, err = p.Token(); err == nil; _, err = p.Token() {
}
- if err != os.EOF {
+ if err != io.EOF {
t.Fatalf("p.Token() = _, %v, want _, os.EOF", err)
}
}
@@ -538,10 +538,10 @@ func TestTrailingToken(t *testing.T) {
func TestEntityInsideCDATA(t *testing.T) {
input := `<test><![CDATA[ &val=foo ]]></test>`
p := NewParser(StringReader(input))
- var err os.Error
+ var err error
for _, err = p.Token(); err == nil; _, err = p.Token() {
}
- if err != os.EOF {
+ if err != io.EOF {
t.Fatalf("p.Token() = _, %v, want _, os.EOF", err)
}
}
@@ -570,7 +570,7 @@ func TestDisallowedCharacters(t *testing.T) {
for i, tt := range characterTests {
p := NewParser(StringReader(tt.in))
- var err os.Error
+ var err error
for err == nil {
_, err = p.Token()