utf8 tag processing

Ray whatdoineed2do at yahoo.co.uk
Wed Jan 17 01:51:01 CET 2007


hi folks,

i think am a little off topic but i've kinda run out
of ideas of my own; i am writing a cmd line tool to
tag mp3s with utf8 unicode strings using taglib.

however i've run into a problem whereby if the unicode
string from argv[] always seem to get messed up
however, if i use the same static string within the
code, it can be encoded and retrieved from the tag
fine.  even if the static string and the input are the
same (as shown by memcmp) the results of getting the
data back is still wrong.

my terminal has LANG="en_US.utf8"

can anyone point me at where i am going wrong?
thanks
ray


#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <iostream>

#include <fileref.h>
#include <tfile.h>
#include <tag.h>
#include <id3v2tag.h>

using namespace std;

int main(int argc, char *argv[])
{
    const char* const  data = "&#38518;&#21894;";

    setlocale(LC_ALL, "en_US.utf8");

    const size_t  b = strlen(data);
    TagLib::ID3v2::Tag  t;

    t.setArtist(TagLib::String(data,
TagLib::String::UTF8));
    cout << "original utf8='" << data << "', as
(latin) cstr='" << t.artist().toCString() << "', as
(unicode) cstr='" << t.artist().toCString(true) << "'"
<< endl;

    if (argc == 2) {
	if (strlen(argv[1]) == b && memcmp(data, argv[1], b)
== 0) {
	    cout << "input and static data are the same" <<
endl;
	}

	t.setComment(TagLib::String(argv[1],
TagLib::String::UTF8));
	cout << "original utf8='" << argv[1] << "', as
(latin) cstr='" << t.comment().toCString() << "', as
(unicode) cstr='" << t.comment().toCString(true) <<
"'" << endl;
    }
}


		
___________________________________________________________ 
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com


More information about the taglib-devel mailing list