diff options
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) +} |
