Some minor error handling fixes.

This commit is contained in:
jim teeuwen 2010-12-16 21:08:01 +01:00
parent 28e474f91f
commit 15ec07ab1a
2 changed files with 9 additions and 11 deletions

View File

@ -166,8 +166,8 @@ func (this *Document) LoadFile(filename string) (err os.Error) {
}
func (this *Document) LoadUri(uri string) (err os.Error) {
r, _, err := http.Get(uri)
if err != nil {
var r *http.Response
if r, _, err = http.Get(uri); err != nil {
return
}
@ -178,8 +178,7 @@ func (this *Document) LoadUri(uri string) (err os.Error) {
return
}
err = this.LoadString(string(b))
return
return this.LoadString(string(b))
}
func (this *Document) LoadStream(r io.Reader) (err os.Error) {
@ -193,8 +192,7 @@ func (this *Document) LoadStream(r io.Reader) (err os.Error) {
buf.Write(s)
}
err = this.LoadString(buf.String())
return
return this.LoadString(buf.String())
}
// *****************************************************************************
@ -220,10 +218,10 @@ func (this *Document) SaveString() (s string, err os.Error) {
}
func (this *Document) SaveStream(w io.Writer) (err os.Error) {
s, err := this.SaveString()
if err != nil {
var s string
if s, err = this.SaveString(); err != nil {
return
}
w.Write([]byte(s))
_, err = w.Write([]byte(s))
return
}

View File

@ -49,11 +49,11 @@ func EntityToUtf8(entity string) string {
}
var arr [4]byte
if size := utf8.EncodeRune(arr[0:], num); size == 0 {
if size := utf8.EncodeRune(arr[:], num); size == 0 {
return "&#" + entity + ";"
}
return string(arr[0:])
return string(arr[:])
}
// Converts a single Go utf8-token to a Html entity.