@@ -26,12 +26,12 @@ func DetectEncodingByUChardetDylib(dat []byte) (string, error) {
2626
2727var (
2828 lib uintptr
29- uchardetNew func () unsafe. Pointer
30- uchardetDelete func (det unsafe. Pointer )
31- uchardetHandleData func (det unsafe. Pointer , data unsafe. Pointer , len uintptr ) int
32- uchardetDataEnd func (det unsafe. Pointer )
33- uchardetGetCharset func (det unsafe. Pointer ) * byte // 返回 C 字符串 (char*)
34- uchardetReset func (det unsafe. Pointer )
29+ uchardetNew func () uintptr
30+ uchardetDelete func (det uintptr )
31+ uchardetHandleData func (det uintptr , data [] byte , len int ) int
32+ uchardetDataEnd func (det uintptr )
33+ uchardetGetCharset func (det uintptr ) * byte // 返回 C 字符串 (char*)
34+ uchardetReset func (det uintptr )
3535)
3636
3737func init () {
@@ -50,7 +50,7 @@ func init() {
5050}
5151
5252type Chardet struct {
53- det unsafe. Pointer
53+ det uintptr
5454}
5555
5656func NewChardet () * Chardet {
@@ -62,18 +62,17 @@ func NewChardet() *Chardet {
6262 }
6363}
6464func (c * Chardet ) Release () {
65- if c .det != nil {
65+ if c .det != 0 {
6666 uchardetDelete (c .det )
67- c .det = nil
67+ c .det = 0
6868 }
6969}
7070func (c * Chardet ) Handle (buf []byte ) int {
71- if c .det == nil || len (buf ) == 0 {
71+ if c .det == 0 || len (buf ) == 0 {
7272 return - 1 // 或其他错误指示
7373 }
74- dataPtr := unsafe .Pointer (& buf [0 ])
75- dlen := uintptr (len (buf ))
76- return uchardetHandleData (c .det , dataPtr , dlen )
74+ dlen := len (buf )
75+ return uchardetHandleData (c .det , buf , dlen )
7776}
7877func (c * Chardet ) End () string {
7978 uchardetDataEnd (c .det )
0 commit comments