0 | module Internal.String
6 | import Data.String.Extra
13 | range : Nat -> List Nat
15 | reverse (drop 1 (iterate next n))
17 | next : Nat -> Maybe Nat
23 | zipWithIndex : List a -> List (a, Nat)
25 | zip l (range (length l))
29 | findAll : Eq a => List a -> List a -> List Nat
31 | reverse (findAllHelper l k 0 [])
33 | findAllHelper : List a -> List a -> Nat -> List Nat -> List Nat
34 | findAllHelper l k index acc =
41 | if isPrefixOf k l then
46 | findAllHelper (drop 1 l) k (index + 1) nextAcc
50 | replace : Eq a => List a -> List a -> List a -> List a
53 | matches = findAll l k
55 | skipLen = case length k of
63 | reverse $
fst $
foldl (\(acc, skip), (c, i) =>
68 | if isJust (find (== i) matches) then
70 | (repl ++ acc, Just skipLen)
73 | ) ([], (the (Maybe Nat) Nothing)) (zipWithIndex l)
76 | wrap : String -> String -> String
81 | listOp : (List Char -> List Char) -> String -> String
87 | findAll : String -> String -> List Nat
88 | findAll str lookup =
89 | List.findAll (unpack str) (unpack lookup)
93 | replace : String -> String -> String -> String
95 | pack (List.replace (unpack str) (unpack k) (unpack v))
98 | filter : (Char -> Bool) -> String -> String
100 | pack . filter test . unpack
103 | showList : (a -> String) -> List a -> String
105 | "[" ++ (join "," (map f els)) ++ "]"
108 | split : Char -> String -> List String
110 | ( map pack ) . Prelude.toList . (Data.List.split (== c)) . unpack
114 | quote : String -> String
117 | . (replace "\n" "\\n")
118 | . (replace "\"" "\\\"")