Created
August 17, 2015 15:31
-
-
Save ha2ne2/8cc52c6979c05efa7023 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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