blob: 4025cf6840ab3f1e22edb758293e55cc395e01d0 (
plain)
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
34
35
36
37
38
39
40
41
42
43
44
|
type t = Basis.string
val str = Basis.str1
val length = Basis.strlen
val append = Basis.strcat
val sub = Basis.strsub
val suffix = Basis.strsuffix
val index = Basis.strindex
val atFirst = Basis.strchr
fun mindex {Haystack = s, Needle = chs} = Basis.strcspn s chs
fun substring s {Start = start, Len = len} = Basis.substring s start len
fun split s ch =
case index s ch of
None => None
| Some i => Some (substring s {Start = 0, Len = i},
substring s {Start = i + 1, Len = length s - i - 1})
fun msplit {Haystack = s, Needle = chs} =
case mindex {Haystack = s, Needle = chs} of
None => None
| Some i => Some (substring s {Start = 0, Len = i},
sub s i,
substring s {Start = i + 1, Len = length s - i - 1})
fun all f s =
let
val len = length s
fun al i =
i >= len
|| (f (sub s i) && al (i + 1))
in
al 0
end
fun newlines [ctx] [[Body] ~ ctx] s : xml ([Body] ++ ctx) [] [] =
case split s #"\n" of
None => cdata s
| Some (s1, s2) => <xml>{[s1]}<br/>{newlines s2}</xml>
|