Zinf and UTF8
Robert Hart <[email protected]>
| Newsgroups | gmane.comp.audio.zinf.devel |
|---|---|
| Organization | University of Nottingham |
| Message-ID | <1061223055.3197.4.camel@euclid> |
Ok, guys. This patch converts the handling of vorbis metadata to UTF8 (which actually removes code because the vorbis API returns UTF-8) As can be seen from this screenshot: http://www.nottingham.ac.uk/~enxrah/utfzinf.png This means that arbitrary unicode characters are used throughout zinf, without causing any problems. I can even copy and paste chinese and arabic text from mozilla into the info editor! This just leaves mp3s, but nobody uses those anymore right? just kidding. It will be trickier though.... Rob -- +-------------------------------------+ | "It's only a trap if you don't take | | a ladder with you to get out of it" | | -S Ring, Bath Uni | | | | [email protected] | | http://www.nott.ac.uk/~enxrah | +-------------------------------------+
utf8.diff
(text/x-patch, 4 KB)
Index: lmc/vorbis/src/vorbislmc.cpp
===================================================================
RCS file: /cvsroot/zinf/zinf/lmc/vorbis/src/vorbislmc.cpp,v
retrieving revision 1.17
diff -a -u -r1.17 vorbislmc.cpp
--- lmc/vorbis/src/vorbislmc.cpp 2 Aug 2003 19:17:49 -0000 1.17
+++ lmc/vorbis/src/vorbislmc.cpp 18 Aug 2003 16:04:49 -0000
@@ -464,22 +464,19 @@
temp = vorbis_comment_query(comment, "title", 0);
if (temp)
{
- iso = ConvertToISO(temp);
- mdata.SetTitle(iso);
+ mdata.SetTitle(temp);
}
temp = vorbis_comment_query(comment, "artist", 0);
if (temp)
{
- iso = ConvertToISO(temp);
- mdata.SetArtist(iso);
+ mdata.SetArtist(temp);
}
temp = vorbis_comment_query(comment, "album", 0);
if (temp)
{
- iso = ConvertToISO(temp);
- mdata.SetAlbum(iso);
+ mdata.SetAlbum(temp);
}
temp = vorbis_comment_query(comment, "tracknumber", 0);
@@ -601,46 +598,3 @@
m_decodeInfo = info;
return kError_NoErr;
}
-
-const string VorbisLMC::ConvertToISO(const char *utf8)
-{
- unsigned char *in, *buf;
- unsigned char *out, *end;
- string ret;
-
- in = (unsigned char *)utf8;
- buf = out = new unsigned char[strlen(utf8) + 1];
- end = in + strlen(utf8);
- for(;*in != 0x00 && in <= end; in++, out++)
- {
- if (*in < 0x80)
- { /* lower 7-bits unchanged */
- *out = *in;
- }
- else
- if (*in > 0xC3)
- { /* discard anything above 0xFF */
- *out = '?';
- }
- else
- if (*in & 0xC0)
- { /* parse upper 7-bits */
- if (in >= end)
- *out = 0;
- else
- {
- *out = (((*in) & 0x1F) << 6) | (0x3F & (*(++in)));
- }
- }
- else
- {
- *out = '?'; /* this should never happen */
- }
- }
- *out = 0x00; /* append null */
- ret = string((char *)buf);
- delete[] buf;
-
- return ret;
-}
-
Index: plm/metadata/vorbis/vorbis.cpp
===================================================================
RCS file: /cvsroot/zinf/zinf/plm/metadata/vorbis/vorbis.cpp,v
retrieving revision 1.14
diff -a -u -r1.14 vorbis.cpp
--- plm/metadata/vorbis/vorbis.cpp 11 May 2003 06:34:18 -0000 1.14
+++ plm/metadata/vorbis/vorbis.cpp 18 Aug 2003 16:04:49 -0000
@@ -48,7 +48,6 @@
#include "vorbis/vorbisfile.h"
#include "vcedit.h"
-#include "utf8.h"
#include "i18n.h"
@@ -97,10 +96,8 @@
static void
load_tags (vorbis_comment *vc, tagmap_t& map)
{
- char *decoded;
string entry;
string key;
- string val;
for (int i=0; i<vc->comments; i++)
{
entry = vc->user_comments[i];
@@ -108,14 +105,8 @@
string::size_type sep = entry.find ('=');
key = entry.substr(0, sep);
- utf8_decode (entry.substr(sep+1, string::npos).c_str(), &decoded);
- val = decoded;
- if(decoded){
- free (decoded);
- decoded = NULL;
- }
transform(key.begin(),key.end(),key.begin(),(int(*)(int))&tolower);
- map.insert (pair<string,string>(key, val));
+ map.insert (pair<string,string>(key, entry.substr(sep+1, string::npos)));
// cerr << "found " << key << " with " << val << endl;
}
}
@@ -132,15 +123,11 @@
string key;
for (tagmap_t::iterator it = map.begin(); it != map.end(); it++)
{
- char *encoded;
-
key = (*it).first;
transform(key.begin(),key.end(),key.begin(),(int(*)(int))&toupper);
- utf8_encode ((*it).second.c_str(), &encoded);
- comment = key + '=' + encoded;
- free (encoded);
+ comment = key + '=' + (*it).second ;
vorbis_comment_add (vc, (char*)comment.c_str());
// cerr << "storing " << comment << endl;