diff options
| author | 2010-02-10 14:24:44 -0800 | |
|---|---|---|
| committer | 2010-02-10 14:24:44 -0800 | |
| commit | d2e6af66ce9fdf7bfa72efe18b74260901a944a6 (patch) | |
| tree | c59d187ed96275270bfc0f86a16dc33c97981dcc /media/libmedia/MediaScannerClient.cpp | |
| parent | e4e82f2782e61658256ecb85066e273c22a37951 (diff) | |
| parent | b45b0845a6db32848ad08ac1037ef67a68ec2d39 (diff) | |
Merge "Do autodetection even if no locale was specified, and use the detected encoding if it is unambiguous."
Diffstat (limited to 'media/libmedia/MediaScannerClient.cpp')
| -rw-r--r-- | media/libmedia/MediaScannerClient.cpp | 74 | 
1 files changed, 39 insertions, 35 deletions
diff --git a/media/libmedia/MediaScannerClient.cpp b/media/libmedia/MediaScannerClient.cpp index bd3596e3781c..bb3717f94aa0 100644 --- a/media/libmedia/MediaScannerClient.cpp +++ b/media/libmedia/MediaScannerClient.cpp @@ -64,28 +64,26 @@ void MediaScannerClient::beginFile()  bool MediaScannerClient::addStringTag(const char* name, const char* value)  { -    if (mLocaleEncoding != kEncodingNone) { -        // don't bother caching strings that are all ASCII. -        // call handleStringTag directly instead. -        // check to see if value (which should be utf8) has any non-ASCII characters -        bool nonAscii = false; -        const char* chp = value; -        char ch; -        while ((ch = *chp++)) { -            if (ch & 0x80) { -                nonAscii = true; -                break; -            } +    // don't bother caching strings that are all ASCII. +    // call handleStringTag directly instead. +    // check to see if value (which should be utf8) has any non-ASCII characters +    bool nonAscii = false; +    const char* chp = value; +    char ch; +    while ((ch = *chp++)) { +        if (ch & 0x80) { +            nonAscii = true; +            break;          } +    } -        if (nonAscii) { -            // save the strings for later so they can be used for native encoding detection -            mNames->push_back(name); -            mValues->push_back(value); -            return true; -        } -        // else fall through +    if (nonAscii) { +        // save the strings for later so they can be used for native encoding detection +        mNames->push_back(name); +        mValues->push_back(value); +        return true;      } +    // else fall through      // autodetection is not necessary, so no need to cache the values      // pass directly to the client instead @@ -198,23 +196,29 @@ void MediaScannerClient::convertValues(uint32_t encoding)  void MediaScannerClient::endFile()  { -    if (mLocaleEncoding != kEncodingNone) { -        int size = mNames->size(); -        uint32_t encoding = kEncodingAll; - -        // compute a bit mask containing all possible encodings -        for (int i = 0; i < mNames->size(); i++) -            encoding &= possibleEncodings(mValues->getEntry(i)); - -        // if the locale encoding matches, then assume we have a native encoding. -        if (encoding & mLocaleEncoding) -            convertValues(mLocaleEncoding); +    int size = mNames->size(); +    uint32_t encoding = kEncodingAll; + +    // compute a bit mask containing all possible encodings +    for (int i = 0; i < mNames->size(); i++) +        encoding &= possibleEncodings(mValues->getEntry(i)); + +    // If one of the possible encodings matches the locale encoding, use that. +    // Otherwise, if there is only one possible encoding, use that. +    if (encoding & mLocaleEncoding) +        convertValues(mLocaleEncoding); +    else if ((encoding & (encoding - 1)) == 0) +        convertValues(encoding); +    else { +        // TODO: try harder to disambiguate the encoding, perhaps by looking at +        // other files by same artist, or even the user's entire collection. +        // For now, fall through and insert the strings as they are. +    } -        // finally, push all name/value pairs to the client -        for (int i = 0; i < mNames->size(); i++) { -            if (!handleStringTag(mNames->getEntry(i), mValues->getEntry(i))) -                break; -        } +    // finally, push all name/value pairs to the client +    for (int i = 0; i < mNames->size(); i++) { +        if (!handleStringTag(mNames->getEntry(i), mValues->getEntry(i))) +            break;      }      // else addStringTag() has done all the work so we have nothing to do  |