diff options
| author | b5f0d6c3 <[email protected]> | 2022-05-06 14:08:24 +0800 |
|---|---|---|
| committer | b5f0d6c3 <[email protected]> | 2022-05-06 14:08:24 +0800 |
| commit | cd151081c008722868062b522ae2076b4df8d312 (patch) | |
| tree | 8b1d5709138c94653723eb43206c7d0c369b0d85 /mkvlib/utils.go | |
| parent | b1258fe475ceeaab59dbc50af99e70f2fd72f652 (diff) | |
update mkvlib:add utf-16le support
Diffstat (limited to 'mkvlib/utils.go')
| -rw-r--r-- | mkvlib/utils.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/mkvlib/utils.go b/mkvlib/utils.go index 590ed2e..85ef657 100644 --- a/mkvlib/utils.go +++ b/mkvlib/utils.go @@ -3,6 +3,9 @@ package mkvlib import ( "errors" "fmt" + "github.com/gogs/chardet" + "golang.org/x/text/encoding/unicode" + "golang.org/x/text/transform" "io" "math/rand" "os" @@ -213,3 +216,13 @@ func randomStr(l int) string { } return string(result) } + +func toUTF8(data []byte) string { + d := chardet.NewTextDetector() + if r, err := d.DetectBest(data); err == nil { + if r.Charset == "UTF-16LE" { + data, _, _ = transform.Bytes(unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewDecoder(), data) + } + } + return string(data) +} |
