From taglib-devel Fri Feb 02 00:12:39 2007 From: Ray Date: Fri, 02 Feb 2007 00:12:39 +0000 To: taglib-devel Subject: bug encoding multibyte? Message-Id: <662282.3465.qm () web23309 ! mail ! ird ! yahoo ! com> X-MARC-Message: https://marc.info/?l=taglib-devel&m=117037517424573 hi, i've been having problem storing multibyte strings in mp3 tags -- i verify the input going in looks valid, but when i read the tag out of the mp3 and examine the data, it looks like garbage. can someone tell me if this is a mistake on my part? thanks ray #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { const TagLib::String::Type enc_ = TagLib::String::UTF16BE; const char* data_ = "foo喆bar"; const char* l; if ( (l = setlocale(LC_ALL, "en_US.UTF-8")) == NULL) { cout << "locale set" << endl; } const size_t n = strlen(data_)*sizeof(wchar_t); wchar_t* w = new wchar_t[n]; memset(w, 0, n); const size_t len = mbstowcs(w, data_, n); cout << "input=" << n << " bytes, len=" << len << endl; char p[MB_CUR_MAX+1]; for (int c=0; c0) p[x]=0; cout << "multibyte char[" << c << "] = '" << p << "' (" << x << " bytes)" << endl; } const TagLib::String s(w, enc_); cout << "encoded input as [" << enc_ << "] '" << data_ << "', unicode='" << s.toCString(true) << "', latin1='" << s.toCString() << "'" << endl; delete [] w; if (access("test.mp3", R_OK | W_OK) != 0) { cerr << "test file unavailable for write" << endl; return 1; } TagLib::MPEG::File f("test.mp3"); TagLib::ID3v2::Tag* tag = f.ID3v2Tag(true); tag->setArtist(s); if (!f.save()) { cerr << "unable to save tag to mp3!" << endl; return 2; } cout << "saved tag to file, re-opening" << endl; TagLib::MPEG::File f1("test.mp3"); if ( (tag = f1.ID3v2Tag(false)) == NULL) { cerr << "no tag on mp3 even tho we just save it out?" << endl; return 3; } cout << "artist='"; const TagLib::String artist = tag->artist(); if (artist == TagLib::String::null) { cout << ""; } else { cout << artist.toCString(true); } cout << "'" << endl; return 0; } ___________________________________________________________ What kind of emailer are you? Find out today - get a free analysis of your email personality. Take the quiz at the Yahoo! Mail Championship. http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk _______________________________________________ taglib-devel mailing list taglib-devel@kde.org https://mail.kde.org/mailman/listinfo/taglib-devel