Skip to content

Instantly share code, notes, and snippets.

@ha2ne2
Created August 17, 2015 15:31
Show Gist options
  • Save ha2ne2/8cc52c6979c05efa7023 to your computer and use it in GitHub Desktop.
Save ha2ne2/8cc52c6979c05efa7023 to your computer and use it in GitHub Desktop.
import System.Environment (getArgs)
interactWith function inputFile outputFile = do
input <- readFile inputFile
writeFile outputFile (function input)
main = mainWith myFunction
where mainWith fn = do
args <- getArgs
case args of
[input,output] -> interactWith fn input output
_ -> putStrLn "error: exactly two arguments needed"
myFunction = fixLines -- ここを= idとか= aaaLinesに替える
aaaLines :: String -> String
aaaLines [] = []
aaaLines (x:xs) =
case x of
'\r' -> '\r'
'\n' -> '\n'
' ' -> ' '
_ -> 'a'
: aaaLines xs
splitLines :: String -> [String]
splitLines [] = []
splitLines cs =
let (pre,suf) = break isLineTerminator cs
in pre : case suf of
('\r':'\n':rest) -> splitLines rest
('\r':rest) -> splitLines rest
('\n':rest) -> splitLines rest
_ -> []
isLineTerminator c = c == '\r' || c == '\n'
fixLines :: String -> String
fixLines input = unlines (splitLines input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment