mirror of
https://gitee.com/johng/gf
synced 2026-06-25 17:22:00 +08:00
完善gxml中匹配encoding的处理,增加gcharset包的说明
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user