Giter VIP home page Giter VIP logo

gonvert's Introduction

Gonvert

Simple character-encoding converter with an automatic character-code detection in Golang. You can convert without a declaration of a previous encoding.

Build Status Coverage Status

Install

go get github.com/timakin/gonvert

Current Support

  • Shift_JIS <-> UTF8
  • Shift_JIS <-> EUC-JP
  • Shift_JIS <-> GBK
  • EUC-JP <-> UTF8
  • EUC-JP <-> GBK
  • GBK <-> UTF8
  • UTF8 <-> UTF16

You can specify the character code to encode/decode with gonvert constatants.

Prepared const character-code is following.

const (
	UTF8 CharCode = iota
	SJIS
	EUCJP
	GBK
	UTF16BE
	UTF16LE
)

Usage

You can call the converter with 2 or 3 arguements.

If you set 2 variables, gonvert will estimate the code automatically.

But if you already know the code of strings, you should set the third arguements, without an estimation.

package main

import (
    "github.com/timakin/gonvert"
    "fmt"
)
func main() {
    // ------------ Estimation case ------------

    // Input a Shift_JIS encoded string
    sjisStr := "\x8c\x8e\x93\xfa\x82\xcd\x95\x53\x91\xe3\x82\xcc\x89\xdf\x8b" +
               "\x71\x82\xc9\x82\xb5\x82\xc4\x81\x41\x8d\x73\x82\xa9\x82\xd3" +
               "\x94\x4e\x82\xe0\x96\x94\x97\xb7\x90\x6c\x96\xe7\x81\x42"
    converter := gonvert.New(sjisStr, gonvert.UTF8)
    result, err := converter.Convert()
    if err != nil {
        panic("Failed to convert!")
    }
    // This will print out the utf-8 encoded string: "月日は百代の過客にして、行かふ年も又旅人也。"
    fmt.Print(result)

    // -----------------------------------------

    // ------------ Specified-code case ------------

    sjisStr := "\x8c\x8e\x93\xfa\x82\xcd\x95\x53\x91\xe3\x82\xcc\x89\xdf\x8b" +
               "\x71\x82\xc9\x82\xb5\x82\xc4\x81\x41\x8d\x73\x82\xa9\x82\xd3" +
               "\x94\x4e\x82\xe0\x96\x94\x97\xb7\x90\x6c\x96\xe7\x81\x42"

    // Should send `before` character code if you already know, because an estimation like above may become incorrect.
    converter := gonvert.New(sjisStr, gonvert.UTF8, gonvert.SJIS)
    result, err := converter.Convert()
    if err != nil {
        panic("Failed to convert!")
    }
    fmt.Print(result)

    // -----------------------------------------
}

gonvert's People

Contributors

timakin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

hh9net ninetin

gonvert's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.