Enumerating encodings

Manuel Martín mmartin at ceyd.es
Tue Dec 12 10:07:21 PST 2006


First of all, thank you very much Vadim for your reply.
I see you get time from sleeping for helping people like me.

 >MM> I have files with different encodigs: A file is an old MS-Dos file;
 >MM> other file is the result of an application that writes 8-bit chars,
 >MM> but I don't know which encoding it uses internally; other file is
 >MM> encoded in my system's default, but I want to convert it to UTF for
 >MM> mailing to other country; other is c++ code written before I began
 >MM> using Unicode and now all my sources are UTF8; and so on.
 >MM> So, I'm making this convert-applet.
 >
 > So you know the input encoding (either explicitly or as
 >wxLocale::GetSystemEncoding() -- which you don't even need to use
 >explicitly in your code as you can just use wxFONTENCODING_SYSTEM) and

Not always. I need to print old .txt files saved in an old diskette
in an old and unknown encoding. I have to try several encodings to
find the right one.

 >know the output one (UTF-8). Hence you can construct wxCSConv for the 
 >input
 >encoding and use it to convert to wchar_t and then use wxMBConvUTF8 to
 >convert to UTF-8. And you may get errors in the process (in theory >during
 >both steps but in practice only for the first one). I think I >understand
 >what you need to do. But I still don't see what exactly is the problem?
 >
 > Regards,
 >VZ

My question, in short, is:
How do I enumerate all the encodings that my_OS && wx can manage?

As you can see in my first post,
- wxFontMapper::IsEncodingAvailable discards some encodings like UTF
- wxFontEnumerator::GetEncodings asserts
- testing (creating wxCSConv) each wx-predefined fails for some
   encodings

After digging into wx sources, I can answer myself:
I have to:
- Iterate through all wxFONTENCODING_xxxx
- Use the not documented wxEncodingToCodepage (found at utils.cpp)
   I know this is a specific WS-Windows code.
- If this usefull function returns -1, the encoding is not avaible.

With this, I'm doing something like a tiny "recode"
    recode.progiciels-bpi.ca
for MS-Win32 with GDI.

Regards
Manolo





More information about the wx-users mailing list