1
0
mirror of https://github.com/golang/go synced 2024-11-23 20:10:08 -07:00

mime: fix names of examples

The names of examples were wrong so they were not shown in
the documentation.

Change-Id: Ib1b985b44d2e056c38c008a591cb441e422c4717
Reviewed-on: https://go-review.googlesource.com/10404
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alexandre Cesaro 2015-05-27 12:38:55 +02:00 committed by Brad Fitzpatrick
parent 5c60a4fb0a
commit f04e7bb1cf

View File

@ -5,6 +5,7 @@
package mime
import (
"bytes"
"errors"
"fmt"
"io"
@ -13,7 +14,7 @@ import (
"testing"
)
func ExampleEncodeWord() {
func ExampleWordEncoder_Encode() {
fmt.Println(QEncoding.Encode("utf-8", "¡Hola, señor!"))
fmt.Println(QEncoding.Encode("utf-8", "Hello!"))
fmt.Println(BEncoding.Encode("UTF-8", "¡Hola, señor!"))
@ -25,17 +26,40 @@ func ExampleEncodeWord() {
// =?ISO-8859-1?q?Caf=E9?=
}
func ExampleDecodeWord() {
func ExampleWordDecoder_Decode() {
dec := new(WordDecoder)
header, err := dec.DecodeHeader("=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=")
header, err := dec.Decode("=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=")
if err != nil {
panic(err)
}
fmt.Println(header)
// Output: ¡Hola, señor!
dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
switch charset {
case "x-case":
// Fake character set for example.
// Real use would integrate with packages such
// as code.google.com/p/go-charset
content, err := ioutil.ReadAll(input)
if err != nil {
return nil, err
}
return bytes.NewReader(bytes.ToUpper(content)), nil
default:
return nil, fmt.Errorf("unhandled charset %q", charset)
}
}
header, err = dec.Decode("=?x-case?q?hello!?=")
if err != nil {
panic(err)
}
fmt.Println(header)
// Output:
// ¡Hola, señor!
// HELLO!
}
func ExampleDecodeHeader() {
func ExampleWordDecoder_DecodeHeader() {
dec := new(WordDecoder)
header, err := dec.DecodeHeader("=?utf-8?q?=C3=89ric?= <eric@example.org>, =?utf-8?q?Ana=C3=AFs?= <anais@example.org>")
if err != nil {
@ -48,9 +72,31 @@ func ExampleDecodeHeader() {
panic(err)
}
fmt.Println(header)
dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
switch charset {
case "x-case":
// Fake character set for example.
// Real use would integrate with packages such
// as code.google.com/p/go-charset
content, err := ioutil.ReadAll(input)
if err != nil {
return nil, err
}
return bytes.NewReader(bytes.ToUpper(content)), nil
default:
return nil, fmt.Errorf("unhandled charset %q", charset)
}
}
header, err = dec.DecodeHeader("=?x-case?q?hello_?= =?x-case?q?world!?=")
if err != nil {
panic(err)
}
fmt.Println(header)
// Output:
// Éric <eric@example.org>, Anaïs <anais@example.org>
// ¡Hola, señor!
// HELLO WORLD!
}
func TestEncodeWord(t *testing.T) {