Mercurial > urweb
diff src/c/urweb.c @ 293:711aad3869d1
Error-parsing floats and bools
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 07 Sep 2008 12:19:15 -0400 |
parents | 6e665c7c96f6 |
children | 1afa94582275 |
line wrap: on
line diff
--- a/src/c/urweb.c Sun Sep 07 12:15:46 2008 -0400 +++ b/src/c/urweb.c Sun Sep 07 12:19:15 2008 -0400 @@ -799,3 +799,22 @@ else lw_error(ctx, FATAL, "Can't parse int: %s", s); } + +lw_Basis_float lw_Basis_stringToFloat_error(lw_context ctx, lw_Basis_string s) { + char *endptr; + lw_Basis_float n = strtod(s, &endptr); + + if (*s != '\0' && *endptr == '\0') + return n; + else + lw_error(ctx, FATAL, "Can't parse float: %s", s); +} + +lw_Basis_bool lw_Basis_stringToBool_error(lw_context ctx, lw_Basis_string s) { + if (!strcasecmp (s, "True")) + return lw_Basis_True; + else if (!strcasecmp (s, "False")) + return lw_Basis_False; + else + lw_error(ctx, FATAL, "Can't parse bool: %s", s); +}