summaryrefslogtreecommitdiff
path: root/firmware/id3.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-09-30 18:45:50 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-09-30 18:45:50 +0000
commitad911c0ac82f409251230b39b39fc3e8c2b83ff9 (patch)
treef94f01d5ea81b83695f8e1c974febe09a7a7866f /firmware/id3.c
parent18ae8f573580660363b4a1c84b483b663d618b12 (diff)
downloadrockbox-ad911c0ac82f409251230b39b39fc3e8c2b83ff9.tar.gz
rockbox-ad911c0ac82f409251230b39b39fc3e8c2b83ff9.zip
Bill Napier wrote this:
This patch adds minimal suppport for 16-bit Unicode strings for ID3 tags. It is basically a modification to the ID3v2 parser that checks for Unicode strings. If a string is found that is a Unicode string, it is converted (in place) to an ASCII string if it is an ASCII character. Since we can support non-ASCII characters on the display, support for non-ASCII characters in ID3 tags should proably also be supported in the future. This patch is just an interem change until full Unicode support is implemented (if ever). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2451 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/id3.c')
-rw-r--r--firmware/id3.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/firmware/id3.c b/firmware/id3.c
index 4da0224641..90db840689 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -86,6 +86,28 @@ const int freqtab[][4] =
86 {22050, 24000, 16000, 0}, /* MPEG version 2 */ 86 {22050, 24000, 16000, 0}, /* MPEG version 2 */
87}; 87};
88 88
89#define UNICODE_BOM_1 0xfffe
90#define UNICODE_BOM_2 0xfeff
91
92/* Checks to see if the passed in string is a 16-bit wide Unicode v2
93 string. If it is, we attempt to convert it to a 8-bit ASCII string
94 (for valid 8-bit ASCII characters). If it's not unicode, we leave
95 it alone. At some point we should fully support unicode strings */
96
97static void unicode_munge(char* string) {
98 unsigned short* short_string = (unsigned short*)string;
99 if (short_string[0] == UNICODE_BOM_1 ||
100 short_string[0] == UNICODE_BOM_2) {
101 int x = 0;
102 do {
103 x++;
104 if (!(short_string[x]&0xff00)) {
105 string[x-1]=(short_string[x]&0xff);
106 }
107 } while (short_string[x]!=0x0000);
108 }
109}
110
89/* 111/*
90 * Removes trailing spaces from a string. 112 * Removes trailing spaces from a string.
91 * 113 *
@@ -249,6 +271,7 @@ static void setid3v2title(int fd, struct mp3entry *entry)
249 artist = buffer + readsize; 271 artist = buffer + readsize;
250 artistn = headerlen; 272 artistn = headerlen;
251 readsize += headerlen; 273 readsize += headerlen;
274 unicode_munge(artist);
252 } 275 }
253 else if(!strncmp(header, "TIT2", strlen("TIT2")) || 276 else if(!strncmp(header, "TIT2", strlen("TIT2")) ||
254 !strncmp(header, "TT2", strlen("TT2"))) { 277 !strncmp(header, "TT2", strlen("TT2"))) {
@@ -257,6 +280,7 @@ static void setid3v2title(int fd, struct mp3entry *entry)
257 title = buffer + readsize; 280 title = buffer + readsize;
258 titlen = headerlen; 281 titlen = headerlen;
259 readsize += headerlen; 282 readsize += headerlen;
283 unicode_munge(title);
260 } 284 }
261 else if(!strncmp(header, "TALB", strlen("TALB"))) { 285 else if(!strncmp(header, "TALB", strlen("TALB"))) {
262 readsize++; 286 readsize++;
@@ -264,6 +288,7 @@ static void setid3v2title(int fd, struct mp3entry *entry)
264 album = buffer + readsize; 288 album = buffer + readsize;
265 albumn = headerlen; 289 albumn = headerlen;
266 readsize += headerlen; 290 readsize += headerlen;
291 unicode_munge(album);
267 } 292 }
268 else if(!strncmp(header, "TRCK", strlen("TRCK"))) { 293 else if(!strncmp(header, "TRCK", strlen("TRCK"))) {
269 readsize++; 294 readsize++;
@@ -271,6 +296,7 @@ static void setid3v2title(int fd, struct mp3entry *entry)
271 tracknum = buffer + readsize; 296 tracknum = buffer + readsize;
272 tracknumn = headerlen; 297 tracknumn = headerlen;
273 readsize += headerlen; 298 readsize += headerlen;
299 unicode_munge(tracknum);
274 } else { 300 } else {
275 readsize += headerlen; 301 readsize += headerlen;
276 } 302 }