Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDecodeReader ¶
NewDecodeReader returns a io.Reader that reads from r and decode it with d. See also golang.org/x/text/transform.NewReader.
Example ¶
package main
import (
"fmt"
"io"
"strings"
"github.com/aileron-projects/go/zx/ztext/zencoding"
"golang.org/x/text/encoding/japanese"
)
func main() {
d := japanese.ShiftJIS.NewDecoder()
r := strings.NewReader("\xe0\x9f") // ShiftJIS string.
rr := zencoding.NewDecodeReader(d, r)
b, _ := io.ReadAll(rr) // UTF-8 string obtained.
fmt.Println(string(b))
}
Output: 燹
func NewDecodeWriter ¶
NewDecodeWriter returns a io.Writer that decode written bytes before write to w. See also golang.org/x/text/transform.NewWriter.
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/aileron-projects/go/zx/ztext/zencoding"
"golang.org/x/text/encoding/japanese"
)
func main() {
d := japanese.ShiftJIS.NewDecoder()
var w bytes.Buffer
ww := zencoding.NewDecodeWriter(d, &w)
ww.Write([]byte("\xe0\x9f")) // Write ShiftJIS string.
fmt.Println(w.String()) // UTF-8 string obtained.
}
Output: 燹
func NewEncodeReader ¶
NewEncodeReader returns a io.Reader that reads from r and encode it with e. See also golang.org/x/text/transform.NewReader.
Example ¶
package main
import (
"fmt"
"io"
"strings"
"github.com/aileron-projects/go/zx/ztext/zencoding"
"golang.org/x/text/encoding/japanese"
)
func main() {
e := japanese.ShiftJIS.NewEncoder()
r := strings.NewReader("燹") // UTF-8 string.
rr := zencoding.NewEncodeReader(e, r)
b, _ := io.ReadAll(rr) // ShiftJIS bytes.
fmt.Printf("%2x", b)
}
Output: e09f
func NewEncodeWriter ¶
NewEncodeWriter returns a io.Writer that encode written bytes before write to w. See also golang.org/x/text/transform.NewWriter.
Example ¶
package main
import (
"bytes"
"fmt"
"github.com/aileron-projects/go/zx/ztext/zencoding"
"golang.org/x/text/encoding/japanese"
)
func main() {
e := japanese.ShiftJIS.NewEncoder()
var w bytes.Buffer
ww := zencoding.NewEncodeWriter(e, &w)
ww.Write([]byte("燹")) // UTF-8 string.
fmt.Printf("%2x", w.Bytes()) // ShiftJIS bytes.
}
Output: e09f
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.