diff options
author | Adam Chlipala <adam@chlipala.net> | 2010-12-21 18:01:23 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2010-12-21 18:01:23 -0500 |
commit | 17ecbd235ad9b7692dfc029329fb13103eb55d9c (patch) | |
tree | 90ec74ac4d55bd062eab0b9ebb1c161b31dd6167 /src | |
parent | 22d11510a829052ea5be8d93c9805572aa13d66e (diff) |
Basis.cdataChar
Diffstat (limited to 'src')
-rw-r--r-- | src/c/urweb.c | 22 | ||||
-rw-r--r-- | src/mono_opt.sml | 7 | ||||
-rw-r--r-- | src/monoize.sml | 5 |
3 files changed, 34 insertions, 0 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index aea2c6ba..d3b8c770 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1963,6 +1963,28 @@ uw_unit uw_Basis_htmlifyInt_w(uw_context ctx, uw_Basis_int n) { return uw_unit_v; } +char *uw_Basis_htmlifySpecialChar(uw_context ctx, unsigned char ch) { + unsigned int n = ch; + int len; + char *r; + + uw_check_heap(ctx, INTS_MAX+3); + r = ctx->heap.front; + sprintf(r, "&#%u;%n", n, &len); + ctx->heap.front += len+1; + return r; +} + +uw_unit uw_Basis_htmlifySpecialChar_w(uw_context ctx, unsigned char ch) { + unsigned int n = ch; + int len; + + uw_check(ctx, INTS_MAX+3); + sprintf(ctx->page.front, "&#%u;%n", n, &len); + ctx->page.front += len; + return uw_unit_v; +} + char *uw_Basis_htmlifyFloat(uw_context ctx, uw_Basis_float n) { int len; char *r; diff --git a/src/mono_opt.sml b/src/mono_opt.sml index 6e137dc5..34f43143 100644 --- a/src/mono_opt.sml +++ b/src/mono_opt.sml @@ -64,6 +64,8 @@ val htmlifyString = String.translate (fn #"<" => "<" | #"&" => "&" | ch => str ch) +fun htmlifySpecialChar ch = "&#" ^ Int.toString (ord ch) ^ ";" + fun hexIt ch = let val s = Int.fmt StringCvt.HEX (ord ch) @@ -180,6 +182,11 @@ fun exp e = ESeq ((EWrite (EPrim (Prim.String (s1 ^ s2)), loc), loc), e) + | EFfiApp ("Basis", "htmlifySpecialChar", [(EPrim (Prim.Char ch), _)]) => + EPrim (Prim.String (htmlifySpecialChar ch)) + | EWrite (EFfiApp ("Basis", "htmlifySpecialChar", [e]), _) => + EFfiApp ("Basis", "htmlifySpecialChar_w", [e]) + | EFfiApp ("Basis", "htmlifyString", [(EFfiApp ("Basis", "intToString", [(EPrim (Prim.Int n), _)]), _)]) => EPrim (Prim.String (htmlifyInt n)) | EFfiApp ("Basis", "htmlifyString", [(EFfiApp ("Basis", "intToString", es), _)]) => diff --git a/src/monoize.sml b/src/monoize.sml index eccf5714..0c0d9d2e 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -2849,6 +2849,11 @@ fun monoExp (env, st, fm) (all as (e, loc)) = in ((L'.EFfiApp ("Basis", "htmlifyString", [se]), loc), fm) end + | L.ECApp ( + (L.ECApp ((L.EFfi ("Basis", "cdataChar"), _), _), _), + _) => + ((L'.EAbs ("ch", (L'.TFfi ("Basis", "char"), loc), (L'.TFfi ("Basis", "string"), loc), + (L'.EFfiApp ("Basis", "htmlifySpecialChar", [(L'.ERel 0, loc)]), loc)), loc), fm) | L.EApp ( (L.EApp ( |