zencoding

package
v0.0.0-alpha.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDecodeReader

func NewDecodeReader(d *encoding.Decoder, r io.Reader) io.Reader

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

func NewDecodeWriter(d *encoding.Decoder, w io.Writer) io.Writer

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

func NewEncodeReader(e *encoding.Encoder, r io.Reader) io.Reader

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

func NewEncodeWriter(e *encoding.Encoder, w io.Writer) io.Writer

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL