on master help sign in
Data.String.Extra: more String utilities
commit075504add45b8ceb62972b3cd99111038e32dc41 authorMichael Morgan <morgan.michael@me.com> dateMon 4 Dec 2017, 11:43 (9 years ago) parent4777dce
1 file changed+13
libs/contrib/Data/String/Extra.idr+13
libs/contrib/Data/String/Extra.idr+13
@@ -73,3 +73,16 @@ index n str with (unpack str)
7373 index n str | [] = Nothing
7474 index Z str | (x :: xs) = Just x
7575 index (S n) str | (x :: xs) = index n str | xs
76+
77+||| Produce a string by repeating the character `c` `n` times.
78+replicate : (n : Nat) -> (c : Char) -> String
79+replicate n c = pack $ replicate n c
80+
81+||| Indent a given string by `n` spaces.
82+indent : (n : Nat) -> String -> String
83+indent n x = replicate n ' ' ++ x
84+
85+||| Indent each line of a given string by `n` spaces.
86+indentLines : (n : Nat) -> String -> String
87+indentLines n str = unlines $ map (indent n) $ lines str
88+