On Thu, Jan 29, 2004 at 02:53:21PM -0000, Simon Marlow wrote: > After Googling around a bit, I found this description of exactly how > Windows interprets command lines in the C runtime: > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng > /htm/progs_12.asp > > As you can see, the rules are indeed very strange,
Very strange indeed.
> but they are
> invertible. I think this code should do the trick:
>
> translate :: String -> String
> translate str = '"' : snd (foldr escape (True,"\"") str)
> where escape '"' (_, str) = (True, '\\' : '"' : str)
> escape '\\' (True, str) = (True, '\\' : '\\' : str)
> escape '\\' (False, str) = (False, '\\' : str)
> escape c (_, str) = (False, c : str)
>
Neat. If I understand the specs correctly, the following should also
work.
translate str = '"' : foldr escape ('"':[]) str
where escape '"' t = '\\':'"':t
escape '\\' t = '\\':'\\':'"':'"':t
escape c t = c:t
Who is going to write the unit test for that?
And assuming both of our solutions satisfy the specs, which one will
work for more versions of Windows? :-)
Greetings,
Carsten
--
Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
http://carsten.codimi.de/
PGP/GPG key on the pgp.net key servers,
fingerprint on my home page.
pgp00000.pgp
Description: PGP signature
_______________________________________________ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
