diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-12-08 08:48:29 -0500 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-12-08 08:48:29 -0500 |
commit | dbfa206063a82b4c5baa86e9889ce0352f4a6d50 (patch) | |
tree | 025a7421b6cba981c02dc3f33203d10b03578d50 /src/mono_opt.sml | |
parent | 555989e9f85be264de04cdeb21d982d2eb1b4826 (diff) |
Move to simpler HTML escaping
Diffstat (limited to 'src/mono_opt.sml')
-rw-r--r-- | src/mono_opt.sml | 72 |
1 files changed, 7 insertions, 65 deletions
diff --git a/src/mono_opt.sml b/src/mono_opt.sml index bda4d93a..eb4f5811 100644 --- a/src/mono_opt.sml +++ b/src/mono_opt.sml @@ -45,45 +45,14 @@ fun attrifyFloat n = else Real.toString n -fun attrifyString s = - let - fun hs (pos, acc) = - if pos >= size s then - String.concat (rev acc) - else - case String.sub (s, pos) of - #"\"" => hs (pos+1, """ :: acc) - | #"&" => hs (pos+1, "&" :: acc) - | ch => - let - val n = ord ch - fun isCont k = pos + k < size s - andalso ord (String.sub (s, pos + k)) div 64 = 2 - fun unicode k = hs (pos+k+1, String.substring (s, pos, k+1) :: acc) - in - if Char.isPrint ch orelse Char.isSpace ch then - hs (pos+1, str ch :: acc) - else if n div 32 = 6 andalso isCont 1 then - unicode 1 - else if n div 16 = 14 andalso isCont 1 andalso isCont 2 then - unicode 2 - else if n div 8 = 30 andalso isCont 1 andalso isCont 2 andalso isCont 3 then - unicode 3 - else - hs (pos+1, "&#" ^ Int.toString (ord ch) ^ ";" :: acc) - end - in - hs (0, []) - end - fun attrifyChar ch = case ch of #"\"" => """ | #"&" => "&" - | ch => if Char.isPrint ch then - str ch - else - "&#" ^ Int.toString (ord ch) ^ ";" + | ch => str ch + +val attrifyString = String.translate attrifyChar + val urlifyInt = attrifyInt val urlifyFloat = attrifyFloat @@ -91,36 +60,9 @@ val urlifyFloat = attrifyFloat val htmlifyInt = attrifyInt val htmlifyFloat = attrifyFloat -fun htmlifyString s = - let - fun hs (pos, acc) = - if pos >= size s then - String.concat (rev acc) - else - case String.sub (s, pos) of - #"<" => hs (pos+1, "<" :: acc) - | #"&" => hs (pos+1, "&" :: acc) - | ch => - let - val n = ord ch - fun isCont k = pos + k < size s - andalso ord (String.sub (s, pos + k)) div 64 = 2 - fun unicode k = hs (pos+k+1, String.substring (s, pos, k+1) :: acc) - in - if Char.isPrint ch then - hs (pos+1, str ch :: acc) - else if n div 32 = 6 andalso isCont 1 then - unicode 1 - else if n div 16 = 14 andalso isCont 1 andalso isCont 2 then - unicode 2 - else if n div 8 = 30 andalso isCont 1 andalso isCont 2 andalso isCont 3 then - unicode 3 - else - hs (pos+1, "&#" ^ Int.toString (ord ch) ^ ";" :: acc) - end - in - hs (0, []) - end +val htmlifyString = String.translate (fn #"<" => "<" + | #"&" => "&" + | ch => str ch) fun hexIt ch = let |