English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] How do I create files with UTF-8 file names?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-15 (14:16)
From: Peter Jolly <peter@j...>
Subject: Re: [Caml-list] How do I create files with UTF-8 file names?
Mattias Waldau wrote:
> I have a filename as an UTF-8 encoded string. I need to be able to 
> handle strange chars like accents, Asian chars etc.
> Is there any way to create a file with that name? I only need it on Win32.

Windows uses UTF-16 for filenames, but provides a non-Unicode interface 
for legacy applications; the standard open() function that OCaml's 
open_out wraps appears to use the legacy interface.  The precise 
codepage this uses is system-dependent, and AFAIK there's no way for a 
program to determine what it is without calling out to the Win32 API, 
but you can be pretty sure it won't be UTF-8.

In other words, there is no reliable way to use a filename containing 
non-ASCII characters with OCaml's standard library.

> Or should I solve this problem by talking directly to the Win32-api?

This is probably the best solution.  A combination of CreateFileW() and 
MultiByteToWideChar() should do what you want.

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners