mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
删除gcharset中的getcharset方法
This commit is contained in:
@ -18,15 +18,6 @@ import (
|
||||
)
|
||||
|
||||
|
||||
|
||||
//获取支持的字符集
|
||||
func GetCharset(name string) (*mahonia.Charset, error) {
|
||||
s := mahonia.GetCharset(name)
|
||||
if s == nil {
|
||||
return nil, errors.New(fmt.Sprintf("not support charset: %s", name))
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
//2个字符集之间的转换
|
||||
func Convert(dstCharset string, srcCharset string, src string) (dst string, err error) {
|
||||
s := mahonia.GetCharset(srcCharset)
|
||||
|
||||
@ -11,8 +11,10 @@ import (
|
||||
"github.com/clbanning/mxj"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"gitee.com/johng/gf/g/encoding/gcharset"
|
||||
"gitee.com/johng/gf/g/util/gregx"
|
||||
"github.com/axgle/mahonia"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 将XML内容解析为map变量
|
||||
@ -47,9 +49,9 @@ func ToJson(xmlbyte []byte) ([]byte, error) {
|
||||
func Prepare(xmlbyte []byte) error {
|
||||
patten := "<\\?xml\\s+version\\s*=.*?\\s+encoding\\s*=\\s*[\\'|\"](.*?)[\\'|\"]\\s*\\?\\s*>"
|
||||
charsetReader := func(charset string, input io.Reader) (io.Reader, error) {
|
||||
reader, err := gcharset.GetCharset(charset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
reader := mahonia.GetCharset(charset)
|
||||
if reader == nil {
|
||||
return nil, errors.New(fmt.Sprintf("not support charset:%s", charset))
|
||||
}
|
||||
return reader.NewDecoder().NewReader(input), nil
|
||||
}
|
||||
@ -59,9 +61,9 @@ func Prepare(xmlbyte []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
charset, err := gcharset.GetCharset(matchStr[1])
|
||||
if err != nil {
|
||||
return err
|
||||
charset := mahonia.GetCharset(matchStr[1])
|
||||
if charset == nil {
|
||||
return errors.New(fmt.Sprintf("not support charset:%s", matchStr[1]))
|
||||
}
|
||||
|
||||
if charset.Name != "UTF-8" {
|
||||
|
||||
Reference in New Issue
Block a user