Permalink
Browse files

Remove redundant parser branch in readpIPv6

The special case of compressed zeroes occurring at the end of an IPv6
address string (e.g. "1:1::") supported by the more general case of
compressed zeroes in the middle or end of the string. Generalize the
branch parsing compressed zeroes in the middle of the string to support
compressed zeroes at the end of the string, and remove the redundant
special case branch.
  • Loading branch information...
1 parent 9b0160d commit a15e3eab574116b539f79a1cdb75cabacbfd8dbb @sebnow committed Oct 16, 2011
Showing with 4 additions and 4 deletions.
  1. +4 −4 Data/Network/Address/IP.hs
@@ -175,13 +175,13 @@ readpIPv6 :: ReadP IPv6
readpIPv6 = fmap (toAddress . word16sToInteger) $ choice
[ liftM2 (:) readHexP (count 7 (char ':' >> readHexP))
, do
- a <- upTo1 6 (readHexP <<* char ':')
- c <- upTo1 (8 - length a) (char ':' >> readHexP)
+ a <- upTo1 7 (readHexP <<* char ':')
+ c <- choice [ upTo1 (8 - length a) (char ':' >> readHexP)
+ , char ':' >> return []
+ ]
let b = replicate (8 - (length a + length c)) 0
return $ a ++ b ++ c
, char ':' >> upTo1 7 (char ':' >> readHexP)
- , upTo1 7 (readHexP <<* char ':') <<* char ':' >>= \xs ->
- return (xs ++ replicate (8 - length xs) 0)
, string "::" >> return [0]
]

0 comments on commit a15e3ea

Please sign in to comment.