comparison 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
comparison
equal deleted inserted replaced
288:4260ad920c36 289:0cc956a3216f
767 *r = n; 767 *r = n;
768 return r; 768 return r;
769 } else 769 } else
770 return NULL; 770 return NULL;
771 } 771 }
772
773 lw_Basis_float *lw_Basis_stringToFloat(lw_context ctx, lw_Basis_string s) {
774 char *endptr;
775 lw_Basis_float n = strtod(s, &endptr);
776
777 if (*s != '\0' && *endptr == '\0') {
778 lw_Basis_float *r = lw_malloc(ctx, sizeof(lw_Basis_float));
779 *r = n;
780 return r;
781 } else
782 return NULL;
783 }
784
785 lw_Basis_bool *lw_Basis_stringToBool(lw_context ctx, lw_Basis_string s) {
786 static lw_Basis_bool true = lw_Basis_True;
787 static lw_Basis_bool false = lw_Basis_False;
788
789 if (!strcasecmp (s, "True"))
790 return &true;
791 else if (!strcasecmp (s, "False"))
792 return &false;
793 else
794 return NULL;
795 }