Categorygithub.com/piex/transcode
modulepackage
0.0.2
Repository: https://github.com/piex/transcode.git
Documentation: pkg.go.dev

# README

transcode

transcode is a lib transcode between UTF-8 and GBK/GB2312/GB10830/HZGB2312 for golang.

中文文档

Install

The easiest way to install is to run go get -u github.com/piex/transcode.

You can also manually git clone the repository to $GOPATH/src/github.com/piex/transcode.

When you use vgo, you can run vgo get github.com/piex/transcode@latest.

Package Files

golang.org/x/text

Usage

To use the package, you'll need the appropriate import statement:

import (
  "github.com/piex/transcode"
)

The libraries use chained calls.

  • Transcode GBxxx to UTF-8

    s := transcode.FromString(gbkString).Decode("GBK").ToString()
    b := transcode.FromByteArray(gbkByteArray).Decode("GBK").ToByteArray()
    
  • Transcode UTF-8 to GBxxx

    b := transcode.FromString(utf8String).Encode("GBK").ToByteArray()
    s := transcode.FromByteArray(utf8String).Encode("GBK").ToString()
    

type Trans

An interface of Transcode, inclueds the func for transcode.

type Trans interface {
  // Decode decode string to UTF-8
  Decode(string) Trans 
  // Encode encode UTF-8 to GBxxx
  Encode(string) Trans 
  // ToByteArray return result as byte
  ToByteArray() []byte  array
  // ToString return result as string
  ToString() string    
}

func FromString

func FromString(s string) Trans

Input a string type variable to transcode UTF-8 between GBxxx.

func FromByteArray

func FromByteArray(b []byte) Trans

Input a byte array type variable to transcode UTF-8 between GBxxx.

# Functions

FromByteArray 输入要转码的 byte 数组.
FromString 输入要转码的字符串.

# Structs

Transcode code type.

# Interfaces

Trans 转化字符串.