short detect (const char *buf, DetectObj ** obj) {
	Detector * det;
	const char * ret;

	det = new Detector;
	det->Reset ();
	if ( det->HandleData (buf, strlen (buf)) == NS_ERROR_OUT_OF_MEMORY ) {
		delete det;
		return CHARDET_OUT_OF_MEMORY;
	}
	det->DataEnd ();

	ret = det->getCharsetName ();
	delete det;

	if ( ! ret )
		return CHARDET_NO_RESULT;
	else if ( *obj == NULL )
		return CHARDET_NULL_OBJECT;

	(*obj)->encoding = (char *) strdup (ret);
	(*obj)->confidence = det->getConfidence ();

	return CHARDET_SUCCESS;
}