Skip to content
forked from mushroomsir/iconv

๐Ÿš€ Pure golang implement

Notifications You must be signed in to change notification settings

fancybits/iconv

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 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
  • UTF-16
  • UTF-16BE
  • UTF-16LE
  • 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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%