codec

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 10 Imported by: 33 modules, 8 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidUTF8 = errors.New("invalid UTF-8")

ErrInvalidUTF8 is returned in ErrorModeStrict when the input to Encode or Count, or the output of Decode, is not valid UTF-8.

Functions

This section is empty.

Types

type Codec

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

func NewCl100kBase

func NewCl100kBase() *Codec

func NewO200kBase added in v0.2.0

func NewO200kBase() *Codec

func NewP50kBase

func NewP50kBase() *Codec

func NewP50kEdit

func NewP50kEdit() *Codec

func NewR50kBase

func NewR50kBase() *Codec

func (*Codec) Count added in v0.5.0

func (c *Codec) Count(input string) (int, error)

Count returns the number of tokens in the input string.

func (*Codec) Decode

func (c *Codec) Decode(tokens []uint) (string, error)

Decode returns the string for the input token IDs

func (*Codec) Encode

func (c *Codec) Encode(input string) ([]uint, []string, error)

Encode returns the token IDs and tokens for the input string.

func (*Codec) ErrorMode added in v0.9.0

func (c *Codec) ErrorMode() ErrorMode

ErrorMode returns the codec's current error mode.

func (*Codec) GetName

func (c *Codec) GetName() string

func (*Codec) SetErrorMode added in v0.9.0

func (c *Codec) SetErrorMode(mode ErrorMode)

SetErrorMode sets the codec's behavior for invalid UTF-8 sequences.

type ErrorMode added in v0.9.0

type ErrorMode int

ErrorMode controls how Encode, Count and Decode handle invalid UTF-8. See the tokenizer package for a description of each mode.

const (
	ErrorModeNone    ErrorMode = iota // return bytes unchanged (default)
	ErrorModeReplace                  // errors="replace"
	ErrorModeIgnore                   // errors="ignore"
	ErrorModeStrict                   // errors="strict"
)

Jump to

Keyboard shortcuts

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