iconv

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(input []byte, output []byte, fromEncoding string, toEncoding string) (bytesRead int, bytesWritten int, err error)

func ConvertString

func ConvertString(input string, fromEncoding string, toEncoding string) (output string, err error)

ConvertString All in one ConvertString method, rather than requiring the construction of an iconv.Converter

func GB2312ToUTF8

func GB2312ToUTF8(in []byte) ([]byte, error)

func GB2312ToUTF8String

func GB2312ToUTF8String(in string) (string, error)

func GBKToUTF8

func GBKToUTF8(in []byte) ([]byte, error)

Types

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

func NewConverter

func NewConverter(fromEncoding string, toEncoding string) (converter *Converter, err error)

NewConverter Initialize a new Converter. If fromEncoding or toEncoding are not supported by iconv then an EINVAL error will be returned. An ENOMEM error maybe returned if there is not enough memory to initialize an iconv descriptor

func (*Converter) Close

func (c *Converter) Close() (err error)

Close a Converter's iconv description explicitly

func (*Converter) Convert

func (c *Converter) Convert(input []byte, output []byte) (bytesRead int, bytesWritten int, err error)

Convert bytes from an input byte slice into a give output byte slice

As many bytes that can converted and fit into the size of output will be processed and the number of bytes read for input as well as the number of bytes written to output will be returned. If not all converted bytes can fit into output and E2BIG error will also be returned. If input contains an invalid sequence of bytes for the Converter's fromEncoding an EILSEQ error will be returned

For shift based output encodings, any end shift byte sequences can be generated by passing a 0 length byte slice as input. Also passing a 0 length byte slice for output will simply reset the iconv descriptor shift state without writing any bytes.

func (*Converter) ConvertString

func (c *Converter) ConvertString(input string) (output string, err error)

ConvertString Convert an input string EILSEQ error may be returned if input contains invalid bytes for the Converter's fromEncoding.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func NewReader

func NewReader(source io.Reader, fromEncoding string, toEncoding string) (*Reader, error)

func NewReaderFromConverter

func NewReaderFromConverter(source io.Reader, converter *Converter) (reader *Reader)

func (*Reader) Read

func (c *Reader) Read(p []byte) (n int, err error)

implement the io.Reader interface

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(destination io.Writer, fromEncoding string, toEncoding string) (*Writer, error)

func NewWriterFromConverter

func NewWriterFromConverter(destination io.Writer, converter *Converter) (writer *Writer)

func (*Writer) Write

func (c *Writer) Write(p []byte) (n int, err error)

implement the io.Writer interface

Jump to

Keyboard shortcuts

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