Path: blob/main/vendor/golang.org/x/text/encoding/internal/internal.go
2893 views
// Copyright 2015 The Go Authors. All rights reserved.1// Use of this source code is governed by a BSD-style2// license that can be found in the LICENSE file.34// Package internal contains code that is shared among encoding implementations.5package internal67import (8"golang.org/x/text/encoding"9"golang.org/x/text/encoding/internal/identifier"10"golang.org/x/text/transform"11)1213// Encoding is an implementation of the Encoding interface that adds the String14// and ID methods to an existing encoding.15type Encoding struct {16encoding.Encoding17Name string18MIB identifier.MIB19}2021// _ verifies that Encoding implements identifier.Interface.22var _ identifier.Interface = (*Encoding)(nil)2324func (e *Encoding) String() string {25return e.Name26}2728func (e *Encoding) ID() (mib identifier.MIB, other string) {29return e.MIB, ""30}3132// SimpleEncoding is an Encoding that combines two Transformers.33type SimpleEncoding struct {34Decoder transform.Transformer35Encoder transform.Transformer36}3738func (e *SimpleEncoding) NewDecoder() *encoding.Decoder {39return &encoding.Decoder{Transformer: e.Decoder}40}4142func (e *SimpleEncoding) NewEncoder() *encoding.Encoder {43return &encoding.Encoder{Transformer: e.Encoder}44}4546// FuncEncoding is an Encoding that combines two functions returning a new47// Transformer.48type FuncEncoding struct {49Decoder func() transform.Transformer50Encoder func() transform.Transformer51}5253func (e FuncEncoding) NewDecoder() *encoding.Decoder {54return &encoding.Decoder{Transformer: e.Decoder()}55}5657func (e FuncEncoding) NewEncoder() *encoding.Encoder {58return &encoding.Encoder{Transformer: e.Encoder()}59}6061// A RepertoireError indicates a rune is not in the repertoire of a destination62// encoding. It is associated with an encoding-specific suggested replacement63// byte.64type RepertoireError byte6566// Error implements the error interface.67func (r RepertoireError) Error() string {68return "encoding: rune not supported by encoding."69}7071// Replacement returns the replacement string associated with this error.72func (r RepertoireError) Replacement() byte { return byte(r) }7374var ErrASCIIReplacement = RepertoireError(encoding.ASCIISub)757677