Mercurial > urweb
diff src/c/urweb.c @ 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 | 6e665c7c96f6 |
line wrap: on
line diff
--- a/src/c/urweb.c Sun Sep 07 11:33:13 2008 -0400 +++ b/src/c/urweb.c Sun Sep 07 11:41:04 2008 -0400 @@ -769,3 +769,27 @@ } else return NULL; } + +lw_Basis_float *lw_Basis_stringToFloat(lw_context ctx, lw_Basis_string s) { + char *endptr; + lw_Basis_float n = strtod(s, &endptr); + + if (*s != '\0' && *endptr == '\0') { + lw_Basis_float *r = lw_malloc(ctx, sizeof(lw_Basis_float)); + *r = n; + return r; + } else + return NULL; +} + +lw_Basis_bool *lw_Basis_stringToBool(lw_context ctx, lw_Basis_string s) { + static lw_Basis_bool true = lw_Basis_True; + static lw_Basis_bool false = lw_Basis_False; + + if (!strcasecmp (s, "True")) + return &true; + else if (!strcasecmp (s, "False")) + return &false; + else + return NULL; +}