Dear experts,
I am currently trying to convert a string to ISO-8859-1 using the following code fragment:
cCharSetConv conv(NULL, "ISO-8859-1"); const char *s_converted = conv.Convert(string);
Running VDR with UTF-8, this conversion failes (i.e., s_converted == string). This is due to the fact, that cCharSetConv::SystemCharacterTable contains "NULL" instead of "UTF-8". This is because systemCharacterTable is never set:
void cCharSetConv::SetSystemCharacterTable(const char *CharacterTable) { free(systemCharacterTable); systemCharacterTable = NULL; if (!strcasestr(CharacterTable, "UTF-8")) { .. systemCharacterTable = strdup(CharacterTable); } }
Is there a reason for this?
The conversion works fine, if I use "UTF-8" instead of "NULL": cCharSetConv conv("UTF-8", "ISO-8859-1");
Best Regards, Joachim.
On 05/18/08 18:27, Joachim Wilke wrote:
systemCharacterTable is only set if it is a single byte character set, which UTF-8 is not.
The conversion works fine, if I use "UTF-8" instead of "NULL": cCharSetConv conv("UTF-8", "ISO-8859-1");
Good, so it works as designed ;-)
Klaus
2008/5/18 Klaus Schmidinger Klaus.Schmidinger@cadsoft.de:
Hi Klaus,
so what do I have to do, to convert a string (from whatever encoding VDR currently uses) to ISO-8859-1 ?
Do I really have to do:
if(cCharSetConv::SystemCharacterTable == NULL) cCharSetConv conv("UTF-8", "ISO-8859-1"); else cCharSetConv conv(NULL, "ISO-8859-1"); const char *s_converted = conv.Convert(string);
This is against the generic use of "NULL" as parameter, in my opinion.
Regards, Joachim.
On 05/18/08 18:53, Joachim Wilke wrote:
Actually this conversion wasn't necessary so far. It was always about converting strings from "some external character set" to "the character set used by the system".
But I guess it should be ok to do this (modified lines marked with MOD):
cCharSetConv::cCharSetConv(const char *FromCode, const char *ToCode) { if (!FromCode) FromCode = systemCharacterTable ? systemCharacterTable : "UTF-8"; //MOD if (!ToCode) ToCode = "UTF-8"; cd = iconv_open(ToCode, FromCode); //MOD result = NULL; length = 0; } ... const char *cCharSetConv::Convert(const char *From, char *To, size_t ToLength) { if (From && *From) { //MOD
Please try this and let me know if it works and doesn't break anything else.
Klaus
2008/5/18 Klaus Schmidinger Klaus.Schmidinger@cadsoft.de:
[...]
Please try this and let me know if it works and doesn't break anything else.
Thanks for the fast patch creation! I tested in on my local installation and it worked for me, I couldn't find any errors.
Best Regards, Joachim.