renameCabalFile :: Text -> Text -> Text -> Text
renameCabalFile oldName newName = T.unlines . map renameLine . T.lines
    where
        prefixes = ["name:", "executable ", "test-suite "]
        prefixesWithLength :: [(Text, Int)]
        prefixesWithLength = zip prefixes $ map T.length prefixes
        renameLine :: Text -> Text
        renameLine line =
            case catMaybes $ map (rename (line, T.toLower line)) prefixesWithLength of
                l:_ -> l
                []  -> line
        rename :: (Text, Text) -> (Text, Int) -> Maybe Text
        rename (line, lcLine) (lcPrefix, pLen) | lcPrefix `T.isPrefixOf` lcLine =
            let (prefix, rest) = T.splitAt pLen line
                (spaces, value) = T.span (==' ') rest in
            Just $ prefix <> spaces <> T.replace oldName newName value
        rename _ _ = Nothing

--  ---------------------------------------------------------------------
--  | We do some twist for handling build infos seperately to edit them in one editor together
--  with the other stuff. This type show what we really edit here
--
renameCabalFile :: Text -> Text -> Text -> Text
renameCabalFile oldName newName = T.unlines . map renameLine . T.lines
    where
        prefixes = ["name:", "executable ", "test-suite "]
        prefixesWithLength :: [(Text, Int)]
        prefixesWithLength = zip prefixes $ map T.length prefixes
        renameLine :: Text -> Text
        renameLine line =
            case catMaybes $ map (rename (line, T.toLower line)) prefixesWithLength of
                l:_ -> l
                []  -> line
        rename :: (Text, Text) -> (Text, Int) -> Maybe Text
        rename (line, lcLine) (lcPrefix, pLen) | lcPrefix `T.isPrefixOf` lcLine =
            let (prefix, rest) = T.splitAt pLen line
                (spaces, value) = T.span (==' ') rest in
            Just $ prefix <> spaces <> T.replace oldName newName value
        rename _ _ = Nothing

--  ---------------------------------------------------------------------
--  | We do some twist for handling build infos seperately to edit them in one editor together
--  with the other stuff. This type show what we really edit here
--
renameCabalFile oldName newName = T.unlines . map renameLine . T.lines
    where
        prefixes = ["name:", "executable ", "test-suite "]
        prefixesWithLength :: [(Text, Int)]
        prefixesWithLength = zip prefixes $ map T.length prefixes
        renameLine :: Text -> Text
        renameLine line =
            case catMaybes $ map (rename (line, T.toLower line)) prefixesWithLength of
                l:_ -> l
                []  -> line
        rename :: (Text, Text) -> (Text, Int) -> Maybe Text
        rename (line, lcLine) (lcPrefix, pLen) | lcPrefix `T.isPrefixOf` lcLine =
            let (prefix, rest) = T.splitAt pLen line
                (spaces, value) = T.span (==' ') rest in
            Just $ prefix <> spaces <> T.replace oldName newName value
        rename _ _ = Nothing

--  ---------------------------------------------------------------------
--  | We do some twist for handling build infos seperately to edit them in one editor together
--  with the other stuff. This type show what we really edit here
--