Refactor APT code to be re-usable for domain requests & other similar things; impleme...
[hcoop/zz_old/portal.git] / util.sml
CommitLineData
8d347a33 1structure Util :> UTIL =
2struct
3
51520441 4datatype 'a flat_element =
5 BEGIN
6 | END
7 | ITEM of 'a
8type 'a flat_tree = 'a flat_element list
9
8d347a33 10fun printInt n =
11 Web.print (if n < 0 then
12 "-" ^ Int.toString (~n)
13 else
14 Int.toString n)
15
16fun printReal n =
17 Web.print (if n < 0.0 then
18 "-" ^ Real.fmt (StringCvt.FIX (SOME 2)) (~n)
19 else
20 Real.fmt (StringCvt.FIX (SOME 2)) n)
21
22fun id x = x
23
24fun makeSet f items =
25 case items of
26 [] => "()"
27 | [usr] => "(" ^ f usr ^ ")"
28 | usr::rest => foldl (fn (usr, s) => s ^ ", " ^ f usr) ("(" ^ f usr) rest ^ ")"
29
f1ea3762 30fun neg (r : real) = ~r
31
ff2b7604 32fun isIdent ch = Char.isLower ch orelse Char.isDigit ch
33
34fun validHost s =
35 size s > 0 andalso size s < 20 andalso List.all isIdent (String.explode s)
36
37fun validDomain s =
38 size s > 0 andalso size s < 100 andalso List.all validHost (String.fields (fn ch => ch = #".") s)
39
40fun whoisUrl dom = String.concat ["http://reports.internic.net/cgi/whois?whois_nic=", dom, "&type=domain"]
41
8d347a33 42end