mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 04:37:49 +08:00
add example for gcharset; fix issue in gxml
This commit is contained in:
parent
4af8ae1470
commit
17d49510c4
@ -9,7 +9,7 @@ package gxml
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/g/encoding/internal"
|
||||
"github.com/gogf/gf/g/encoding/gcharset"
|
||||
"github.com/gogf/gf/g/text/gregex"
|
||||
"github.com/gogf/gf/third/github.com/clbanning/mxj"
|
||||
"strings"
|
||||
@ -61,16 +61,12 @@ func convert(xml []byte) (res []byte, err error) {
|
||||
xmlEncode = matchStr[1]
|
||||
}
|
||||
xmlEncode = strings.ToUpper(xmlEncode)
|
||||
s := internal.GetCharset(xmlEncode)
|
||||
if s == false {
|
||||
return nil, fmt.Errorf("not support charset:%s\n", xmlEncode)
|
||||
}
|
||||
res, err = gregex.Replace(patten, []byte(""), xml)
|
||||
res, err = gregex.Replace(patten, []byte(""), xml)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if xmlEncode != "UTF-8" && xmlEncode != "UTF8" {
|
||||
dst, err := internal.Convert("UTF-8", xmlEncode, string(res))
|
||||
dst, err := gcharset.Convert("UTF-8", xmlEncode, string(res))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
17
geg/encoding/gcharset/gcharset.go
Normal file
17
geg/encoding/gcharset/gcharset.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/g/encoding/gcharset"
|
||||
)
|
||||
|
||||
func main() {
|
||||
src := "~{;(<dR;:x>F#,6@WCN^O`GW!#"
|
||||
srcCharset := "GB2312"
|
||||
dstCharset := "UTF-8"
|
||||
str, err := gcharset.Convert(dstCharset, srcCharset, src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(str)
|
||||
}
|
Loading…
Reference in New Issue
Block a user