Why taglib use wstring internally? And any way to get RAW tag string?

Yanhui Shen shen.elf at gmail.com
Tue Jun 5 21:07:03 UTC 2012


Hi,

Recently I'm using taglib for my player to read/write metainfo,
However I can't understand why it use wstring instead of char* or string.
I think the charset issue should be solved by upper layer.

The only thing I need is a RAW tag string,
with RAW data,  I can check whether it is encoded by utf8,
or use user's choice
or even use mozilla's algorithm for charset detecting,
then I can use iconv() or mb*()/wc*() to convert it.

But I found it was hard to do this with taglib,
Currently I already have these code to approach that goal(to get raw string)

 67 string WStringToStdString(const std::wstring& str)
>  68 {
>  69     const size_t buflen = (str.size()+1) * MB_LEN_MAX;
>  70     vector<char> buf(buflen);
>  71     size_t ret = wcstombs(&buf[0], str.c_str(), buflen);
>  72     return (ret != (size_t)-1) ? string(&buf[0], ret) : string("") ;
>  73 }
>  74
>  75 string StringToStdString(const TagLib::String& str)
>  76 {
>  77     return ( str.isLatin1() || str.isAscii() ) ?
>  78         str.to8Bit() : WStringToStdString(str.toWString());
>  79 }


StringToStdString() works fine in most cases,
but it depends on locale, and I do not want to call setlocale(LC_ALL, "").

So here is my second question, any simplest way to get RAW tag string?

-- 
Best regards,
Yanhui Shen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/taglib-devel/attachments/20120606/46a706f6/attachment.html>


More information about the taglib-devel mailing list