Skip to content
Snippets Groups Projects
Commit 6c057015 authored by Alice Brenon's avatar Alice Brenon
Browse files

Take linearize out into a module for reuse

parent 2a451868
No related branches found
No related tags found
No related merge requests found
module Text.Filter.Linearize
( linearize ) where
import Data.Char (isUpper, isLower)
linearize :: Bool -> String -> String
linearize _ "" = ""
linearize b ('¬':'\n':s) = linearize b s
linearize b ('\n':'\n':s) = "\n\n" ++ linearize b s
linearize True ('.':'\n':c0:c1:c2:s)
| isUpper c0 && isLower c1 && isLower c2 = ".\n\n" ++ c0:c1:c2:linearize True s
linearize b ('.':'\n':'—':s) = ".\n\n—" ++ linearize b s
linearize b ('\n':s) = ' ' : linearize b s
linearize b ('-':'\n':c:s)
| isUpper c = '-' : c : linearize b s
linearize b (c:s) = c : linearize b s
#!/usr/bin/env -S runhaskell --ghc-arg="-Wall" --ghc-arg="-i lib"
import Data.Char (isUpper, isLower)
import System.Environment (getArgs)
import System.Script (syntax)
import Text.Filter (xargs)
linearize :: String -> String
linearize "" = ""
linearize ('¬':'\n':s) = linearize s
linearize ('\n':'\n':s) = "\n\n" ++ linearize s
linearize ('.':'\n':c0:c1:c2:s)
| isUpper c0 && isLower c1 && isLower c2 = ".\n\n" ++ c0:c1:c2:linearize s
linearize ('.':'\n':'—':s) = ".\n\n—" ++ linearize s
linearize ('\n':s) = ' ' : linearize s
linearize ('-':'\n':c:s)
| isUpper c = '-' : c : linearize s
linearize (c:s) = c : linearize s
import Text.Filter.Linearize (linearize)
main :: IO ()
main = getArgs >>= cli
where
cli [target] = xargs (pure.linearize) target
cli _ = syntax "TARGET_DIR"
cli [inferParagraphs, target] =
xargs (pure.linearize (inferParagraphs == "Y")) target
cli _ = syntax "[Y|N] TARGET_DIR"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment