Skip to content
/ transcode Public

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

Notifications You must be signed in to change notification settings

piex/transcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages