enca

package module
Version: v0.0.0-...-00fe968 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2016 License: MIT Imports: 5 Imported by: 0

README

enca Build Status

This is a minimal cgo bindings for libenca.

If you need to detect the language of a string you can use guesslanguage package.

Supported Go versions

enca is tested against Go 1.0, 1.1, 1.2, 1.3 and tip.

Usage

Install libenca to your system:

$ sudo apt-get install libenca0 libenca-dev

Install in your ${GOPATH} using go get -u github.com/endeveit/enca

Then call it:

package main

import (
	"fmt"
	"github.com/endeveit/enca"
)

func main() {
	analyzer, err := enca.New("zh")

	if err == nil {
		encoding, err := analyzer.FromString("美国各州选民今天开始正式投票。据信,", enca.NAME_STYLE_HUMAN)
		defer analyzer.Free()

		// Output:
		// UTF-8
		if err == nil {
			fmt.Println(encoding)
		}
	}
}

Documentation

godoc is available here.

Documentation

Overview

Package enca provides a minimal cgo bindings for libenca

Source code and project home: https://github.com/endeveit/go-enca

Index

Constants

View Source
const (
	// Default, implicit charset name in Enca
	NAME_STYLE_ENCA = 0 << iota
	// RFC 1345 or otherwise canonical charset name
	NAME_STYLE_RFC1345
	// Cstocs charset name (may not exist)
	NAME_STYLE_CSTOCS
	// Iconv charset name (may not exist)
	NAME_STYLE_ICONV
	// Human comprehensible description
	NAME_STYLE_HUMAN
	// Preferred MIME name (may not exist)
	NAME_STYLE_MIME
)

Variables

This section is empty.

Functions

func GetAvailableLanguages

func GetAvailableLanguages() []string

Returns list of available languages

Types

type EncaAnalyser

type EncaAnalyser struct {
	sync.Mutex
	// Language for which the analyser is initialized
	Language string
	// contains filtered or unexported fields
}

func New

func New(lang string) (*EncaAnalyser, error)

Returns a new EncaAnalyzer object for the given language.

func (*EncaAnalyser) Free

func (ea *EncaAnalyser) Free()

Frees memory used by EncaAnalyser

func (*EncaAnalyser) FromBytes

func (ea *EncaAnalyser) FromBytes(bytes []byte, nameStyle int) (result string, err error)

Returns encoding of provided byte array

func (*EncaAnalyser) FromString

func (ea *EncaAnalyser) FromString(text string, nameStyle int) (string, error)

Helper function that returns encoding of provided string

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL