GO語言"mime"包中"WordDecoder.Decode"類型的用法及代碼示例。
用法:
func(d *WordDecoder) Decode(word string)(string, error)
Decode 對 RFC 2047 encoded-word 進行解碼。
例子:
package main
import (
"bytes"
"fmt"
"io"
"mime"
)
func main() {
dec := new(mime.WordDecoder)
header, err := dec.Decode("=?utf-8?q?=C2=A1Hola,_se=C3=B1or!?=")
if err != nil {
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 := io.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)
}
輸出:
¡Hola, señor! HELLO!
相關用法
- GO WordDecoder.DecodeHeader用法及代碼示例
- GO WordEncoder.Encode用法及代碼示例
- GO WithDeadline用法及代碼示例
- GO Writer.Init用法及代碼示例
- GO WaitGroup用法及代碼示例
- GO Writer.WriteAll用法及代碼示例
- GO WriteFile用法及代碼示例
- GO Writer.RegisterCompressor用法及代碼示例
- GO WithValue用法及代碼示例
- GO WalkDir用法及代碼示例
- GO WithTimeout用法及代碼示例
- GO Writer用法及代碼示例
- GO WriteString用法及代碼示例
- GO Write用法及代碼示例
- GO WithCancel用法及代碼示例
- GO Writer.AvailableBuffer用法及代碼示例
- GO Walk用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO LeadingZeros32用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 WordDecoder.Decode。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。