getSection :: AsString a => String -> String -> Either String ([a], String)
getSection title orig =
    case lines orig of
        [] -> Left "Unexpected EOF when looking for a section"
        l1:ls1
            | l1 == begin ->
                case break (== end) ls1 of
                    (here, _:"":rest) -> do
                        here' <- mapM fromString' here
                        Right (here', unlines rest)
                    (_, _) -> Left $ "Could not find section end: " ++ title
            | otherwise -> Left $ "Could not find section start: " ++ title
  where
    begin = "-- BEGIN " ++ title
    end = "-- END " ++ title

    fromString' x = do
        (y, z) <- fromString x
        if null z
            then return y
            else Left $ "Unconsumed input on line: " ++ x

-- | Used for Hackage distribution purposes.
getSection :: AsString a => String -> String -> Either String ([a], String)
getSection title orig =
    case lines orig of
        [] -> Left "Unexpected EOF when looking for a section"
        l1:ls1
            | l1 == begin ->
                case break (== end) ls1 of
                    (here, _:"":rest) -> do
                        here' <- mapM fromString' here
                        Right (here', unlines rest)
                    (_, _) -> Left $ "Could not find section end: " ++ title
            | otherwise -> Left $ "Could not find section start: " ++ title
  where
    begin = "-- BEGIN " ++ title
    end = "-- END " ++ title

    fromString' x = do
        (y, z) <- fromString x
        if null z
            then return y
            else Left $ "Unconsumed input on line: " ++ x

-- | Used for Hackage distribution purposes.
getSection title orig =
    case lines orig of
        [] -> Left "Unexpected EOF when looking for a section"
        l1:ls1
            | l1 == begin ->
                case break (== end) ls1 of
                    (here, _:"":rest) -> do
                        here' <- mapM fromString' here
                        Right (here', unlines rest)
                    (_, _) -> Left $ "Could not find section end: " ++ title
            | otherwise -> Left $ "Could not find section start: " ++ title
  where
    begin = "-- BEGIN " ++ title
    end = "-- END " ++ title

    fromString' x = do
        (y, z) <- fromString x
        if null z
            then return y
            else Left $ "Unconsumed input on line: " ++ x

-- | Used for Hackage distribution purposes.