decode

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToUTF8

func ToUTF8(txt io.Reader) (io.Reader, error)

ToUTF8 returns UTF-8 text from other encoding text (auto detection of encoding)

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/spiegel-im-spiegel/text/decode"
)

func main() {
	jisText := []byte{0x1b, 0x24, 0x42, 0x24, 0x33, 0x24, 0x73, 0x24, 0x4b, 0x24, 0x41, 0x24, 0x4f, 0x40, 0x24, 0x33, 0x26, 0x1b, 0x28, 0x42}
	res, err := decode.ToUTF8(bytes.NewReader(jisText))
	if err != nil {
		fmt.Println(err)
		return
	}
	buf := &bytes.Buffer{}
	if _, err := buf.ReadFrom(res); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(buf)
}
Output:

こんにちは世界

func ToUTF8From

func ToUTF8From(e detect.CharEncoding, txt io.Reader) (io.Reader, error)

ToUTF8From returns UTF-8 text from other encoding text

func ToUTF8ja

func ToUTF8ja(txt io.Reader) (io.Reader, error)

ToUTF8ja returns UTF-8 text from other encoding text (auto detection of japanses encoding)

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/spiegel-im-spiegel/text/decode"
)

func main() {
	jisText := []byte{0x1b, 0x24, 0x42, 0x24, 0x33, 0x24, 0x73, 0x24, 0x4b, 0x24, 0x41, 0x24, 0x4f, 0x40, 0x24, 0x33, 0x26, 0x1b, 0x28, 0x42}
	res, err := decode.ToUTF8ja(bytes.NewReader(jisText))
	if err != nil {
		fmt.Println(err)
		return
	}
	buf := &bytes.Buffer{}
	if _, err := buf.ReadFrom(res); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(buf)
}
Output:

こんにちは世界

Types

This section is empty.

Jump to

Keyboard shortcuts

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