Daniël Mantione a écrit :
Op Thu, 7 Dec 2006, schreef Dominique Leducq:
Hello folks,
I need to do some conversion from one character set encoding, given by its
name (e.g. value of encoding attribute in XML header), to another (used
internally, based on locale), and back.
I know of iconv on Linux/Unix OSes, but I would like to do it in a portable
manner, if possible.
Do you know an existing solution ?
I saw there is a 'charset' unit in the RTL of FPC, but it is not documented,
ant it is not yet very clear to me how to use it or even if it does what I
need...
For the website generation, I use a tweaked cwstring widestring manager,
see http://svn.freepascal.org/svn/html/adp2html.pp. For a more structural
and portable approach, the functionality to specify encodings needs to be
integrated into the widestringmanager.
Daniël
------------------------------------------------------------------------
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Thanks Daniël,
The changes you made to cwstring is merely to export the iconv API from
it. As I stated, I already know how to use iconv on Linux/Unix. And I
don't necessarily have to deal with widestrings (for example to convert
latin-1 to UTF-8).
On MS Windows, I found WideCharToMultiByte and MultiByteToWideChar,
which take a numerical CodePage as parameter. But I don't know how to
map a charset name ('UTF-8', 'Latin-1', 'ISO-8859-15'...) to a CodePage
(any hint ?).
So apparently there doesn't exist a portable API on top of this.
Dominique
P.S.: About the cwstring unit, I experimented that nl_langinfo(CODESET)
always gives ANSI_X3.4-1968 (US-ASCII), unless you call
setlocale(LC_CTYPE, ...) before (... here being an explicit locale name,
or empty string to use the locale environment variables setting). So the
widestring manager don't work as expected...
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal