comparison src/mono_opt.sml @ 135:b1cfe49ce692

Proper escaping of cdata
author Adam Chlipala <adamc@hcoop.net>
date Thu, 17 Jul 2008 13:33:56 -0400
parents 6230bdd122e7
children c0ea24dcb86f
comparison
equal deleted inserted replaced
134:18299126a343 135:b1cfe49ce692
44 "-" ^ Real.toString (Real.~ n) 44 "-" ^ Real.toString (Real.~ n)
45 else 45 else
46 Real.toString n 46 Real.toString n
47 47
48 val attrifyString = String.translate (fn #"\"" => "&quot;" 48 val attrifyString = String.translate (fn #"\"" => "&quot;"
49 | #"&" => "&amp;"
49 | ch => if Char.isPrint ch then 50 | ch => if Char.isPrint ch then
50 str ch 51 str ch
51 else 52 else
52 "&#" ^ Int.toString (ord ch) ^ ";") 53 "&#" ^ Int.toString (ord ch) ^ ";")
53 54
54 val urlifyInt = attrifyInt 55 val urlifyInt = attrifyInt
55 val urlifyFloat = attrifyFloat 56 val urlifyFloat = attrifyFloat
57
58 val htmlifyString = String.translate (fn ch => case ch of
59 #"<" => "&lt;"
60 | #"&" => "&amp;"
61 | _ =>
62 if Char.isPrint ch orelse Char.isSpace ch then
63 str ch
64 else
65 "&#" ^ Int.toString (ord ch) ^ ";")
56 66
57 fun hexIt ch = 67 fun hexIt ch =
58 let 68 let
59 val s = Int.fmt StringCvt.HEX (ord ch) 69 val s = Int.fmt StringCvt.HEX (ord ch)
60 in 70 in
120 130
121 | EWrite (EStrcat (e1, e2), loc) => 131 | EWrite (EStrcat (e1, e2), loc) =>
122 ESeq ((optExp (EWrite e1, loc), loc), 132 ESeq ((optExp (EWrite e1, loc), loc),
123 (optExp (EWrite e2, loc), loc)) 133 (optExp (EWrite e2, loc), loc))
124 134
135 | EFfiApp ("Basis", "htmlifyString", [(EPrim (Prim.String s), _)]) =>
136 EPrim (Prim.String (htmlifyString s))
137 | EWrite (EFfiApp ("Basis", "htmlifyString", [(EPrim (Prim.String s), _)]), loc) =>
138 EWrite (EPrim (Prim.String (htmlifyString s)), loc)
139 | EWrite (EFfiApp ("Basis", "htmlifyString", [e]), _) =>
140 EFfiApp ("Basis", "htmlifyString_w", [e])
141
125 | EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]) => 142 | EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]) =>
126 EPrim (Prim.String (attrifyInt n)) 143 EPrim (Prim.String (attrifyInt n))
127 | EWrite (EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]), loc) => 144 | EWrite (EFfiApp ("Basis", "attrifyInt", [(EPrim (Prim.Int n), _)]), loc) =>
128 EWrite (EPrim (Prim.String (attrifyInt n)), loc) 145 EWrite (EPrim (Prim.String (attrifyInt n)), loc)
129 | EWrite (EFfiApp ("Basis", "attrifyInt", [e]), _) => 146 | EWrite (EFfiApp ("Basis", "attrifyInt", [e]), _) =>