完善gxml中匹配encoding的处理,增加gcharset包的说明

This commit is contained in:
wenzi1
2018-06-06 14:12:40 +08:00
parent 57018a67b6
commit e209119dd5
2 changed files with 6 additions and 3 deletions

View File

@ -7,7 +7,8 @@
//gcharset
//@author wenzi1
//@date 20180604
//字符集转换方法.
//使用mahonia实现的字符集转换方法支持的字符集包括常见的utf8/UTF-16/UTF-16LE/macintosh/big5/gbk/gb18030,支持的全量字符集可以参考mahonia包
package gcharset
import (
@ -16,6 +17,8 @@ import (
"fmt"
)
//获取支持的字符集
func GetCharset(name string) (*mahonia.Charset, error) {
s := mahonia.GetCharset(name)

View File

@ -11,7 +11,7 @@ import (
"github.com/clbanning/mxj"
"encoding/xml"
"io"
"gitee.com/johng/gf/g/encoding/gcharset"
"gitee.com/wenzi1/gf/g/encoding/gcharset"
"gitee.com/johng/gf/g/util/gregx"
)
@ -45,7 +45,7 @@ func ToJson(xmlbyte []byte) ([]byte, error) {
//@author wenzi1
//@date 20180604
func Prepare(xmlbyte []byte) error {
patten := "<\\?xml\\s+.*?\\s+encoding=\"(.*?)\""
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 {