on master help sign in
Add isNL/lines
commit44dd3befb089d89be75c13fc2b0551d638b463bd authorEdwin Brady <ecb10@st-andrews.ac.uk> dateThu 15 Nov 2012, 12:34 (14 years ago) parent64fc043
2 files changed+12
lib/Prelude/Chars.idr+3 lib/Prelude/Strings.idr+9
lib/Prelude/Chars.idr+3
@@ -22,6 +22,9 @@ isSpace x = x == ' ' || x == '\t' || x == '\r' ||
2222 x == '\n' || x == '\f' || x == '\v' ||
2323 x == '\xa0'
2424
25+isNL : Char -> Bool
26+isNL x = x == '\r' || x == '\n'
27+
2528toUpper : Char -> Char
2629toUpper x = if (isLower x)
2730 then (prim__intToChar (prim__charToInt x - 32))
lib/Prelude/Strings.idr+9
@@ -74,6 +74,15 @@ words' s = case dropWhile isSpace s of
7474words : String -> List String
7575words s = map pack $ words' $ unpack s
7676
77+lines' : List Char -> List (List Char)
78+lines' s = case dropWhile isNL s of
79+ [] => []
80+ s' => let (w, s'') = break isSpace s'
81+ in w :: words' s''
82+
83+lines : String -> List String
84+lines s = map pack $ words' $ unpack s
85+
7786partial
7887foldr1 : (a -> a -> a) -> List a -> a
7988foldr1 f [x] = x