-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathCamelCase.hs
33 lines (27 loc) · 915 Bytes
/
CamelCase.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
-- ghc -O2 -fspec-constr-recursive=10 -fmax-worker-args=16
-- Convert the input file to camel case and write to stdout
import Data.Maybe (fromJust, isJust)
import System.Environment (getArgs)
import System.IO (Handle, IOMode(..), openFile, stdout)
import qualified Streamly.Prelude as S
import qualified Streamly.Internal.FileSystem.Handle as FH
camelCase :: Handle -> Handle -> IO ()
camelCase src dst =
FH.fromBytes dst
$ S.map fromJust
$ S.filter isJust
$ S.map snd
$ S.scanl' step (True, Nothing)
$ FH.toBytes src
where
step (wasSpace, _) x =
if x == 0x0a || x >= 0x41 && x <= 0x5a
then (False, Just x)
else if x >= 0x61 && x <= 0x7a
then (False, Just $ if wasSpace then x - 32 else x)
else (True, Nothing)
main :: IO ()
main = do
name <- fmap head getArgs
src <- openFile name ReadMode
camelCase src stdout