diff options
author | Marco Nelissen <marcone@google.com> | 2010-02-08 15:04:23 -0800 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2010-02-08 16:16:54 -0800 |
commit | 5a2621a64de196cbdb9a2a50357dee1c32fcf11b (patch) | |
tree | 4cf47b553e0c17f7eeaf9432f2b3adee892293e9 /media/libstagefright/id3/ID3.cpp | |
parent | 6c8a9a4132337a3419a72a735f0b40df0b82061f (diff) | |
download | frameworks_av-5a2621a64de196cbdb9a2a50357dee1c32fcf11b.zip frameworks_av-5a2621a64de196cbdb9a2a50357dee1c32fcf11b.tar.gz frameworks_av-5a2621a64de196cbdb9a2a50357dee1c32fcf11b.tar.bz2 |
Skip the endianness marker when converting UCS-2 to UTF-8, since it
ends up in the UTF-8 string otherwise.
Diffstat (limited to 'media/libstagefright/id3/ID3.cpp')
-rw-r--r-- | media/libstagefright/id3/ID3.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp index 6d64717..65a4ae4 100644 --- a/media/libstagefright/id3/ID3.cpp +++ b/media/libstagefright/id3/ID3.cpp @@ -24,6 +24,7 @@ #include <media/stagefright/MediaDebug.h> #include <media/stagefright/Utils.h> #include <utils/String8.h> +#include <sys/endian.h> namespace android { @@ -336,7 +337,26 @@ void ID3::Iterator::getString(String8 *id) const { } else { // UCS-2 // API wants number of characters, not number of bytes... - id->setTo((const char16_t *)(mFrameData + 1), n / 2); + int len = n / 2; + const char16_t *framedata = (const char16_t *) (mFrameData + 1); + char16_t *framedatacopy = NULL; + if (*framedata == 0xfffe) { + // endianness marker doesn't match host endianness, convert + framedatacopy = new char16_t[len]; + for (int i = 0; i < len; i++) { + framedatacopy[i] = swap16(framedata[i]); + } + framedata = framedatacopy; + } + // If the string starts with an endianness marker, skip it + if (*framedata == 0xfeff) { + framedata++; + len--; + } + id->setTo(framedata, len); + if (framedatacopy != NULL) { + delete[] framedatacopy; + } } } |