Mercurial > urweb
comparison tests/fromString.ur @ 289:0cc956a3216f
Parsing strings for floats and bools
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 07 Sep 2008 11:41:04 -0400 |
parents | 4260ad920c36 |
children | df00701f2323 |
comparison
equal
deleted
inserted
replaced
288:4260ad920c36 | 289:0cc956a3216f |
---|---|
1 fun i2s s = | 1 fun s2i s = |
2 case stringToInt s of | 2 case stringToInt s of |
3 None => 0 | 3 None => 0 |
4 | Some n => n | 4 | Some n => n |
5 | 5 |
6 fun s2f s = | |
7 case stringToFloat s of | |
8 None => 0.0 | |
9 | Some n => n | |
10 | |
11 fun s2b s = | |
12 case stringToBool s of | |
13 None => False | |
14 | Some b => b | |
15 | |
6 fun main () : transaction page = return <html><body> | 16 fun main () : transaction page = return <html><body> |
7 Error = {cdata (show _ (i2s "Error"))}<br/> | 17 Error = {cdata (show _ (s2i "Error"))}<br/> |
8 3 = {cdata (show _ (i2s "+3"))}<br/> | 18 3 = {cdata (show _ (s2i "+3"))}<br/> |
19 <br/> | |
20 Error = {cdata (show _ (s2f "Error"))}<br/> | |
21 98.76 = {cdata (show _ (s2f "98.76"))}<br/> | |
22 <br/> | |
23 Error = {cdata (show _ (s2b "Error"))}<br/> | |
24 False = {cdata (show _ (s2b "false"))}<br/> | |
25 True = {cdata (show _ (s2b "trUE"))}<br/> | |
9 </body></html> | 26 </body></html> |
10 |