Documentation ¶
Index ¶
- Constants
- Variables
- func AnsiToUtf8(ansi []byte, codepage uintptr) (utf8 string, err error)
- func AtoU(ansi []byte, codepage uintptr) (string, error)deprecated
- func ConsoleCP() uintptr
- func NewAutoDecoder(cp uintptr) transform.Transformer
- func NewDecoder(cp uintptr) transform.Transformer
- func NewEncoder(cp uintptr) transform.Transformer
- func Utf8ToAnsi(utf8 string, codepage uintptr) (ansi []byte, err error)
- func UtoA(utf8 string, codepage uintptr) (ansi []byte, err error)deprecated
- type AutoDecoder
- type Filter
Examples ¶
Constants ¶
const ACP = 0
ACP is the constant meaning the active codepage for OS
const CP_ACP = 0
Code generated by go-importconst DO NOT EDIT.
const CP_MACCP = 2
const CP_OEMCP = 1
const CP_SYMBOL = 42
const CP_UTF7 = 65000
const CP_UTF8 = 65001
const MB_COMPOSITE = 2
const MB_ERR_INVALID_CHARS = 8
const MB_PRECOMPOSED = 1
const MB_USEGLYPHCHARS = 4
const THREAD_ACP = 3
THREAD_ACP is the constant meaning the active codepage for thread
const WC_COMPOSITECHECK = 512
const WC_ERR_INVALID_CHARS = 128
const WC_NO_BEST_FIT_CHARS = 1024
Variables ¶
var ErrUnsupportedOs = errors.New("Unsupported OS")
ErrUnsupportedOs is return value when AtoU,UtoA is called on not Windows
Functions ¶
func AnsiToUtf8 ¶ added in v0.2.0
AnsiToUtf8 Converts Ansi-bytes to UTF8-String
Example ¶
ExampleAnsiToUtf8 converts from ANSI-string of STDIN to UTF8 via STDOUT
sc := bufio.NewScanner(os.Stdin) for sc.Scan() { text, err := mbcs.AnsiToUtf8(sc.Bytes(), mbcs.ACP) if err != nil { fmt.Fprintln(os.Stderr, err.Error()) os.Exit(1) } fmt.Println(text) }
Output:
func NewAutoDecoder ¶ added in v0.4.0
func NewAutoDecoder(cp uintptr) transform.Transformer
NewAutoDecoder returns transform.Transformer that converts strings that are unknown to ANSI or UTF8 to UTF8.
func NewDecoder ¶ added in v0.4.0
func NewDecoder(cp uintptr) transform.Transformer
func NewEncoder ¶ added in v0.4.0
func NewEncoder(cp uintptr) transform.Transformer
func Utf8ToAnsi ¶ added in v0.2.0
Utf8ToAnsi Converts UTF8-String to Ansi-bytes
Example ¶
ExampleUtf8ToAnsi converts from UTF8-string of STDIN to ANSI via STDOUT
sc := bufio.NewScanner(os.Stdin) for sc.Scan() { bytes, err := mbcs.Utf8ToAnsi(sc.Text(), mbcs.ACP) if err != nil { fmt.Fprintln(os.Stderr, err.Error()) os.Exit(1) } os.Stdout.Write(bytes) os.Stdout.Write([]byte{'\n'}) }
Output:
Types ¶
type AutoDecoder ¶ added in v0.3.0
type AutoDecoder struct {
CP uintptr
}
AutoDecoder is an implementation of transform.Transformer that converts strings that are unknown to ANSI or UTF8 to UTF8.
func (AutoDecoder) Reset ¶ added in v0.3.0
func (f AutoDecoder) Reset()
Reset does nothing in AutoDecoder
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is the class like bufio.Scanner but detects the encoding-type and converts to utf8 on Windows. On other OSes, it works like bufio.Scanner
func (*Filter) ForceGuessAlways ¶
func (f *Filter) ForceGuessAlways()
ForceGuessAlways should be called when you should guess the encoding for each line repeadedly