
Hi, I'm trying to download a file in UTF-8 with libcurl(1.3.5) and GHC 6.12:
import Network.Curl
u = "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt" main = curlGetString u [] >>= putStrLn . snd
Which doesn't print the characters correctly. If i read the file from local storage with getFile it is displayed properly.

В сообщении от 23 апреля 2010 02:36:07 Rickard Karlsson написал:
Hi,
I'm trying to download a file in UTF-8 with libcurl(1.3.5) and GHC 6.12:
import Network.Curl
u = "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt" main = curlGetString u [] >>= putStrLn . snd
Which doesn't print the characters correctly. If i read the file from local storage with getFile it is displayed properly.
I think curl knows nothing about encoding and convert one byte to one Char and getFile uses new IO which uses system locale to choose encoding. encodeString from utf8-string package could fix that.

Thanks, i just used decodeString.
import Network.Curl import Codec.Binary.UTF8.String u = "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt" main = curlGetString u [] >>= putStrLn . decodeString . snd
2010/4/23 Khudyakov Alexey
В сообщении от 23 апреля 2010 02:36:07 Rickard Karlsson написал:
Hi,
I'm trying to download a file in UTF-8 with libcurl(1.3.5) and GHC 6.12:
import Network.Curl
u = "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt" main = curlGetString u [] >>= putStrLn . snd
Which doesn't print the characters correctly. If i read the file from local storage with getFile it is displayed properly.
I think curl knows nothing about encoding and convert one byte to one Char and getFile uses new IO which uses system locale to choose encoding.
encodeString from utf8-string package could fix that. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 2010-04-23, Khudyakov Alexey
В сообщении от 23 апреля 2010 02:36:07 Rickard Karlsson написал:
Hi,
I'm trying to download a file in UTF-8 with libcurl(1.3.5) and GHC 6.12:
import Network.Curl
u = "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt" main = curlGetString u [] >>= putStrLn . snd
Which doesn't print the characters correctly. If i read the file from local storage with getFile it is displayed properly.
I think curl knows nothing about encoding and convert one byte to one Char and getFile uses new IO which uses system locale to choose encoding.
Then clearly curl should not return Strings, but byte arrays. Of course, curl can very well look at the headers which in this case do specify UTF-8, and so perhaps it should do the translation itself. -- Aaron Denney -><-
participants (3)
-
Aaron Denney
-
Khudyakov Alexey
-
Rickard Karlsson