comparison 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
comparison
equal deleted inserted replaced
292:6e665c7c96f6 293:711aad3869d1
797 if (*s != '\0' && *endptr == '\0') 797 if (*s != '\0' && *endptr == '\0')
798 return n; 798 return n;
799 else 799 else
800 lw_error(ctx, FATAL, "Can't parse int: %s", s); 800 lw_error(ctx, FATAL, "Can't parse int: %s", s);
801 } 801 }
802
803 lw_Basis_float lw_Basis_stringToFloat_error(lw_context ctx, lw_Basis_string s) {
804 char *endptr;
805 lw_Basis_float n = strtod(s, &endptr);
806
807 if (*s != '\0' && *endptr == '\0')
808 return n;
809 else
810 lw_error(ctx, FATAL, "Can't parse float: %s", s);
811 }
812
813 lw_Basis_bool lw_Basis_stringToBool_error(lw_context ctx, lw_Basis_string s) {
814 if (!strcasecmp (s, "True"))
815 return lw_Basis_True;
816 else if (!strcasecmp (s, "False"))
817 return lw_Basis_False;
818 else
819 lw_error(ctx, FATAL, "Can't parse bool: %s", s);
820 }