1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
package charset_test
import (
"bytes"
"fmt"
"github.com/paulrosania/go-charset/charset"
_ "github.com/paulrosania/go-charset/data"
"io/ioutil"
"log"
"strings"
)
func ExampleNewReader() {
r, err := charset.NewReader("latin1", strings.NewReader("\xa35 for Pepp\xe9"))
if err != nil {
log.Fatal(err)
}
result, err := ioutil.ReadAll(r)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", result)
// Output: £5 for Peppé
}
func ExampleNewWriter() {
buf := new(bytes.Buffer)
w, err := charset.NewWriter("latin1", buf)
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(w, "£5 for Peppé")
w.Close()
fmt.Printf("%q\n", buf.Bytes())
// Output: "\xa35 for Pepp\xe9"
}
|