Is there a cross-platform way to parse program arguments into a list of ByteString
(instead of a list of String
, as in System.Environment.getArgs
)?
I am aware of System.Posix.Env.ByteString.getArgs
from the unix
package, but I would like to be able to run my program on Windows without cygwin. I am also aware of Data.ByteString.Char8.pack
, but that truncates characters to 8 bits, and I would like to be able to process any Unicode character sequence of bytes.
EDIT: My program is a simple cipher which xor's the bits of the key against the bits of the message. For that reason, I would prefer to process the exact bits that were provided to the program instead of translating them into UTF-8 and back first.
fromString
function in Data.ByteString.UTF8 "converts a Haskell string into a UTF8 encoded bytestring." - see hackage.haskell.org/package/utf8-string-0.3.8/docs/… – SelaText
? ByteString isn't really that Unicode friendly. Apart from that issue, you could transform theString
to aCStringLen
and create aByteString
from that. After all, you're already inIO
. – InmeshString
withord
andchr
? – Finagleord
/chr
would yield Unicode codepoints above 255, which I would need to translate into bytes, and there's no certainty that the method I might use to do so would match the character-encoding scheme in which it was provided (if it is indeed provided in a valid character-encoding scheme). – KlaipedaSystem.Environment
- if you look at these sources,getArgs
converts to the system encoding at the last moment, it reads the data as "raw bytes". It seems that the code you want already exists, the piece you want is simply not exported as a function. – Contrabandist