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; }
extern "C" const char * run_detector (const char * buf, int len) { const char * r; Detector *det = new Detector; det->HandleData (buf, len); det->DataEnd (); r = det->getresult(); delete det; return r; }