0 | module Libraries.Utils.String
 1 |
 2 | %default total
 3 |
 4 | export
 5 | stripSurrounds : (lead : Nat) -> (tail : Nat) -> String -> String
 6 | stripSurrounds lead tail str = substr lead (length str `minus` (lead + tail)) str
 7 |
 8 | export
 9 | stripQuotes : String -> String
10 | stripQuotes = stripSurrounds 1 1
11 |
12 | export
13 | lowerFirst : String -> Bool
14 | lowerFirst "" = False
15 | lowerFirst str = isLower $ assert_total $ prim__strHead str
16 |
17 | escapeGeneric : Char -> List Char -> String -> String
18 | escapeGeneric esc toEscape = pack . foldr escape [] . unpack
19 |   where
20 |     escape : Char -> List Char -> List Char
21 |     escape c cs =
22 |       if elem c toEscape
23 |         then (esc :: c :: cs)
24 |         else (c :: cs)
25 |
26 | export
27 | escapeStringUnix : String -> String
28 | escapeStringUnix = escapeGeneric '\\' ['"', '\\']
29 |
30 | export
31 | escapeStringChez : String -> String
32 | escapeStringChez = escapeGeneric '\\' ['\'', '\\']
33 |