iconv

package module
v0.0.0-...-a968cfb Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: BSD-2-Clause Imports: 4 Imported by: 0

README

test-iconv

Documentation

Overview

Wraps the iconv API present on most systems, which allows for conversion of bytes from one encoding to another. This package additionally provides some convenient interface implementations like a Reader and Writer.

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)

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

func ConvertString

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

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

Types

type Converter

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

func NewConverter

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

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 (this *Converter) Close() (err error)

Close a Converter's iconv description explicitly

func (*Converter) Convert

func (this *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 (this *Converter) ConvertString(input string) (output string, err error)

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 (this *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 (this *Writer) Write(p []byte) (n int, err error)

implement the io.Writer interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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