enc

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(toIanaName string, writer io.Writer, fromIanaName string, txt io.Reader) error

Convert function converts character encoding text stream.

Example
package main

import (
	"bytes"
	"fmt"
	"os"
	"strings"

	"github.com/goark/gnkf/dump"
	"github.com/goark/gnkf/enc"
)

func main() {
	buf := &bytes.Buffer{}
	if err := enc.Convert("Shift_JIS", buf, "UTF-8", strings.NewReader("こんにちは,世界!\n私の名前は Spiegel です。")); err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
	if err := dump.Octet(os.Stdout, buf); err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
}
Output:

0x82, 0xb1, 0x82, 0xf1, 0x82, 0xc9, 0x82, 0xbf, 0x82, 0xcd, 0x81, 0x43, 0x90, 0xa2, 0x8a, 0x45, 0x81, 0x49, 0x0a, 0x8e, 0x84, 0x82, 0xcc, 0x96, 0xbc, 0x91, 0x4f, 0x82, 0xcd, 0x20, 0x53, 0x70, 0x69, 0x65, 0x67, 0x65, 0x6c, 0x20, 0x82, 0xc5, 0x82, 0xb7, 0x81, 0x42

func Decode

func Decode(writer io.Writer, ianaName string, txt io.Reader) error

Decode converts from UTF-8 encodeing text.

func Encode

func Encode(ianaName string, writer io.Writer, txt io.Reader) error

Encode converts UTF-8 from other character encoding text.

func Encoding

func Encoding(ianaName string) (encoding.Encoding, error)

GetEncoding returns encoding.Encoding instance from MIME or IANA name

Types

This section is empty.

Jump to

Keyboard shortcuts

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