• Acolyte of the Butterfly
    Acolyte of the Butterfly
    walkero
    Posts: 102 from 2006/3/1
    Hello all again.
    I am having a hard time to convert UTF8 text to ISO-8859-7. Here is what I am doing so far

    Code:

    const char* to = "ISO-8859-7";
    const char* from = "UTF-8";
    size_t text_len = 0;
    APTR text = <here is the unicode text>

    char *output;
    LONG output_len = 0;

    ULONG fromMib = GetCharsetNumber(from, CSF_IANA_MIMENAME);
    if (fromMib == 0)
    fromMib = GetCharsetNumber(from, CSF_IANA_NAME);
    if (fromMib == 0)
    fromMib = GetCharsetNumber(from, CSF_IANA_ALIAS);

    ULONG toMib = GetCharsetNumber(to, CSF_IANA_MIMENAME);
    if (toMib == 0)
    toMib = GetCharsetNumber(to, CSF_IANA_NAME);
    if (toMib == 0)
    toMib = GetCharsetNumber(to, CSF_IANA_ALIAS);

    printf("DBG: %s, %ld -> %s, %ldn", from, fromMib, to, toMib);
    output_len = GetLength(text, text_len, fromMib);
    printf("DBG: output_len %ldn", output_len);

    LONG dstEnc = 0;
    struct TagItem tags[] = { { CST_DoNotTerminate, FALSE }, { CST_GetDestEncoding, &dstEnc }, { TAG_DONE, 0 } };

    printf("DBG: Text: %dn%sn", text_len, (char *)text);

    LONG result = ConvertTagList((APTR)text, text_len, (APTR)output, output_len, fromMib, toMib, tags);
    printf("DBG: dstEnc: %ldn", dstEnc);
    if (result <= 0)
    {
    printf("DBG: failed converting from '%s' to '%s'n", from, to);
    return 2;
    }
    printf("DBG: ~%s~n", output);


    What I am getting at the debug output is the following:

    Code:

    DBG: UTF-8, 106 -> ISO-8859-7, 10
    DBG: output_len 32
    DBG: Text: 58
    <here is the unicode text printed>

    DBG: dstEnc: 10
    DBG: failed converting from 'UTF-8' to 'ISO-8859-7'
    DBG: ~(null)~


    Although that it gets the text correctly, and this is visible from the correct length count (Text: 58) and when it is printed at the terminal, the conversion of it always fail.

    Also, the CST_GetDestEncoding seems to get the right Mib for ISO-8859-7

    Any ideas will be helpful.
  • »22.02.24 - 22:32
    Profile Visit Website