浏览代码

x/net/html/charset: Change NewReaderByName to NewReaderLabel.

Change-Id: Ic4d1df0c4f7048a3e2472cca09ef9390bcfd149d
Reviewed-on: https://go-review.googlesource.com/4533
Reviewed-by: Rob Pike <r@golang.org>
Andy Balholm 11 年之前
父节点
当前提交
6460565bec
共有 2 个文件被更改,包括 8 次插入8 次删除
  1. 7 7
      html/charset/charset.go
  2. 1 1
      html/charset/charset_test.go

+ 7 - 7
html/charset/charset.go

@@ -111,14 +111,14 @@ func NewReader(r io.Reader, contentType string) (io.Reader, error) {
 	return r, nil
 }
 
-// NewReaderByName returns a reader that converts from the specified charset to
-// UTF-8. It returns an error if the charset is not one of the standard
-// encodings for HTML. It is suitable for use as encoding/xml.Decoder's
-// CharsetReader function.
-func NewReaderByName(charset string, input io.Reader) (io.Reader, error) {
-	e, _ := Lookup(charset)
+// NewReaderLabel returns a reader that converts from the specified charset to
+// UTF-8. It uses Lookup to find the encoding that corresponds to label, and
+// returns an error if Lookup returns nil. It is suitable for use as
+// encoding/xml.Decoder's CharsetReader function.
+func NewReaderLabel(label string, input io.Reader) (io.Reader, error) {
+	e, _ := Lookup(label)
 	if e == nil {
-		return nil, fmt.Errorf("unsupported charset: %q", charset)
+		return nil, fmt.Errorf("unsupported charset: %q", label)
 	}
 	return transform.NewReader(input, e.NewDecoder()), nil
 }

+ 1 - 1
html/charset/charset_test.go

@@ -219,7 +219,7 @@ func TestXML(t *testing.T) {
 	const s = "<?xml version=\"1.0\" encoding=\"windows-1252\"?><a><Word>r\xe9sum\xe9</Word></a>"
 
 	d := xml.NewDecoder(strings.NewReader(s))
-	d.CharsetReader = NewReaderByName
+	d.CharsetReader = NewReaderLabel
 
 	var a struct {
 		Word string