QCharsetMatch QCharsetDetector::detect()
{
    // Just call QCharsetDetector::detectAll() and take the first
    // match here instead of using ucsdet_detect() to get only a
    // single match. The list returned by ucsdet_detectAll() maybe
    // tweaked a bit in QCharsetDetector::detectAll() to improve
    // the quality of the detection. Therefore, the first element
    // of the list returned by QCharsetDetector::detectAll() may
    // differ from the single match returned by ucsdet_detect().
    Q_D(QCharsetDetector);
    QList<QCharsetMatch> qCharsetMatchList = detectAll();
    if(hasError()) {
        qWarning() << __PRETTY_FUNCTION__ << errorString();
        return QCharsetMatch();
    }
    if (qCharsetMatchList.isEmpty()) {
        // should never happen, because detectAll() already sets an
        // error if no matches are found which the previous
        // if(hasError()) should detect.
        d->_status = U_CE_NOT_FOUND_ERROR;
        qWarning() << __PRETTY_FUNCTION__
                   << "no matches found at all" << errorString();
        return QCharsetMatch();
    }
    return qCharsetMatchList.first();
}
Exemplo n.º 2
0
const CharsetMatch *CharsetDetector::detect(UErrorCode &status)
{
    int32_t maxMatchesFound = 0;

    detectAll(maxMatchesFound, status);

    if(maxMatchesFound > 0) {
        return resultArray[0];
    } else {
        return NULL;
    }
}