1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
17 func ExampleWordEncoder_Encode() {
18 fmt
.Println(mime
.QEncoding
.Encode("utf-8", "¡Hola, señor!"))
19 fmt
.Println(mime
.QEncoding
.Encode("utf-8", "Hello!"))
20 fmt
.Println(mime
.BEncoding
.Encode("UTF-8", "¡Hola, señor!"))
21 fmt
.Println(mime
.QEncoding
.Encode("ISO-8859-1", "Caf\xE9"))
23 // =?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=
25 // =?UTF-8?b?wqFIb2xhLCBzZcOxb3Ih?=
26 // =?ISO-8859-1?q?Caf=E9?=
29 func ExampleWordDecoder_Decode() {
30 dec
:= new(mime
.WordDecoder
)
31 header
, err
:= dec
.Decode("=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=")
37 dec
.CharsetReader
= func(charset
string, input io
.Reader
) (io
.Reader
, error
) {
40 // Fake character set for example.
41 // Real use would integrate with packages such
42 // as code.google.com/p/go-charset
43 content
, err
:= ioutil
.ReadAll(input
)
47 return bytes
.NewReader(bytes
.ToUpper(content
)), nil
49 return nil, fmt
.Errorf("unhandled charset %q", charset
)
52 header
, err
= dec
.Decode("=?x-case?q?hello!?=")
62 func ExampleWordDecoder_DecodeHeader() {
63 dec
:= new(mime
.WordDecoder
)
64 header
, err
:= dec
.DecodeHeader("=?utf-8?q?=C3=89ric?= <eric@example.org>, =?utf-8?q?Ana=C3=AFs?= <anais@example.org>")
70 header
, err
= dec
.DecodeHeader("=?utf-8?q?=C2=A1Hola,?= =?utf-8?q?_se=C3=B1or!?=")
76 dec
.CharsetReader
= func(charset
string, input io
.Reader
) (io
.Reader
, error
) {
79 // Fake character set for example.
80 // Real use would integrate with packages such
81 // as code.google.com/p/go-charset
82 content
, err
:= ioutil
.ReadAll(input
)
86 return bytes
.NewReader(bytes
.ToUpper(content
)), nil
88 return nil, fmt
.Errorf("unhandled charset %q", charset
)
91 header
, err
= dec
.DecodeHeader("=?x-case?q?hello_?= =?x-case?q?world!?=")
97 // Éric <eric@example.org>, Anaïs <anais@example.org>