[Haskell-cafe] How to reverse ghc encoding of command line arguments
Donn Cave
donn at avvanta.com
Sun Nov 16 18:46:44 UTC 2014
quoth Ben Franksen <ben.franksen at online.de>
...
> Perhaps it is simpler to write our own getArgs/getEnv functions and directly
> convert the data we get from the system to a proper (Unicode) String?
I may be confused here - trying this out, I seem to be getting
garbage I don't understand from System.Environment getArgs.
But there's a System.Posix.Env.ByteString getArgs, that looks like
just what you propose above.
import qualified Data.ByteString.Char8 as P
import qualified System.Posix.Env.ByteString as B
import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
argsb <- B.getArgs
putStrLn ("byte args: " ++ show(argsb))
let argsu = map (encodeUtf8 . T.pack . P.unpack) argsb
putStrLn ("UTF8 byte args: " ++ show(argsu))
$ ./cvtargs [string that perhaps should not be in this email!]
byte args: ["S\228kkij\228rven","Polkka"]
UTF8 byte args: ["S\195\164kkij\195\164rven","Polkka"]
Donn
More information about the Haskell-Cafe
mailing list