charsetutil

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: BSD-2-Clause Imports: 8 Imported by: 11

README

charsetutil - An easiest way to convert character set encodings in Go

charsetutil provides easiest way to convert character set encodings in Go.

Install

go get github.com/yuin/charsetutil

Utilities

  • Decode* : Converts from the specified charset to UTF-8.

  • Encode* : Converts from the UTF-8 to specified charset.

  • Guess* : Guesses a charcter set.

  • MustDecode* : Same as Decode*, but panics when errors occur

  • MustEncode* : Same as Encode*, but panics when errors occur

b, err = EncodeString("こんにちわ", "Windows-31J")
b, err = Encode("こんにちわ", "Windows-31J")
b, err = EncodeBytes([]byte("こんにちわ"), "Windows-31J")
b, err = EncodeReader(strings.NewReader("こんにちわ"), "Windows-31J")
b = MustEncodeString("こんにちわ", "Windows-31J")
b = MustEncode("こんにちわ", "Windows-31J")
b = MustEncodeBytes([]byte("こんにちわ"), "Windows-31J")
b = MustEncodeReader(strings.NewReader("こんにちわ"), "Windows-31J")

s, err = DecodeString(string(source), "Windows-31J")
s, err = Decode(source, "Windows-31J")
s, err = DecodeBytes(source, "Windows-31J")
s, err = DecodeReader(bytes.NewReader(source), "Windows-31J")
s = MustDecodeString(string(source), "Windows-31J")
s = MustDecode(source, "Windows-31J")
s = MustDecodeBytes(source, "Windows-31J")
s = MustDecodeReader(bytes.NewReader(source), "Windows-31J")

cs, err := GuessString(string(source))
cs, err := GuessBytes(source)
cs, err := GuessReader(bytes.NewReader(source))
cs, err := Guess(source)

Supported character sets

See Encoding spec on WHATWG

Author

Yusuke Inuzuka

License

BSD License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(s []byte, enc string) (string, error)

DecodeBytes converts given bytes to a UTF-8 string

func DecodeBytes

func DecodeBytes(s []byte, enc string) (string, error)

DecodeBytes converts given bytes to a UTF-8 string

func DecodeReader

func DecodeReader(s io.Reader, enc string) (string, error)

DecodeReader converts given Reader to a UTF-8 string

func DecodeString

func DecodeString(s, enc string) (string, error)

DecodeString converts given string to a UTF-8 string

func Encode

func Encode(s string, enc string) ([]byte, error)

Encode converts a string to bytes encoded with given encoding

func EncodeBytes

func EncodeBytes(s []byte, enc string) ([]byte, error)

EncodeBytes converts bytes to bytes encoded with given encoding

func EncodeReader

func EncodeReader(s io.Reader, enc string) ([]byte, error)

EncodeReader converts a Reader to bytes encoded with given encoding

func EncodeString

func EncodeString(s, enc string) ([]byte, error)

EncodeString converts a string to bytes encoded with given encoding

func MustDecode

func MustDecode(s []byte, enc string) string

MustDecodeBytes converts given bytes to a UTF-8 string and panics if errros occur.

func MustDecodeBytes

func MustDecodeBytes(s []byte, enc string) string

MustDecodeBytes converts given bytes to a UTF-8 string and panics if errros occur.

func MustDecodeReader

func MustDecodeReader(s io.Reader, enc string) string

MustDecodeReader converts given Reader to a UTF-8 string and panics if errros occur.

func MustDecodeString

func MustDecodeString(s, enc string) string

MustDecodeString converts given string to a UTF-8 string and panics if errros occur.

func MustEncode

func MustEncode(s string, enc string) []byte

MustEncode converts a bytes to bytes encoded with given encoding and panics if errors occur

func MustEncodeBytes

func MustEncodeBytes(s []byte, enc string) []byte

MustEncodeBytes converts a bytes to bytes encoded with given encoding and panics if errors occur

func MustEncodeReader

func MustEncodeReader(s io.Reader, enc string) []byte

MustEncodeReader converts a Reader to bytes encoded with given encoding and panics if errors occur

func MustEncodeString

func MustEncodeString(s, enc string) []byte

MustEncodeString converts a bytes to bytes encoded with given encoding and panics if errors occur

Types

type CharsetGuess

type CharsetGuess interface {
	// Charset returns a guessed charcter set
	Charset() string

	// Language returns a guessed language
	Language() string

	// Confidence returns a confidence of this guess
	Confidence() int
}

CharsetGuess is a guessd charcter set

func Guess

func Guess(s []byte) (CharsetGuess, error)

Guess guesses a character set of given bytes

func GuessBytes

func GuessBytes(s []byte) (CharsetGuess, error)

GuessBytes guesses a character set of given bytes

func GuessReader

func GuessReader(s io.Reader) (CharsetGuess, error)

GuessBytes guesses a character set of given Reader

func GuessString

func GuessString(s string) (CharsetGuess, error)

GuessBytes guesses a character set of given string

Jump to

Keyboard shortcuts

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