Skip to content

Commit

Permalink
force gbk into gb18030
Browse files Browse the repository at this point in the history
  • Loading branch information
gonejack committed Aug 25, 2023
1 parent cc57460 commit 2525246
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 5 additions & 0 deletions transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2525246

Please sign in to comment.