Skip to content

mushroomsir/iconv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

iconv

Build Status Coverage Status License GoDoc

Installation

go get -u github.com/mushroomsir/iconv

Support charset

  • UTF-8
  • GBK
  • GB-18030
  • GB2312
  • Big5
  • ISO-8859-1
  • EUC-JP
  • Shift_JIS
  • More coming soon

Usage

import (
	github.com/mushroomsir/iconv
)

Converting string Values

Converting a string can be done with two methods. First, there's iconv.ConvertString(input, fromEncoding, toEncoding string) syntactic sugar.

output,err := iconv.ConvertString("Hello World!", iconv.GBK, iconv.UTF8)

Alternatively, you can create a converter and use its ConvertString method. Reuse of a Converter instance is recommended when doing many string conversions between the same encodings.

converter := iconv.NewConverter(iconv.GBK, iconv.UTF8)
output,err := converter.ConvertString("Hello World!")

Converting []byte Values

Converting a []byte can similarly be done with two methods. First, there's iconv.Convert(input []byte, fromEncoding, toEncoding string).

input := []byte("Hello World!")
output, err := iconv.ConvertBytes(input, iconv.GBK, iconv.UTF8)

Just like with ConvertString, there is also a Convert method on Converter that can be used.

convert,err := iconv.NewConverter(iconv.GBK, iconv.UTF8)
input := []byte("Hello World!")
output, err := converter.ConvertBytes(input)

Converting an io.Reader

The iconv.Reader allows any other *io.Reader to be wrapped and have its bytes transcoded as they are read.

reader,err := iconv.Convert(strings.NewReader("Hello World!"),  iconv.GBK, iconv.UTF8)

Licenses

All source code is licensed under the MIT License.

About

๐Ÿš€ Pure golang implement

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages