-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnconcatUkr.hs
43 lines (38 loc) · 1.76 KB
/
UnconcatUkr.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- |
-- Module : Main
-- Copyright : (c) OleksandrZhabenko 2021-2025
-- License : MIT
-- Stability : Experimental
-- Maintainer : [email protected]
--
--
{-# OPTIONS_GHC -threaded -rtsopts #-}
{-# OPTIONS_HADDOCK -show-extensions #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import GHC.Base
import Aftovolio.Ukrainian.ReverseConcatenations
import System.Environment (getArgs)
import Text.Read (readMaybe)
import Data.Maybe (fromMaybe)
import System.IO
import GHC.List
import Data.Char (isDigit)
main :: IO ()
main = do
args0 <- getArgs
let !fstA = fromMaybe 1 (readMaybe (mconcat . take 1 $ args0)::Maybe Int)
!args
| fstA == 1 = filter (/= "-i") args0
| otherwise = filter (/= "-i") . drop 1 $ args0
!stdinput = any (== "-i") args0 -- If you specify \"-i\" then reads the input text from the stdin otherwise from the file specified instead.
!filterMusicInformation = any (== "-m") args -- ^ If you specify as one of the command line arguments \"-m\" then the digits and symbols like \'=\' and \'_\' are filtered, so cleaning from the music information is done.
if stdinput then do
contents <- getContents
putStrLn . reverseConcatenations fstA . (if filterMusicInformation then filter (\c -> (not . isDigit $ c) && c /= '=' && c /= '_') else id) $ contents
else do
let !file = concat . take 1 $ args
!toFile = concat . drop 1 . take 2 $ args
if null file then putStrLn "No file to read the Ukrainian text is specified. "
else readFile file >>= return . reverseConcatenations fstA . (if filterMusicInformation then filter (\c -> (not . isDigit $ c) && c /= '=' && c /= '_') else id) >>= (\ts -> if null toFile then putStrLn ts else writeFile toFile ts)