示例#1
0
func (b *strBuffer) String() string {
	d := japanese.ISO2022JP.NewDecoder()

	result, _, err := transform.Bytes(d, b.data)
	if err != nil {
		panic(err)
	}

	return string(result)
}
示例#2
0
func Convert(charset, s string) (string, error) {
	charset = strings.Replace(charset, "-", "", -1)
	charset = strings.ToLower(charset)

	if charset == "utf8" {
		return s, nil
	}

	e := Encoding(charset)
	if e == nil {
		return "", ErrUnknownCharset
	}

	d := e.NewDecoder()

	res, _, err := transform.Bytes(d, []byte(s))
	if err != nil {
		return "", err
	}

	return string(res), nil
}