changeset 2021:2da693675de9

String.trim; add OnChange to more tags
author Adam Chlipala <adam@chlipala.net>
date Tue, 10 Jun 2014 10:58:22 -0400
parents 924e2ef31f5a
children 1a4b2b983889
files lib/ur/basis.urs lib/ur/string.ur lib/ur/string.urs
diffstat 3 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ur/basis.urs	Mon Jun 09 18:26:03 2014 -0400
+++ b/lib/ur/basis.urs	Tue Jun 10 10:58:22 2014 -0400
@@ -946,11 +946,11 @@
 val hidden : formTag string [] [Data = data_attr, Id = string, Value = string]
 val textbox : formTag string [] ([Value = string, Size = int, Placeholder = string, Source = source string, Onchange = transaction unit,
                                   Ontext = transaction unit] ++ boxAttrs)
-val password : formTag string [] ([Value = string, Size = int, Placeholder = string] ++ boxAttrs)
+val password : formTag string [] ([Value = string, Size = int, Placeholder = string, Onchange = transaction unit] ++ boxAttrs)
 val textarea : formTag string [] ([Rows = int, Cols = int, Onchange = transaction unit,
                                    Ontext = transaction unit] ++ boxAttrs)
 
-val checkbox : formTag bool [] ([Checked = bool] ++ boxAttrs)
+val checkbox : formTag bool [] ([Checked = bool, Onchange = transaction unit] ++ boxAttrs)
 
 type file
 val fileName : file -> option string
@@ -1010,7 +1010,7 @@
                           Ontext = transaction unit] ++ boxAttrs) []
 val button : cformTag ([Value = string] ++ boxAttrs) []
 
-val ccheckbox : cformTag ([Value = bool, Size = int, Source = source bool] ++ boxAttrs) []
+val ccheckbox : cformTag ([Value = bool, Size = int, Source = source bool, Onchange = transaction unit] ++ boxAttrs) []
 
 con cselect = [Cselect]
 val cselect : cformTag ([Source = source string, Onchange = transaction unit] ++ boxAttrs) cselect
--- a/lib/ur/string.ur	Mon Jun 09 18:26:03 2014 -0400
+++ b/lib/ur/string.ur	Tue Jun 10 10:58:22 2014 -0400
@@ -86,3 +86,28 @@
 
 fun isPrefix {Full = f, Prefix = p} =
     length f >= length p && substring f {Start = 0, Len = length p} = p
+
+fun trim s =
+    let
+        val len = length s
+
+        fun findStart i =
+            if i < len && Char.isSpace (sub s i) then
+                findStart (i+1)
+            else
+                i
+
+        fun findFinish i =
+            if i >= 0 && Char.isSpace (sub s i) then
+                findFinish (i-1)
+            else
+                i
+
+        val start = findStart 0
+        val finish = findFinish (len - 1)
+    in
+        if finish >= start then
+            substring s {Start = start, Len = finish - start + 1}
+        else
+            ""
+    end
--- a/lib/ur/string.urs	Mon Jun 09 18:26:03 2014 -0400
+++ b/lib/ur/string.urs	Tue Jun 10 10:58:22 2014 -0400
@@ -33,3 +33,5 @@
 val newlines : ctx ::: {Unit} -> [[Body] ~ ctx] => string -> xml ([Body] ++ ctx) [] []
 
 val isPrefix : {Full : t, Prefix : t} -> bool
+
+val trim : t -> t