unicode

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package unicode implements unicode encoding and decoding with streaming support. It provides unicode encoding using strconv.QuoteToASCII for converting byte data to unicode escape sequences and back.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStreamDecoder

func NewStreamDecoder(r io.Reader) io.Reader

NewStreamDecoder creates a new streaming unicode decoder that reads encoded data from the provided io.Reader. The decoder uses strconv.Unquote.

func NewStreamEncoder

func NewStreamEncoder(w io.Writer) io.WriteCloser

NewStreamEncoder creates a new streaming unicode encoder that writes encoded data to the provided io.Writer. The encoder uses strconv.QuoteToASCII.

Types

type DecodeFailedError

type DecodeFailedError struct {
	Input string // The invalid input that caused the error
}

DecodeFailedError represents an error when unicode decoding fails. This error occurs when invalid unicode escape sequences are encountered during decoding operations.

func (DecodeFailedError) Error

func (e DecodeFailedError) Error() string

Error returns a formatted error message describing the decode failure.

type EncodeFailedError

type EncodeFailedError struct {
	Input string // The input that failed to encode
}

EncodeFailedError represents an error when unicode encoding fails. This error is rarely used since strconv.QuoteToASCII rarely fails.

func (EncodeFailedError) Error

func (e EncodeFailedError) Error() string

Error returns a formatted error message describing the encode failure.

type InvalidUnicodeError

type InvalidUnicodeError struct {
	Char string // The invalid unicode character that was found
}

InvalidUnicodeError represents an error when invalid unicode data is encountered. This error occurs when malformed unicode escape sequences are found.

func (InvalidUnicodeError) Error

func (e InvalidUnicodeError) Error() string

Error returns a formatted error message describing the invalid unicode.

type StdDecoder

type StdDecoder struct {
	Error error // Error field for storing decoding errors
}

StdDecoder represents a unicode decoder for standard decoding operations. It wraps strconv.Unquote to provide a consistent interface with error handling capabilities.

func NewStdDecoder

func NewStdDecoder() *StdDecoder

NewStdDecoder creates a new unicode decoder using strconv.Unquote.

func (*StdDecoder) Decode

func (d *StdDecoder) Decode(src []byte) (dst []byte, err error)

Decode decodes the given unicode-encoded byte slice back to binary data. Returns the decoded data and any error encountered during decoding. Returns an empty byte slice and nil error if the input is empty.

type StdEncoder

type StdEncoder struct {
	Error error // Error field for storing encoding errors
}

StdEncoder represents a unicode encoder for standard encoding operations. It wraps strconv.QuoteToASCII to provide a consistent interface with error handling capabilities.

func NewStdEncoder

func NewStdEncoder() *StdEncoder

NewStdEncoder creates a new unicode encoder using strconv.QuoteToASCII.

func (*StdEncoder) Encode

func (e *StdEncoder) Encode(src []byte) (dst []byte)

Encode encodes the given byte slice using unicode encoding. Returns an empty byte slice if the input is empty. The encoding process uses strconv.QuoteToASCII to convert bytes to unicode escape sequences.

type StreamDecoder

type StreamDecoder struct {
	Error error // Error field for storing decoding errors
	// contains filtered or unexported fields
}

StreamDecoder represents a streaming unicode decoder that implements io.Reader. It provides efficient decoding for large data streams by processing data in chunks and maintaining an internal buffer for partial reads.

func (*StreamDecoder) Read

func (d *StreamDecoder) Read(p []byte) (n int, err error)

Read implements the io.Reader interface for streaming unicode decoding. Reads and decodes unicode data from the underlying reader in chunks. Maintains an internal buffer to handle partial reads efficiently.

type StreamEncoder

type StreamEncoder struct {
	Error error // Error field for storing encoding errors
	// contains filtered or unexported fields
}

StreamEncoder represents a streaming unicode encoder that implements io.WriteCloser. It provides efficient encoding for large data streams by processing data in chunks and writing encoded output immediately.

func (*StreamEncoder) Close

func (e *StreamEncoder) Close() error

Close implements the io.Closer interface for streaming unicode encoding. Encodes any remaining buffered bytes from the last Write call. This is the only place where we handle cross-Write state.

func (*StreamEncoder) Write

func (e *StreamEncoder) Write(p []byte) (n int, err error)

Write implements the io.Writer interface for streaming unicode encoding. Processes data in chunks while maintaining minimal state for cross-Write calls. This is true streaming - processes data immediately without accumulating large buffers.

Source Files

  • errors.go
  • unicode.go

Jump to

Keyboard shortcuts

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