Documentation ¶
Index ¶
- Constants
- Variables
- func AesDe(encrypted string, k string) (string, error)
- func AesEn(text string, k string) (string, error)
- func Append(t Transformer, dst, src []byte) (result []byte, n int, err error)
- func Ask(str string, check func(string) error) string
- func Associate[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
- func Authcode(text string, params ...interface{}) string
- func Average[T Integer | Float](numbers ...T) T
- func Base642Img(path, data string) (ps string)
- func Base64Decode(s string, isurl bool) string
- func Base64Encode(s string, isurl bool) (s1 string)
- func Bytes(t Transformer, b []byte) (result []byte, n int, err error)
- func Choose(question string, choices map[string]string) string
- func Chunk[T any](collection []T, size int) [][]T
- func ChunkString[T ~string](str T, size int) []T
- func ColorHexToRGB(colorHex string) (red, green, blue int)
- func ColorRGBToHex(red, green, blue int) string
- func Compact[T comparable](collection []T) []T
- func Confirm(question string) bool
- func Contain[T comparable](slice []T, target T) bool
- func ContainSubSlice[T comparable](slice, subSlice []T) bool
- func CopyFile(srcPath string, dstPath string) error
- func CreateDir(absPath string) error
- func CreateFile(path string) bool
- func CurrentPath() string
- func Date(format string, ts ...time.Time) string
- func DownloadFile(filepath string, url string) error
- func Drop[T any](collection []T, n int) []T
- func DropRight[T any](collection []T, n int) []T
- func DropRightWhile[T any](collection []T, predicate func(item T) bool) []T
- func DropWhile[T any](collection []T, predicate func(item T) bool) []T
- func Emoji(s string) (ss string)
- func EmojiDecode(s string) string
- func EmojiEncode(s string) string
- func Empty[T any]() T
- func EncodeUrl(urlStr string) (string, error)
- func Err(err error)
- func FileCount(sizes int64) string
- func FileSize(path string) (int64, error)
- func Filter[V any](collection []V, predicate func(item V, index int) bool) []V
- func FilterMap[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
- func Flatten[T any](collection [][]T) []T
- func ForEach[T any](collection []T, iteratee func(item T, index int))
- func ForEachMap[K comparable, V any](m map[K]V, iteratee func(key K, value V))
- func Gbk2Utf8(gbkStr string) string
- func Get(u string) string
- func GetAppPath() string
- func GetIp() string
- func GetOsBits() int
- func GetPinyin(s, sp string) (pinyin, shortpinyin string)
- func GetWeekday(ri string) string
- func HasKey[K comparable, V any](m map[K]V, key K) bool
- func Hash(password string, salt ...string) (ps string, err error)
- func HashBytes(password []byte, salt ...[]byte) (hash []byte, err error)
- func HideString(origin string, start, end int, replaceChar string) string
- func HideTel(phone string) (str string)
- func HtmlDecode(s string) string
- func HtmlEncode(s string) string
- func Img2Base64(filename string) (s string)
- func InsertAt[T any](slice []T, index int, value any) []T
- func Intersect[T comparable](list1 []T, list2 []T) []T
- func Invert[K comparable, V comparable](in map[K]V) map[V]K
- func IsASCII(str string) bool
- func IsAsc[T Ordered](slice []T) bool
- func IsBase64(base64 string) bool
- func IsChinese(s string) bool
- func IsChineseIdNum(id string) bool
- func IsDesc[T Ordered](slice []T) bool
- func IsDir(path string) bool
- func IsEmail(email string) bool
- func IsEmpty[T comparable](v T) bool
- func IsExist(path string) bool
- func IsFloat(v any) bool
- func IsGBK(data []byte) bool
- func IsInt(v any) bool
- func IsIp(ipstr string) bool
- func IsJSON(str string) bool
- func IsLeapYear(year int) bool
- func IsLinux() bool
- func IsMac() bool
- func IsMobile(mobileNum string) bool
- func IsNumber(v any) bool
- func IsSorted[T Ordered](slice []T) bool
- func IsStrongPassword(password string, length int) bool
- func IsUrl(str string) bool
- func IsUtf8(s string) bool
- func IsWeekend(t time.Time) bool
- func IsWeixin(r *http.Request) bool
- func IsWindows() bool
- func IsZipFile(filepath string) bool
- func Join[T any](slice []T, separator string) string
- func Keys[K comparable, V any](in map[K]V) []K
- func Last[T any](collection []T) (T, error)
- func ListFile(path string) ([]string, error)
- func MTime(filepath string) (int64, error)
- func Map[T any, U any](slice []T, iteratee func(index int, item T) U) []U
- func Map2Http(param map[string]any) string
- func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(key K, value V) R) []R
- func Match(password, hash string) bool
- func MatchBytes(password []byte, hash []byte) bool
- func Max[T Ordered](collection []T) T
- func Md5(s string) string
- func Merge[T any](slices ...[]T) []T
- func MergeMap[K comparable, V any](maps ...map[K]V) map[K]V
- func MiMeType(file any) string
- func MicroTime() float64
- func Min[T Ordered](collection []T) T
- func NumberFormat(number float64, decimals int, decPoint, thousandsSep string) string
- func Openurl(url string)
- func PasswordHash(password string) (string, error)
- func PasswordVerify(password, hash string) bool
- func Percent(val, total float64, n int) float64
- func PointDistance(x1, y1, x2, y2 float64) float64
- func RandColor() string
- func RandInt(min, max int) int
- func RandomString(size int, charset []rune) string
- func Range[T Integer | Float](start T, elementNum int) []T
- func RangeWithStep[T Integer | Float](start, end, step T) []T
- func ReadCsvFile(filepath string) ([][]string, error)
- func ReadFile(path string) (string, error)
- func ReadFileByLine(path string) ([]string, error)
- func RemoveFile(path string) error
- func Reverse[T any](collection []T) []T
- func RoundToFloat(x float64, n int) float64
- func RoundToString(x float64, n int) string
- func RuneLength(str string) int
- func Salt(rounds ...int) (string, error)
- func SaltBytes(rounds ...int) (salt []byte, err error)
- func Sample[T any](collection []T) T
- func Samples[T any](collection []T, count int) []T
- func SendEmail(from string, to1 string, subject string, body string, secret string, ...) (err error)
- func Sha1(str string) string
- func Sha256(str string) string
- func Shuffle[T any](collection []T) []T
- func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
- func Sort[T Ordered](slice []T, sortOrder ...string)
- func SplitStr(str, delimiter string, characterMask ...string) []string
- func Str2Time(s string) int64
- func String(t Transformer, s string) (result string, n int, err error)
- func StripTags(content string) string
- func StructToMap(value any) map[string]any
- func Substring(s string, offset int, length uint) string
- func Sum[T Float | Integer | Complex](collection []T) T
- func TableArr(s string) [][]string
- func Ternary[T any](condition bool, ifOutput T, elseOutput T) T
- func TernaryF[T any](condition bool, ifFunc func() T, elseFunc func() T) T
- func Time() int64
- func TimeLine(t int64) string
- func Timestr2Time(str string) time.Time
- func ToBool(s string) (bool, error)
- func ToBytes(value any) ([]byte, error)
- func ToChar(s string) []string
- func ToFloat(value any) (float64, error)
- func ToInt(value any) (int64, error)
- func ToInterface(v reflect.Value) (value interface{}, ok bool)
- func ToJson(value any) (string, error)
- func ToMap[T any, K comparable, V any](array []T, iteratee func(T) (K, V)) map[K]V
- func ToString(value any) string
- func Trim(str string, characterMask ...string) string
- func TruncRound(x float64, n int) float64
- func Typeof(a any) reflect.Type
- func UUIdV4() (string, error)
- func UnZip(zipFile string, destPath string) error
- func Unicode2utf8(str string) string
- func Union[T comparable](slices ...[]T) []T
- func Uniq[T comparable](collection []T) []T
- func Uniqid(prefix string) string
- func Unix2Time(t int64) time.Time
- func Utf2Gbk(str string) string
- func Utf82unicode(str string) string
- func Values[K comparable, V any](in map[K]V) []V
- func WriteCsvFile(filepath string, records [][]string, append bool) error
- func WriteFile(filepath string, content string, append bool) error
- func Zip(path string, destPath string) error
- func ZipAppendEntry(fpath string, destPath string) error
- type Complex
- type Decoder
- type Encoder
- type Encoding
- type Encoding1
- type Float
- type FuncEncoding
- type Integer
- type Interface
- type MIB
- type NopResetter
- type Ordered
- type Reader
- type RepertoireError
- type Signed
- type SimpleEncoding
- type SpanningTransformer
- type Transformer
- type Unsigned
- type Writer
Constants ¶
const ( MaxRounds = 31 MinRounds = 4 DefaultRounds = 12 SaltLen = 16 BlowfishRounds = 16 )
const ASCIISub = '\x1a'
ASCIISub is the ASCII substitute character, as recommended by https://unicode.org/reports/tr36/#Text_Comparison
Variables ¶
var ( InvalidRounds = errors.New("bcrypt: Invalid rounds parameter") InvalidSalt = errors.New("bcrypt: Invalid salt supplied") )
var ( // ErrShortDst means that the destination buffer was too short to // receive all of the transformed bytes. ErrShortDst = errors.New("transform: short destination buffer") // ErrShortSrc means that the source buffer has insufficient data to // complete the transformation. ErrShortSrc = errors.New("transform: short source buffer") // ErrEndOfSpan means that the input and output (the transformed input) // are not identical. ErrEndOfSpan = errors.New("transform: input and output are not identical") )
编码转换
var ( // Discard is a Transformer for which all Transform calls succeed // by consuming all bytes and writing nothing. Discard Transformer = discard{} // Nop is a SpanningTransformer that copies src to dst. Nop SpanningTransformer = nop{} )
var ConfirmNoRegex = regexp.MustCompile(`^(?i)no?$`)
var ConfirmRejection = "<warn>Please respond with \"y\" or \"n\"\n\n"
var ConfirmYesRegex = regexp.MustCompile(`^(?i)y(es)?$`)
var ( // DefaultTrimChars are the characters which are stripped by Trim* functions in default. DefaultTrimChars = string([]byte{ '\t', '\v', '\n', '\r', '\f', ' ', 0x00, 0x85, 0xA0, }) )
var ErrASCIIReplacement = RepertoireError(ASCIISub)
var ErrInvalidUTF8 = errors.New("encoding: invalid UTF-8")
ErrInvalidUTF8 means that a transformer encountered invalid UTF-8.
var RenderChooseOption = func(key, value string, size int) string { return fmt.Sprintf("%-"+fmt.Sprintf("%d", size+1)+"s %s\n", key+")", value) }
var RenderChooseQuery = func() string {
return "Choose: "
}
var RenderChooseQuestion = func(question string) string {
return question + "\n"
}
cli选择
var UTF8ValidatorTransformer = utf8Validator{}
UTF8Validator is a transformer that returns ErrInvalidUTF8 on the first input byte that is not valid UTF-8.
Functions ¶
func AesEn ¶
*
- @Description: Aes加密
- @param text
- @param key ,分别代表AES-128, AES-192和 AES-256
- @return string
- @return error
func Append ¶
func Append(t Transformer, dst, src []byte) (result []byte, n int, err error)
Append appends the result of converting src[:n] using t to dst, where n <= len(src), If err == nil, n will be len(src). It calls Reset on t.
func Ask ¶
*
- @Description: cli实现提示输入 qq:=php.Ask("请输入",nil)
- @param str 提示字符串
- @param check nil
- @return string
func Associate ¶
func Associate[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
Associate[T any, K comparable, V any]
@Description: scile处理成map Associate([]string("a","bb","cc"), func(str string) (string, int) { return str, len(str) }) @param collection @param transform @return map[K]V
func Authcode ¶
*
- @Description: 对称加密解密函数
- @param text 要加密或解密字符串
- @param false解码 true加密
密钥 字符串 s:=php.Authcode("1234==+wo我们",true,"abc") s=php.Authcode(s,false,"abc")
- @return string
func Base642Img ¶
*
- @Description: base64还原成图片
- @param path 当前 . qq/ss 最后不要带/
- @param data 上传的base64
- @return ps 路径
func Base64Decode ¶
*
- @Description: 解码base64 str=php.Base64Decode(str,false)
- @param s 要解码字符串
- @param isurl 是否url
- @return string
func Base64Encode ¶
func Bytes ¶
func Bytes(t Transformer, b []byte) (result []byte, n int, err error)
Bytes returns a new byte slice with the result of converting b[:n] using t, where n <= len(b). If err == nil, n will be len(b). It calls Reset on t.
func Choose ¶
*
- @Description: cli选择
- @param question 提示内容
- @param choices map[string]string{ "1": "苹果", "2": "橘子", "3": "西瓜", }
- @return string 返回key
func Chunk ¶
Chunk[T any] Chunk([]int(1,2,3,4), 2) [1,2] [3,4]
@Description: 分割数组,切片,按照个数组成新的切片 @param collection @param size @return [][]T
func ChunkString ¶
ChunkString[T ~string] ChunkString("123456", 2) [1,2][3,4][5,6]
@Description: 分割字符串 @param str @param size @return []T
func Compact ¶
func Compact[T comparable](collection []T) []T
Compact[T comparable] []string{"", "foo", "", "bar", ""} 返回["foo","bar"]
@Description: 返回非空切片的新切片 @param collection @return []T
func Contain ¶
func Contain[T comparable](slice []T, target T) bool
Contains[T comparable]
@Description: 判断sclie是否包含元素 @param collection @param element @return bool
func DropRightWhile ¶
右边条件删除
func DropWhile ¶
DropWhile[T any]
@Description: 左边开始条件删除 @param collection DropWhile(list, func(val int) bool { return val > 2 }) @return []T
func Filter ¶
Filter[V any] Filter([]int64{1, 2, 3, 4},func(a int64,i int)bool{ 返回被2整除 return a%2 ==0 })
@Description:刷选集合中元素 @param collection @param predicate @return []V
func FilterMap ¶
func FilterMap[K comparable, V any](m map[K]V, predicate func(key K, value V) bool) map[K]V
func Flatten ¶
func Flatten[T any](collection [][]T) []T
Flatten[T any] [][]int{{0, 1, 2}, {3, 4, 5}}=> [0,1,2,3,4,5]
@Description: 转换数组维度 @param collection @return []T
func ForEach ¶
ForEach[T any]
@Description: scile循环处理 @param collection item值 index是key @param iteratee
func ForEachMap ¶
func ForEachMap[K comparable, V any](m map[K]V, iteratee func(key K, value V))
处理map
func HasKey ¶
func HasKey[K comparable, V any](m map[K]V, key K) bool
HasKey[K comparable, V any]
@Description:检查 map 是否包含某个 key @param m mp := map[string]string{"a": "中国", "b": "日本"} fmt.Println(yo.HasKey(mp, "a")) @param key @return bool
func HideString ¶
HideString
@Description: 隐藏字符串特定位置 @param origin @param start @param end @param replaceChar @return string
func Img2Base64 ¶
*
- @Description: 图片转换成base64
filename:="1.jpg" s:=php.Img2Base64(filename)
- @param filename
- @return s
func InsertAt ¶
InsertAt[T any]
@Description: 在scile索引位置插入值 @param slice @param index @param value @return []T
func Intersect ¶
func Intersect[T comparable](list1 []T, list2 []T) []T
Intersect[T comparable] list1 := []int{0, 1, 2, 3, 4, 3}
list2 := []int{3, 4, 3} @Description: 两个切片 交集 @param list1 @param list2 @return []T
func Invert ¶
func Invert[K comparable, V comparable](in map[K]V) map[V]K
Invert[K comparable, V comparable] kv := map[string]int{"foo": 1, "bar": 2, "baz": 3, "new": 3}
@Description: 键值交换 @param in @return map[V]K
func IsEmpty ¶
func IsEmpty[T comparable](v T) bool
IsEmpty[T comparable]
@Description: 是否为空 0 "" 是空 @param v @return bool
func IsStrongPassword ¶
验证字符串是否是强密码:(字母+数字+特殊字符)
func Join ¶
Join[T any]
@Description:用指定的分隔符链接切片元素 @param slice 切片转换字符串 @param separator Join(nums, ",") @return string
func Keys ¶
func Keys[K comparable, V any](in map[K]V) []K
------------------字典开始----------------------- Keys[K comparable, V any]
@Description: 返回字典key @param in @return []K
func Map ¶
Map[T any, U any]
@Description:对 slice 中的每个元素执行 map 函数以创建一个新切片 @param slice Map(nums,func(_ int, v int) int { return v + 1 }) @param iteratee @return []U
func MapToSlice ¶
func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(key K, value V) R) []R
MapToSlice[K comparable, V any, R any]
@Description: map转换scile,可以自己处理逻辑 @param in @param iteratee @return []R
func MatchBytes ¶
func Merge ¶
func Merge[T any](slices ...[]T) []T
Merge[T any]
@Description: 合并多个切片,同元素存在 @param slices @return []T
func NumberFormat ¶
*
- @Description: 四舍五入,分割字符
- @param number 浮点数
- @param decimals 保留位数2
- @param decPoint .
- @param thousandsSep , 分隔符
- @return string
func PasswordHash ¶
*
- @Description: 创建密码散列,password 密码
- @param password 要加密字符串
- @return string
- @return error
func PasswordVerify ¶
*
- @Description: 验证密码,密码和密码散列
- @param password 密码
- @param hash 上面生成的散列密码
- @return bool
func Range ¶
Range[T Integer | Float]
@Description: 生成数组 @param start Range(1,5) @param elementNum @return []T
func RangeWithStep ¶
根据指定的起始值,结束值,步长,创建一个数字切片
func Reverse ¶
func Reverse[T any](collection []T) []T
Reverse[T any]
@Description: sclie反序 @param collection @return []T
func Sample ¶
func Sample[T any](collection []T) T
Sample[T any]
@Description: 随机返回一个值
[]int64{1,2,3}
@param collection @return T
func Samples ¶
Samples[T any]
@Description: 随即返回指定个数scile @param collection @param count @return []T
func SendEmail ¶
func SendEmail(from string, to1 string, subject string, body string, secret string, host string, port int) (err error)
*
- @Description: 发送邮件不使用任何扩展 from :="logwwwove@qq.com" to1:="yobybxy@163.com,18291448834@163.com" secret := "abc" host :="smtp.qq.com" port := 25 subject:="主题" body:="内容是测试" err:=php.SendEmail(from,to1,subject,body,secret,host,port) php.CheckErr(err)
- @param from 发送人邮箱
- @param to1 收件人邮箱,多个用,隔开"yoby21bxy@163.com,182914114811834@163.com"
- @param subject 标题
- @param body 内容
- @param secret 密钥,qq邮箱授权码密码
- @param host 主机地址
- @param port 端口25
- @return err
func Shuffle ¶
func Shuffle[T any](collection []T) []T
Shuffle[T any] Shuffle([]string{"a", "bb", "c", "ee"})
@Description: 打乱数组 @param collection @return []T
func SliceToMap ¶
func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
SliceToMap[T any, K comparable, V any]
@Description:切片转换字典 @param collection @param transform @return map[K]V
func Sort ¶
Sort[T Ordered]
@Description: 对任何有序类型(数字或字符串)的切片进行排序,使用快速排序算法 @param slice @param sortOrder
func SplitStr ¶
SplitStr
@Description: 切割字符串为scile @param str @param delimiter 切割符号 @param characterMask 去除空格或其他 @return []string
func String ¶
func String(t Transformer, s string) (result string, n int, err error)
String returns a string with the result of converting s[:n] using t, where n <= len(s). If err == nil, n will be len(s). It calls Reset on t.
func StructToMap ¶
func Ternary ¶
Ternary[T any]
@Description: 三元运算符 字符串 @param condition @param ifOutput @param elseOutput @return T
func TernaryF ¶
TernaryF[T any]
@Description: 三元运算符函数 @param condition @param ifFunc @param elseFunc @return T
func ToInterface ¶
ToInterface 将反射值转换成对应的 interface 类型
@Description: @param v @return value @return ok
func ToMap ¶
func ToMap[T any, K comparable, V any](array []T, iteratee func(T) (K, V)) map[K]V
ToMap[T any, K comparable, V any]
@Description:将切片转为 map @param array @param iteratee @return map[K]V
func ToString ¶
ToString
@Description: 将值转换为字符串,对于数字、字符串、[]byte,将转换为字符串。 对于其他类型(切片、映射、数组、结构)将调用 json.Marshal @param value @return string
func Unicode2utf8 ¶
unicode2utf8 @Description: unicode转换utf8 @param str @return string utf8
func Union ¶
func Union[T comparable](slices ...[]T) []T
Union[T comparable]
@Description: 合并多个切片,相同元素也会合并 @param slices @return []T
func Uniq ¶
func Uniq[T comparable](collection []T) []T
Uniq[T comparable] Uniq([]string{"Samuel", "John", "Samuel"})
@Description: 去除scile中重复元素 @param collection @return []T
func Utf82unicode ¶
utf82unicode @Description: utf8转换unnicode @param str @return string unicode
func Values ¶
func Values[K comparable, V any](in map[K]V) []V
Values[K comparable, V any]
@Description: 返回字典值 @param in @return []V
Types ¶
type Complex ¶
type Complex interface { ~complex64 | ~complex128 }
type Decoder ¶
type Decoder struct { Transformer // contains filtered or unexported fields }
A Decoder converts bytes to UTF-8. It implementsTransformer.
Transforming source bytes that are not of that encoding will not result in an error per se. Each byte that cannot be transcoded will be represented in the output by the UTF-8 encoding of '\uFFFD', the replacement rune.
func (*Decoder) Bytes ¶
Bytes converts the given encoded bytes to UTF-8. It returns the converted bytes or nil, err if any error occurred.
type Encoder ¶
type Encoder struct { Transformer // contains filtered or unexported fields }
An Encoder converts bytes from UTF-8. It implementsTransformer.
Each rune that cannot be transcoded will result in an error. In this case, the transform will consume all source byte up to, not including the offending rune. Transforming source bytes that are not valid UTF-8 will be replaced by `\uFFFD`. To return early with an error instead, useChain to preprocess the data with a UTF8Validator.
func HTMLEscapeUnsupported ¶
HTMLEscapeUnsupported wraps encoders to replace source runes outside the repertoire of the destination encoding with HTML escape sequences.
This wrapper exists to comply to URL and HTML forms requiring a non-terminating legacy encoder. The produced sequences may lead to data loss as they are indistinguishable from legitimate input. To avoid this issue, use UTF-8 encodings whenever possible.
func ReplaceUnsupported ¶
ReplaceUnsupported wraps encoders to replace source runes outside the repertoire of the destination encoding with an encoding-specific replacement.
This wrapper is only provided for backwards compatibility and legacy handling. Its use is strongly discouraged. Use UTF-8 whenever possible.
func (*Encoder) Bytes ¶
Bytes converts bytes from UTF-8. It returns the converted bytes or nil, err if any error occurred.
type Encoding ¶
type Encoding interface { // NewDecoder returns a Decoder. NewDecoder() *Decoder // NewEncoder returns an Encoder. NewEncoder() *Encoder }
第二波
var (
GBK Encoding = &gbk
)
var Replacement Encoding = replacement{}
Replacement is the replacement encoding. Decoding from the replacement encoding yields a single '\uFFFD' replacement rune. Encoding from UTF-8 to the replacement encoding yields the same as the source bytes except that invalid UTF-8 is converted to '\uFFFD'.
It is defined at http://encoding.spec.whatwg.org/#replacement
type FuncEncoding ¶
type FuncEncoding struct { Decoder func() Transformer Encoder func() Transformer }
FuncEncoding is an Encoding that combines two functions returning a new Transformer.
func (FuncEncoding) NewDecoder ¶
func (e FuncEncoding) NewDecoder() *Decoder
func (FuncEncoding) NewEncoder ¶
func (e FuncEncoding) NewEncoder() *Encoder
type Interface ¶
type Interface interface { // ID returns an encoding identifier. Exactly one of the mib and other // values should be non-zero. // // In the usual case it is only necessary to indicate the MIB code. The // other string can be used to specify encodings for which there is no MIB, // such as "x-mac-dingbat". // // The other string may only contain the characters a-z, A-Z, 0-9, - and _. ID() (mib MIB, other string) }
----------------------------------
type MIB ¶
type MIB uint16
A MIB identifies an encoding. It is derived from the IANA MIB codes and adds some identifiers for some encodings that are not covered by the IANA standard.
type NopResetter ¶
type NopResetter struct{}
NopResetter can be embedded by implementations of Transformer to add a nop Reset method.
func (NopResetter) Reset ¶
func (NopResetter) Reset()
Reset implements the Reset method of the Transformer interface.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps another io.Reader by transforming the bytes read.
type RepertoireError ¶
type RepertoireError byte
A RepertoireError indicates a rune is not in the repertoire of a destination encoding. It is associated with an encoding-specific suggested replacement byte.
func (RepertoireError) Error ¶
func (r RepertoireError) Error() string
Error implements the error interrface.
func (RepertoireError) Replacement ¶
func (r RepertoireError) Replacement() byte
Replacement returns the replacement string associated with this error.
type SimpleEncoding ¶
type SimpleEncoding struct { Decoder Transformer Encoder Transformer }
SimpleEncoding is an Encoding that combines two Transformers.
func (*SimpleEncoding) NewDecoder ¶
func (e *SimpleEncoding) NewDecoder() *Decoder
func (*SimpleEncoding) NewEncoder ¶
func (e *SimpleEncoding) NewEncoder() *Encoder
type SpanningTransformer ¶
type SpanningTransformer interface { Transformer // Span returns a position in src such that transforming src[:n] results in // identical output src[:n] for these bytes. It does not necessarily return // the largest such n. The atEOF argument tells whether src represents the // last bytes of the input. // // Callers should always account for the n bytes consumed before // considering the error err. // // A nil error means that all input bytes are known to be identical to the // output produced by the Transformer. A nil error can be returned // regardless of whether atEOF is true. If err is nil, then n must // equal len(src); the converse is not necessarily true. // // ErrEndOfSpan means that the Transformer output may differ from the // input after n bytes. Note that n may be len(src), meaning that the output // would contain additional bytes after otherwise identical output. // ErrShortSrc means that src had insufficient data to determine whether the // remaining bytes would change. Other than the error conditions listed // here, implementations are free to report other errors that arise. // // Calling Span can modify the Transformer state as a side effect. In // effect, it does the transformation just as calling Transform would, only // without copying to a destination buffer and only up to a point it can // determine the input and output bytes are the same. This is obviously more // limited than calling Transform, but can be more efficient in terms of // copying and allocating buffers. Calls to Span and Transform may be // interleaved. Span(src []byte, atEOF bool) (n int, err error) }
SpanningTransformer extends the Transformer interface with a Span method that determines how much of the input already conforms to the Transformer.
type Transformer ¶
type Transformer interface { // Transform writes to dst the transformed bytes read from src, and // returns the number of dst bytes written and src bytes read. The // atEOF argument tells whether src represents the last bytes of the // input. // // Callers should always process the nDst bytes produced and account // for the nSrc bytes consumed before considering the error err. // // A nil error means that all of the transformed bytes (whether freshly // transformed from src or left over from previous Transform calls) // were written to dst. A nil error can be returned regardless of // whether atEOF is true. If err is nil then nSrc must equal len(src); // the converse is not necessarily true. // // ErrShortDst means that dst was too short to receive all of the // transformed bytes. ErrShortSrc means that src had insufficient data // to complete the transformation. If both conditions apply, then // either error may be returned. Other than the error conditions listed // here, implementations are free to report other errors that arise. Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) // Reset resets the state and allows a Transformer to be reused. Reset() }
Transformer transforms bytes.
func Chain ¶
func Chain(t ...Transformer) Transformer
Chain returns a Transformer that applies t in sequence.
func RemoveFunc
deprecated
func RemoveFunc(f func(r rune) bool) Transformer
Deprecated: Use runes.Remove instead.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer wraps another io.Writer by transforming the bytes read. The user needs to call Close to flush unwritten bytes that may be buffered.