Esempio n. 1
0
func ucsdOpen() (*C.UCharsetDetector, error) {
	uErr := C.UErrorCode(C.U_ZERO_ERROR)
	ucsd, err := C.ucsdet_open(&uErr)
	if err != nil {
		return nil, err
	}
	if err = uErrorToGoError(uErr); err != nil {
		return nil, err
	}
	return ucsd, nil
}
Esempio n. 2
0
// Creates new charset detector. If it is successfully created, it
// must be closed as it needs to free native ICU resources.
func NewCharsetDetector() (*CharsetDetector, error) {
	det := new(CharsetDetector)

	var status int
	statusPtr := unsafe.Pointer(&status)

	det.ptr = C.ucsdet_open((*C.UErrorCode)(statusPtr))

	if status != U_ZERO_ERROR {
		return nil, fmt.Errorf("ICU Error code returned: %d", status)
	}

	return det, nil
}