Re: [Haskell-cafe] File name encodings

2008-12-10 Thread Duncan Coutts
On Tue, 2008-12-09 at 18:17 -0800, Don Stewart wrote:
> Oh, perhaps you want to 'decode' the string that 
> dirOpenDialog returns.
> 
> redcom:
> > Hi Don,
> > 
> > must be doing something wrong.
> > 
> > The messed up string originates from calling Graphics.UI.WX.dirOpenDialog  
> > and selecting a directory with Umlauts.

This is such a huge can of worms.

The Gtk open dialog has two functions for returning the selected file
name. One returns a string suitable to use with operating system
functions like readFile while the other returns a unicode string
suitable to display in the user interface.

These need not be the same, or even inter-convertible. On Windows they
are identical because it uses unicode for file names, however unix uses
byte strings and people sometimes use utf8 and sometimes some other
locale.

So it's not safe to convert a file name to a unicode string and then
back again and expect to be saving the same file. Document editor
programs typically remember both strings so that it can save the file
again even if displaying the file name was lossy (eg due to locale
conversion errors like invalid utf8).

Yet another reason why FilePath /= String (except on Windows where it
does).

Duncan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] File name encodings

2008-12-09 Thread Don Stewart
Oh, perhaps you want to 'decode' the string that 
dirOpenDialog returns.

redcom:
> Hi Don,
> 
> must be doing something wrong.
> 
> The messed up string originates from calling Graphics.UI.WX.dirOpenDialog  
> and selecting a directory with Umlauts.
> 
> The encode function doesn't seem to help here as it's too far at the end  
> of the chain.
> 
> Günther
> 
> Am 10.12.2008, 02:45 Uhr, schrieb Don Stewart <[EMAIL PROTECTED]>:
> 
> >redcom:
> >>Hi,
> >>
> >>how can I convert a file name with for example umlauts (ü, ä ... ) into
> >>UTF8, or some other format that I can actually use it?
> >>
> >>Günther
> >>
> >
> >Using the utf8-string package to encode the file name string.
> >
> >e.g.
> >
> >x <- readFile (encode "ኃይሌ ገብረሥላሴ")
> >
> >http://hackage.haskell.org/cgi-bin/hackage-scripts/package/utf8-string
> 
> 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] File name encodings

2008-12-09 Thread Don Stewart
dons:
> redcom:
> > Hi,
> > 
> > how can I convert a file name with for example umlauts (ü, ä ... ) into  
> > UTF8, or some other format that I can actually use it?
> > 
> > Günther
> > 
> 
> Using the utf8-string package to encode the file name string.
> 
> e.g.
> 
> x <- readFile (encode "ኃይሌ ገብረሥላሴ")
> 
> http://hackage.haskell.org/cgi-bin/hackage-scripts/package/utf8-string

In fact, utf8-string readFile already encodes the file name, so


http://hackage.haskell.org/packages/archive/utf8-string/0.3.3/doc/html/System-IO-UTF8.html#v%3AreadFile

should be enough.

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] File name encodings

2008-12-09 Thread Don Stewart
redcom:
> Hi,
> 
> how can I convert a file name with for example umlauts (ü, ä ... ) into  
> UTF8, or some other format that I can actually use it?
> 
> Günther
> 

Using the utf8-string package to encode the file name string.

e.g.

x <- readFile (encode "ኃይሌ ገብረሥላሴ")

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/utf8-string
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe