diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-05-30 09:59:10 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-05-30 09:59:10 -0400 |
commit | 581a2290590268039cacfbe0762b343f710c3116 (patch) | |
tree | a464f8a46243a2a77f37e93ab8934b1d7d11f0fc | |
parent | 62c7b094ecf7e618a2e31658994bf648e1b36819 (diff) |
String.length
-rw-r--r-- | include/urweb.h | 1 | ||||
-rw-r--r-- | lib/js/urweb.js | 6 | ||||
-rw-r--r-- | lib/ur/basis.urs | 1 | ||||
-rw-r--r-- | lib/ur/string.ur | 3 | ||||
-rw-r--r-- | lib/ur/string.urs | 4 | ||||
-rw-r--r-- | src/c/urweb.c | 8 | ||||
-rw-r--r-- | src/settings.sml | 3 |
7 files changed, 20 insertions, 6 deletions
diff --git a/include/urweb.h b/include/urweb.h index 1b4a5558..f5a4c391 100644 --- a/include/urweb.h +++ b/include/urweb.h @@ -111,6 +111,7 @@ uw_Basis_string uw_Basis_unurlifyString(uw_context, char **); uw_Basis_bool uw_Basis_unurlifyBool(uw_context, char **); uw_Basis_time uw_Basis_unurlifyTime(uw_context, char **); +uw_Basis_int uw_Basis_strlen(uw_context, const char *); uw_Basis_char uw_Basis_strsub(uw_context, const char *, uw_Basis_int); uw_Basis_string uw_Basis_strsuffix(uw_context, const char *, uw_Basis_int); uw_Basis_string uw_Basis_strcat(uw_context, const char *, const char *); diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 40b170c4..db3c934c 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -237,7 +237,6 @@ function setHTML(html) { x.innerHTML = html; addNode(x); runScripts(x); - alert("HTML:\n" + html); } var thisScript = null; @@ -351,8 +350,9 @@ function eh(x) { function ts(x) { return x.toString() } function bs(b) { return (b ? "True" : "False") } -function sub(x, i) { return x[i]; } -function suf(x, i) { return x.substring(i); } +function sub(s, i) { return s[i]; } +function suf(s, i) { return s.substring(i); } +function slen(s) { return s.length; } function pi(s) { var r = parseInt(s); diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index 1209d265..c63c5ed4 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -53,6 +53,7 @@ val ord_time : ord time (** String operations *) +val strlen : string -> int val strcat : string -> string -> string val strsub : string -> int -> char val strsuffix : string -> int -> string diff --git a/lib/ur/string.ur b/lib/ur/string.ur index 5362805b..23670966 100644 --- a/lib/ur/string.ur +++ b/lib/ur/string.ur @@ -1,4 +1,7 @@ type t = Basis.string +val length = Basis.strlen +val append = Basis.strcat + val sub = Basis.strsub val suffix = Basis.strsuffix diff --git a/lib/ur/string.urs b/lib/ur/string.urs index 524e002d..ef522387 100644 --- a/lib/ur/string.urs +++ b/lib/ur/string.urs @@ -1,4 +1,8 @@ type t = string +val length : t -> int + +val append : t -> t -> t + val sub : t -> int -> char val suffix : t -> int -> string diff --git a/src/c/urweb.c b/src/c/urweb.c index d399b3bd..cffbb57c 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1807,8 +1807,12 @@ uw_Basis_string uw_Basis_strsuffix(uw_context ctx, uw_Basis_string s, uw_Basis_i uw_error(ctx, FATAL, "Out-of-bounds strsuffix"); } +uw_Basis_int uw_Basis_strlen(uw_context ctx, uw_Basis_string s) { + return strlen(s); +} + uw_Basis_string uw_Basis_strcat(uw_context ctx, uw_Basis_string s1, uw_Basis_string s2) { - int len = strlen(s1) + strlen(s2) + 1; + int len = uw_Basis_strlen(ctx, s1) + uw_Basis_strlen(ctx, s2) + 1; char *s; uw_check_heap(ctx, len); @@ -1823,7 +1827,7 @@ uw_Basis_string uw_Basis_strcat(uw_context ctx, uw_Basis_string s1, uw_Basis_str } uw_Basis_string uw_strdup(uw_context ctx, uw_Basis_string s1) { - int len = strlen(s1) + 1; + int len = uw_Basis_strlen(ctx, s1) + 1; char *s; uw_check_heap(ctx, len); diff --git a/src/settings.sml b/src/settings.sml index 4b2092d2..fa162660 100644 --- a/src/settings.sml +++ b/src/settings.sml @@ -152,7 +152,8 @@ val jsFuncsBase = basisM [("alert", "alert"), ("attrifyBool", "bs"), ("boolToString", "ts"), ("strsub", "sub"), - ("strsuffix", "suf")] + ("strsuffix", "suf"), + ("strlen", "slen")] val jsFuncs = ref jsFuncsBase fun setJsFuncs ls = jsFuncs := foldl (fn ((k, v), m) => M.insert (m, k, v)) jsFuncsBase ls fun jsFunc x = M.find (!jsFuncs, x) |