summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2014-06-10 10:58:22 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2014-06-10 10:58:22 -0400
commitd5b6e2668069721d91acb7fbcd0b2a92e08ce71e (patch)
tree149096ba19a65de99f88d83a146906af4fecc689 /lib
parent8023f94ecb26116e00e1fcd25a6bd821e998ea4a (diff)
String.trim; add OnChange to more tags
Diffstat (limited to 'lib')
-rw-r--r--lib/ur/basis.urs6
-rw-r--r--lib/ur/string.ur25
-rw-r--r--lib/ur/string.urs2
3 files changed, 30 insertions, 3 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index ce864563..5e5e81c3 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -946,11 +946,11 @@ con formTag = fn (ty :: Type) (inner :: {Unit}) (attrs :: {Type}) =>
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 @@ val ctextbox : cformTag ([Value = string, Size = int, Source = source string, Pl
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
diff --git a/lib/ur/string.ur b/lib/ur/string.ur
index 59a8e5c5..d760ec2b 100644
--- a/lib/ur/string.ur
+++ b/lib/ur/string.ur
@@ -86,3 +86,28 @@ fun newlines [ctx] [[Body] ~ ctx] (s : string) : xml ([Body] ++ ctx) [] [] =
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
diff --git a/lib/ur/string.urs b/lib/ur/string.urs
index 0861279d..1bdca96c 100644
--- a/lib/ur/string.urs
+++ b/lib/ur/string.urs
@@ -33,3 +33,5 @@ val mp : (char -> char) -> string -> string
val newlines : ctx ::: {Unit} -> [[Body] ~ ctx] => string -> xml ([Body] ++ ctx) [] []
val isPrefix : {Full : t, Prefix : t} -> bool
+
+val trim : t -> t