8d347a33 |
1 | structure Util :> UTIL = |
2 | struct |
3 | |
51520441 |
4 | datatype 'a flat_element = |
5 | BEGIN |
6 | | END |
7 | | ITEM of 'a |
8 | type 'a flat_tree = 'a flat_element list |
9 | |
8d347a33 |
10 | fun printInt n = |
11 | Web.print (if n < 0 then |
12 | "-" ^ Int.toString (~n) |
13 | else |
14 | Int.toString n) |
15 | |
16 | fun 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 | |
22 | fun id x = x |
23 | |
24 | fun 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 |
30 | fun neg (r : real) = ~r |
31 | |
ff2b7604 |
32 | fun isIdent ch = Char.isLower ch orelse Char.isDigit ch |
33 | |
34 | fun validHost s = |
35 | size s > 0 andalso size s < 20 andalso List.all isIdent (String.explode s) |
36 | |
37 | fun validDomain s = |
38 | size s > 0 andalso size s < 100 andalso List.all validHost (String.fields (fn ch => ch = #".") s) |
39 | |
40 | fun whoisUrl dom = String.concat ["http://reports.internic.net/cgi/whois?whois_nic=", dom, "&type=domain"] |
41 | |
8d347a33 |
42 | end |