diff --git a/README.md b/README.md index bcea013..cc4d685 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,3 @@ Flags: -w, --overwrite Overwrite source file. --about Show about. ``` - -## Advices -For converting Simplified Chinese texts into UTF-8, set source encoding as gb18030 instead of gbk or gb2312 for maximum compatibility. diff --git a/transcode.go b/transcode.go index 7ccb321..47a61d8 100644 --- a/transcode.go +++ b/transcode.go @@ -13,6 +13,7 @@ import ( "github.com/gogs/chardet" "golang.org/x/text/encoding" "golang.org/x/text/encoding/htmlindex" + "golang.org/x/text/encoding/simplifiedchinese" "golang.org/x/text/transform" ) @@ -138,6 +139,10 @@ func parseEncoding(encoding string) (enc encoding.Encoding, err error) { if err != nil { err = fmt.Errorf("invalid encoding: %s", encoding) } + switch enc { + case simplifiedchinese.GBK: + enc = simplifiedchinese.GB18030 + } return } func detectEncoding(r *bufio.Reader) (string, error) {